"Yukihiro Matsumoto" <matz / ruby-lang.org> wrote in message > |If a subclass of Symbol like SelectorSymbol also had a @namespace slot to > |provide selector namespaces (which would be great with Ruby's modules and > |re-opening of classes; SmallScript does something similar), we would also > |need some way to associate a namespace with a selector symbol. e.g. > | x.send :move # which namespace? symbol or selector symbol? > | x.send N1::move # ah, N1's :move selector symbol > | x.send :move # send could treat :move symbol as default_ns::move > |selector symbol? > > I'm not sure I get you, but I feel like you're suggesting something > interesting. Let me consider. Detailed explanation would be welcomed. When defining a method (via def... or define_method) we need to indicate which namespace the selector belongs to; and when invoking a method via x.send or x.foo, we need to indicate which namespace selector we are using. -------------- First for invocations of the form: x.send(selector, *args) #send needs to know the namespace of the selector so it can lookup the correct method. A subclass of Symbol, say SelectorSymbol, could have a @namespace slot. NameSpace#lookup(symbol) could return a SelectorSymbol, and all methods (or unbound methods) could be indexed by SelectorSymbols. So I can now write in verbose form: x.send my_namespace.lookup(:move) other_args We need a better syntax to indicate which namespace. Something like: x.send myns::move other_args # :: resolves to a SelectorSymbol or x.send myns:.move other_args # :. resolves to a SelectorSymbol If #send receives a regular symbol (instead of a SelectorSymbol), it can look up the SelectorSymbol from Ruby's current namespace, or from some global default namespace, or first one then the other. x.send :move args becomes x.send default_ns::move args or, as an alternative language design choice x.send current_ns::move args Also, define_method would need very similar logic to index its methods. -------------- Next, for invocations of the form: x.selector y, z Given: x.move args Here the compiler/interpreter/vm must know the current namespace and treat is as equivalent to x.send current_ns::move args -------------- Lastly, we need a way to indicate the current namespace. I believe Ruby modules are the right unit for this: module M class Desk def move # M::move end end class Chair def move # also M::move end end x.move #=> x.send M::move end However, there may be other conflicts which how modules and module::foo are used in Ruby that make it necessary to have either a different explicit namespace construct, or use something like M:.name instead M::name to resolve selectors. And we need a namespace "import" which only makes the imported module the current namespace (i.e. not the same as require and include). module N import M n.move # n.send M::move class Bed def move # N::move or M::move? I think the latter end def M::move # alternate approach end end end end -------------- There are implementations of selector namespaces in SmallScript and Squeak. I think the SmallScript ones are very good (www.smallscript.com , with several discussions available via google http://www.google.com/search?q=selector+namespace+smallscript&sourceid=mozilla-search&start=0&start=0&ie=utf-8&oe=utf-8&client=firefox-a&rls=org.mozilla:en-US:official ) Hope that helps ...