Q: how to start a module name with a lower case character?

I am trying to write Ruby classes to model RDF, RDFS, and Owl, much
like SWCLOS does for Common Lisp:

module Rdfs
...
end

x = Rdfs::Class.new(Rdfs::Label => "label_1")

It would be nice to have a hack that would allow module names to start
with a lower case letter. Any ideas?

It would also be good to be able to alias "::" to ":" so that I could
use a syntax like:

rdfs:Label

Any ideas and references to things to read, no matter how hack-like,
will be appreciated.

I can think of two hacks, one to get lowercase module names, and one to get
a single colon, but they aren't compatible with each other:

Lowercase module name:

rdfs = Module.new do
  ... code ...
end

(Note that rdfs is a local variable, with all the attendant scoping issues)

rdfs:Label syntax:

module Rdfs
   ... code ...
end

def rdfs( name )
   Rdfs.const_get(name)
end

rdfs:Label # yuck

You know if you really want to make look just like the syntax you want, you
can use strings. I would not recommend abusing ruby to the extent you would
have to almost acheive what you want.

···

On 6/25/07, Mark Watson <mark.watson@gmail.com> wrote:

I am trying to write Ruby classes to model RDF, RDFS, and Owl, much
like SWCLOS does for Common Lisp:

module Rdfs
...
end

x = Rdfs::Class.new(Rdfs::Label => "label_1")

It would be nice to have a hack that would allow module names to start
with a lower case letter. Any ideas?

It would also be good to be able to alias "::" to ":" so that I could
use a syntax like:

rdfs:Label

Any ideas and references to things to read, no matter how hack-like,
will be appreciated.

I am trying to write Ruby classes to model RDF, RDFS, and Owl, much
like SWCLOS does for Common Lisp:

module Rdfs
...
end

x = Rdfs::Class.new(Rdfs::Label => "label_1")

It would be nice to have a hack that would allow module names to start
with a lower case letter. Any ideas?

You can't because module names must be constants and constants have to start with an uppercase letter.

It would also be good to be able to alias "::" to ":" so that I could
use a syntax like:

rdfs:Label

Hm, no idea whether there is a way although Ruby seems to accept the syntax:

$ ruby -ce 'rdfs:Label'
Syntax OK

Kind regards

  robert

···

On 25.06.2007 16:53, Mark Watson wrote:

Robert Klemme wrote:
[snip]

> It would also be good to be able to alias "::" to ":" so that I could
> use a syntax like:
>
> rdfs:Label

Hm, no idea whether there is a way although Ruby seems to accept the syntax:

$ ruby -ce 'rdfs:Label'
Syntax OK

FWIW, this is because Ruby interprets that as a method call with a
symbol argument, i.e. rdfs( :Label )

irb(main):002:0> rdfs:Label
NoMethodError: undefined method `rdfs' for main:Object
        from (irb):2
irb(main):003:0> def rdfs( *args ) p args end
=> nil
irb(main):004:0> rdfs:Label
[:Label]

So, with predefined or dynamic prefixes, you could use that syntax as
a method that returns a specially-namespaced constant.

···

On 25.06.2007 16:53, Mark Watson wrote:

Incase it wasn't clear what was going on in Logan's post, the reason
why that syntax is okay is because it's interpreted as rdfs(:Label)

···

On 6/25/07, Robert Klemme <shortcutter@googlemail.com> wrote:

Hm, no idea whether there is a way although Ruby seems to accept the syntax:

$ ruby -ce 'rdfs:Label'
Syntax OK