--- Yukihiro Matsumoto <matz / ruby-lang.org> wrote:

> Hi,
> 
> In message "Re: A comparison by example of keyword argument
> styles"
>     on Tue, 25 Oct 2005 00:15:35 +0900, Eric Mahurin
> <eric_mahurin / yahoo.com> writes:
> 
> |> otherwise we
> |> must change the code as
> |> 
> |>   def foo(*args, **keys)
> |>     bar(*args, **keys)
> |>   end
> |> 
> |> everywhere, to just do delegation.
> |
> |or rather:
> |
> |def foo(*args, **keys, &block)
> |  bar(*args, **keys, &block)
> |end
> |
> |What's wrong with having to do that?
> 
> It's longer than it is really needed.  I want to delegate
> everything
> I've passed, that's all.  I'd rather delegate blocks as well
> when I
> write bar(*args).
> 
> 							matz.

So would a Proc for the block appear as the last element of
args?  If so, you'd have ambiguity between a Proc as the last
positional arg (with no block) and having a block.  Or would
you have a special class for blocks?  Either way you'd create
compatibility problems.  Or maybe args wouldn't be a normal
Array and "hide" the block (and named args)?  Splatting this
would reveal the block and/or named args when you delegate.

What if you want to pass on the positional args but give your
own block (or named arguments)?

If delegation is the only reason for wanting named-args (and
blocks) to appear in the positional args, what about having a
new syntax that splats/unsplats all types of arguments
(positional, named, block) into a special object?  This object
would closely correlate to the method-call mechanism so that
minimal overhead is needed.  Maybe *&:

def foo(*&args) # grab positional, named, and block
  bar(*&args) # pass positional, named, and block
end

The *& would have to be the last "argument" (positional, named,
block) given in the method definition and method call.  Maybe
you would allow positional arguments to come before it - but no
other kind.

Matz, what did you think about the idea of being able to use
named arguments in a multi-assign so that you could return
named arguments?  Like I said, I think the only thing that is
needed to make this reasonable is the ability to have the
keyword and the local variable name different.  Then make make
the multi-LHS look similar to arguments in a method definition
and a multi-RHS/return look like arguments in a method call.



__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com