Hello,

Koichi told me that I can commit my patch to the trunk.  So
I'll do after I fix the issues Benoit reported.
But I'll remain this ticket open to continue to discuss the
spec.


2011/10/30 Benoit Daloze <eregontp / gmail.com>:
> I have a few questions/remarks:

Thank you very much for your trying my patch and your opinion!


> 1) What is the way to pass keyword arguments ?
> I would guess `**h` like:
>
> def meth(a, **h)
>  
> end # => syntax error

I didn't implement caller's **.
I wonder if we need it or not.  Is "other(a, h)" not enough?


> BTW, using **h in the argument list does not seems to work in some cases for me:
>
> def a(**h)
> end # => syntax error, unexpected tPOW

Currently, my patch allows ** only when there are one or more
keyword arguments.

This is because I didn't think of any use case.
In addition, I wanted to simplify the implementation of parser.
(Unfortunately, adding a new argument type requries *doubling*
 the parser rules to avoid yacc's conflict)
Do you think we need it?


> def m(k: nil, **h, &block)
> end
> m() # => undefined method `key?' for nil:NilClass

This must be a bug.  I'll fix it.  Thanks!


> 2) I'm a bit dubious about the `**h` syntax to get (and I guess to
> pass) a Hash though.

As I said above, it serves as just `get', not `pass,' currently.


> I believe `*args` is appropriate for the rest argument, because the
> star is the splat operator.
> I cannot think of any clear logic like that for `**h` except "another
> rest argument".
> Also `**` is the power operator, which is unrelated.
> Something related to `{}`, the literal Hash syntax, would fit better
> in my opinion.

I accept another syntax, if it is allowed by matz, and yacc :-)


> Do you have any idea of an alternate syntax to `**h` ?

No I don't.


> 3) What would {Proc,Method,UnboundMethod}#parameters returns for
> keywords arguments ?

Indeed.  I completely forgot.  I'll do.


> 4)    
> def a(k: :a, **h)
>   > end
> a(:b, c: :d, e: :f) # => wrong number of arguments (2 for 0) (ArgumentError)
> It should be "1 for 0"

Yes, the error message should be considered.
But in the case, you're passing two arguments actually:
":b", and "{:c=>:d, :e=>:f}"
Do you mean the keyword argument (= hash) should be ignored?


> def a(k: :a)
>   > end
> a(r: :a) # => unknown keyword (TypeError)
> It should say which keyword is missing

Strongly agreed.  I was just lazy :-)


> (and an ArgumentError rather than TypeError, no?).

Yes, fixed.  Matz said so too.  [ruby-core:40298]

Thanks!

-- 
Yusuke Endoh <mame / tsg.ne.jp>