On Mon, 24 Oct 2005, Trans wrote:

> Yukihiro Matsumoto wrote:
>> It's for method delegation.  Currently we do
>>
>>   def foo(*args)
>>     bar(*args)
>>   end
>>
>> for method delegation.  Under my proposal, this delegation would still
>> work fine, since we have named arguments appear twice, otherwise we
>> must change the code as
>>
>>   def foo(*args, **keys)
>>     bar(*args, **keys)
>>   end
>>
>> everywhere, to just do delegation.
>
> This is sinking worse and worse into a stenchy quagmire. If someone puts
> **keys in the parameters then it makes sense for the keys NOT to appear in
> args. I know you want to remain backward compatable so without **keys then
> the keys will appear in args. But how does one say they want any number of
> ordered parameters but NO named parameters? I suppose you just can't.
> Moreover the args won't be cleanly separated.  So this doesn't do us much
> good, I'll still be pop'n off trailing hashes :(  Really, think about that!

it's not that big a deal to do is it?  i've abstracted this in alib like so:

   harp:~ > cat a.rb
   require 'alib'
   include ALib::Util

   def meth *argv
     args, opts = optfilter argv
     foo = getopt 'foo', opts
     bar = getopt 'bar', opts, 'forty-two'  # default value

     p 'args' => args
     p 'opts' => opts
     p 'foo' => foo
     p 'bar' => bar
   end

   meth 'foo', 'bar', 'foo' => 42


   harp:~ > ruby a.rb
   {"args"=>["foo", "bar"]}
   {"opts"=>{"foo"=>42}}
   {"foo"=>42}
   {"bar"=>"forty-two"}


easy cheasy.  parseargs abstracts even further.  if a language mod must be
made the answer seems clear: old style keywords land in *args as before, new
style ones land in keys, for example:

   def meth *args
     p args
   end

   meth 42              #=> [42]
   meth 42, 'foo' => 42 #=> [42, {'foo' => 42}]


   def meth *args, **keys
     p [args, keys]
   end

   meth 42                         #=> [ [42], {} ]
   meth 42, 'foo' => 42            #=> [ [42, {'foo' => 42}], {} ]
   meth 42, foo : 42               #=> [ [42, {}], {'foo' => 42} ]
   meth 42, 'foo' => 42, foo : 42  #=> [ [42, {'foo' => 42}], {'foo' => 42} ]

i might add that i hope whatever keys object will hash key and symbol
arguments the same so we can do

   val = keys['foo']

or

   val = keys[:foo]

i hate having to check for both (that's what getopt above does).

2cts.

-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
===============================================================================