On Wed, 2 Nov 2005, Minero Aoki wrote:

> [ruby-dev:27417] selector namespace
>
>  Shugo Maeda proposed a new language feature, "selector namespace".  Matz
>  also noted this topic in his key note at Ruby Conference 2005.
>
>  Selector namespace is a namespace of selector (method name).  This function
>  is useful to replace methods temporarily.  For example, current jcode.rb
>  replaces String#chop itself, which effects globally.  But with selector
>  namespace, it effects only in "jcode" namespace.
>
>    class String
>      def jcode$chop   # define #chop method in jcode namespace
>        ...
>      end
>    end
>
>    # "\244\242\244\244" is Japanese characters 'A'+'I' in EUC-JP
>    p "\244\242\244\244".chop         # "\244\242\244"  # wrong result
>    p "\244\242\244\244".jcode$chop   # "\244\242"      # right result
>
>  You can omit namespace specifier ("jcode$") by using "using" syntax:
>
>    class String
>      def jcode$chop() ... end
>    end
>
>    using jcode
>    p "\244\242\244\244".chop   # "\244\242"      # right result

i don't see why the above cannot be

   class String
     def jcode::chop
     end
   end

   p "\244\242\244\244".jcode::chop

   using String::jcode (i assume that was what was meant - surely String's
                        jcode is not exported to the top level or we'd have
                        many clashing namespaces!)

'::' is non-ambiguous in all these situations.  this syntax also suggests

   class String
     namespace jcode
       def chop
       end
       namespace util
         ...
       end
       namespace const
         ...
       end
     end
   end

in otherwords, namespaces may be declared in a nested way.

now i suppose yacc will be the problem... ;-(


-a
-- 
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| anything that contradicts experience and logic should be abandoned.
| -- h.h. the 14th dalai lama
===============================================================================