Hello, Matz

What do you think about Marc-Andre's alternative syntax for
keyword arguments and mechanism?


2011/12/22, Marc-Andre Lafortune <ruby-core-mailing-list / marc-andre.ca>:
> I haven't given much thought, but here's an alternate suggestion,
> where **h => {*h}:
>
>    def foo(a, b=1, *rest, {c: 2, d: 3, *options})
>    end
>
> If the parser allows, the {} could be optional, at least in the case
> without a "hash-rest" argument.
>
> This could actually be two new concepts that could be used everywhere
> in Ruby (not just for argument passing):
> a) Splat inside a hash does a merge, e.g.
>
>     h = {foo: 1, bar: 2}
>     {*h, baz: 3} # => {foo: 1, bar: 2, baz: 3}
>
> I'm not sure if it should be silent in case of duplicate key (like
> `Hash#merge` with no block) or if it should raise an error.
>
> b) Hash destructuring, e.g.:
>
>     h = {foo: 1, bar: 2}
>     {foo: 42, extra: 0, *rest} = h
>     foo   # => 1
>     extra # => 0
>     rest  # => {bar: 2}
>
> It would be nice to not need a default:
>
>     {foo, extra, *rest} = h
>     extra # => nil
>
> This could be allowed in arguments too:
>
>     def foo(a, b=1, *rest, {c, d, *options})
>     end


I think the mechanism looks neater then my proposal.
My first proposal is less flexible; it allows us only keyword
arguments by making the complex concept, i.e., method arguments,
more complex.

On the contrary, Marc-Andre's proposal consists of some small
concepts (each which looks useful) and minimum extension for
method arguments.  It is agreement with the Unix philosophy ---
do one thing and do it well.

I'm not sure if his proposal is implementable or not, but if you
prefer it, I (or anyone) will try to implement it.

Which do you prefer?

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