From: Eric Mahurin Date: 2008-05-12T00:53:02+09:00 Subject: Re: lambda, ->, haskell, and so on ------=_Part_1256_6841963.1210521180385 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Sun, May 11, 2008 at 9:49 AM, Nobuyoshi Nakada wrote: > Hi, > > At Sun, 11 May 2008 15:14:54 +0900, > Evan Phoenix wrote in [ruby-core:16705]: > > Not to throw the whole thread into a tizzy again, but why again is: > > > > ->(a,b) { } # stabby proc > > > > better than > > > > def(a,b) { } # anonymous def > > It would conflict with singleton method definitions. > > -- > Nobu Nakada > > I've never seen the ()'s used for the "singleton". i.e. def (a+b).foo ... end Is it necessary to preserve compatibility to do this since nobody really uses it? You could still do the above with: c = a+b def c.foo ... end My personal preference would be to not introduce some brand new block/lambda/proc/def form. I think there is already enough confusion around the topic. Instead, just extend block arguments to allow for defaults and its own block argument. i.e. ... { |a, b=1, c=(d|e), &f| ... } To handle the ambiguity between "|" in the default value vs. the argument list terminator, I think the only thing that you'd need to do is to restrict the default value to be "primary" instead of "arg_value". For a "def", an optional argument in parse.y is: f_opt : tIDENTIFIER '=' arg_value For a block, it would just be: block_f_opt : tIDENTIFIER '=' primary and you'd change block_params to allow block_f_opt like f_args allows for f_opt. Any downside with this? Eric ------=_Part_1256_6841963.1210521180385 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline

On Sun, May 11, 2008 at 9:49 AM, Nobuyoshi Nakada <nobu@ruby-lang.org> wrote:
Hi,

At Sun, 11 May 2008 15:14:54 +0900,
Evan Phoenix wrote in [ruby-core:16705]:
> Not to throw the whole thread into a tizzy again, but why again is:
>
>   ->(a,b) { }   # stabby proc
>
> better than
>
>    def(a,b) { } # anonymous def

It would conflict with singleton method definitions.

--
Nobu Nakada


I've never seen the ()'s used for the "singleton".  i.e.

def (a+b).foo
...
end

Is it necessary to preserve compatibility to do this since nobody really uses it?  You could still do the above with:

c = a+b
def c.foo
...
end

My personal preference would be to not introduce some brand new block/lambda/proc/def form.  I think there is already enough confusion around the topic.  Instead, just extend block arguments to allow for defaults and its own block argument.  i.e.

... { |a, b=1, c=(d|e), &f| ... }

To handle the ambiguity between "|" in the default value vs. the argument list terminator, I think the only thing that you'd need to do is to restrict the default value to be "primary" instead of "arg_value".  For a "def", an optional argument in parse.y is:

f_opt           : tIDENTIFIER '=' arg_value

For a block, it would just be:

block_f_opt : tIDENTIFIER '=' primary

and you'd change block_params to allow block_f_opt like f_args allows for f_opt.

Any downside with this?

Eric

------=_Part_1256_6841963.1210521180385--