From: Eric Mahurin Date: 2008-05-27T00:51:40+09:00 Subject: Re: [PATCH] lambda with normal block syntax ------=_Part_10534_26140071.1211817136058 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Mon, May 26, 2008 at 9:14 AM, Dave Thomas wrote: > > On May 26, 2008, at 8:54 AM, Yukihiro Matsumoto wrote: > > "trouble with recognition"? I thought they hated the -> mark, mostly >> because it's different from lambda symbols (and syntax) in other >> languages (except for Perl6). I assumed those hatred will decrease >> once they used to the new syntax. But I didn't recognized they had >> recognition problem. >> > > My personal experience is that I don't find it a natural notation: when I > see ->, I don't immediately think 'block coming'. Instead, I think > 'pointer', 'member access', or something similar. So, for me, it really is a > 'cognition' issue (so I guess the second time it's recognition). > > You asked people to try the patched syntax that allows > > meth {|a| a+1}, {|b| b*2} > > I think that this particular syntax is a lot less obtrusive, and a lot > easier to recognize, than > Actually, in my patch (and I believe ruby from r8044), the above is equivalent to: (meth {|a| a+1}), lambda {|b| b*2} If you want these to be lambda arguments, you'll need parens around your args: meth( {|a| a+1}, {|b| b*2} ) Personally, for most cases I use ()'s around my args to reduce confusion about precedence, so the above isn't a problem for me. With this patch you'll need to use () for your arguments if your first argument is a bare block (that gets interpreted as a lambda). Regardless of this patch, this precedence/ambiguity problem already exists today. Take a look at this example: [meth {}, {}] The first {} is the block for meth and the second is a Hash as the second item in a list (the first is the meth call). The interpretation of the above won't change with this patch. You'll need to use {|| } to get a lambda to differentiate it from a Hash. I think it all comes down to a matter of clearly describing the precedence. meth -> a { a + 1}, -> b { b * 2 } > > The first one is obviously a couple of blocks: that's what I read when I > see {|a| ...}. > > It seems that most of the posters on this thread agree. And, using your > criteria of "try it for a while and see", I'd judge that people have tried > -> for a while, and might well be happier with the {|| } version. > > I'd also argue that the {|a| } makes for a better language. My experience > teaching this stuff shows that people are confused by the large number of > different options that surround blocks. Unifying block parameters with > method parameters, and then removing the need for this somewhat strange -> > notation, will reduce the number of special cases, and make it a lot easier > for people to understand the language. And that's a major cognition win. > > Please, please consider adding both these patches into 1.9. > > > > Dave > > ------=_Part_10534_26140071.1211817136058 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Mon, May 26, 2008 at 9:14 AM, Dave Thomas <dave@pragprog.com> wrote:

On May 26, 2008, at 8:54 AM, Yukihiro Matsumoto wrote:

"trouble with recognition"?  I thought they hated the -> mark, mostly
because it's different from lambda symbols (and syntax) in other
languages (except for Perl6).  I assumed those hatred will decrease
once they used to the new syntax.  But I didn't recognized they had
recognition problem.

My personal experience is that I don't find it a natural notation: when I see ->, I don't immediately think 'block coming'. Instead, I think 'pointer', 'member access', or something similar. So, for me, it really is a 'cognition' issue (so I guess the second time it's recognition).

You asked people to try the patched syntax that allows

 meth {|a| a+1}, {|b| b*2}

I think that this particular syntax is a lot less obtrusive, and a lot easier to recognize, than
 
Actually, in my patch (and I believe ruby from r8044), the above is equivalent to:

(meth {|a| a+1}), lambda {|b| b*2}

If you want these to be lambda arguments, you'll need parens around your args:

meth( {|a| a+1}, {|b| b*2} )

Personally, for most cases I use ()'s around my args to reduce confusion about precedence, so the above isn't a problem for me.  With this patch you'll need to use () for your arguments if your first argument is a bare block (that gets interpreted as a lambda).

Regardless of this patch, this precedence/ambiguity problem already exists today.  Take a look at this example:

[meth {}, {}]

The first {} is the block for meth and the second is a Hash as the second item in a list (the first is the meth call).  The interpretation of the above won't change with this patch.  You'll need to use {|| } to get a lambda to differentiate it from a Hash.

I think it all comes down to a matter of clearly describing the precedence.

  meth -> a { a + 1}, -> b { b * 2 }

The first one is obviously a couple of blocks: that's what I read when I see {|a| ...}.

It seems that most of the posters on this thread agree. And, using your criteria of "try it for a while and see", I'd judge that people have tried -> for a while, and might well be happier with the {|| } version.

I'd also argue that the {|a| } makes for a better language. My experience teaching this stuff shows that people are confused by the large number of different options that surround blocks. Unifying block parameters with method parameters, and then removing the need for this somewhat strange -> notation, will reduce the number of special cases, and make it a lot easier for people to understand the language. And that's a major cognition win.

Please, please consider adding both these patches into 1.9.



Dave


------=_Part_10534_26140071.1211817136058--