This topic came up at RubyConf 2001 during David Black’s Ruby Behaviors
talk. David Simmons (creator of SmallScript or S#) suggested the need for
something called “selector namespaces”, which has been discussed (with
David’s input) in ruby-talk:18567.
It’s actually not all that difficult under some circumstances, but
there are some costs associated with it. Basically what you need is
both lexical namespaces and namespace overlays. Not a trivial task,
by any means, but doable if you need it. (Whether it’s worthwhile
or not is a separate issue, of course)
Could you whip us up a quick working prototype so we can see how it feels?
I’ve already got perl and parrot’s internals wedged into my brain–if
I added Ruby’s, well, I expect Horrible Lovecraftian Things would
happen. Not, mind, that anyone’s likely to notice, but still…
But, seriously, will parrot have these features?
Yeah, it’s an outgrowth of the support needed for some of Python’s
namespace stuff, so it’ll be in there. I’m not thrilled about the
cost, but there’s pie involved, so one does what one must.
Selector Namespaces, for those who’re following along, are
essentially lexical namespaces. They allow you to have a local
override to a global (generally) name, or a name that only exists
inside a lexical scope. This way you can have, for example, a Foo
method for class Bar that only is visible in some scope–it may mask
an existing Foo, or may be brand new and only exist inside that
scope. This way you can have private versions of methods, private
methods, and even private classes if you want.
To make this work, generally you need nested name tables. Each
lexical scope has a pointer to a name table, and when you go look up
a name, you look in the lexical table. Each lexical table has a
pointer to an outer table, which potentially points to its outer
table, and so forth. When you look a name up, you walk up the tables
until you find the name, or fail.
As you can imagine, this makes name lookup a bit slower, since you
probably have to walk several levels, and makes scope changing a bit
more complex, since you need to save and restore these pointers.
Doable, certainly, and it provides a lot of power, but the places its
useful are somewhat restricted.
···
At 11:00 AM +0900 6/5/03, Chad Fowler wrote:
Dan
--------------------------------------“it’s like this”-------------------
Dan Sugalski even samurai
dan@sidhe.org have teddy bears and even
teddy bears get drunk