From: Evan Phoenix Date: 2008-05-12T03:44:49+09:00 Subject: Re: lambda, ->, haskell, and so on On May 11, 2008, at 8:52 AM, David A. Black wrote: > Hi -- > > On Sun, 11 May 2008, 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. > > I can't quite figure that out; can you elaborate? Also, as Michael > pointed out, I think Evan meant: > > def(a,b) > ... > end Yeah, I did. I thought about this a bit more last night, and realized perhaps a reason that matz decided on stabby proc was it makes parens optional (and I've seen a no parens stabby proc example). Anonymous def would be ambiguous without parens with one arg: def a end Everyone can see the ambiguity there. But to push on this a little bit, the stabby proc with no parens is SO hard for my brain to parse. It appears to be a mismatch of random symbols without no cohesive elements pulling them together: -> a, b { a + b } In the name of consistency, I can see why the matz wanted it to be allowed without parens, everything else doesn't require them. But ick, it looks so... ick. So, there are a few options: 1) Anonymous def must have parens. The problem is that it bucks consistency with parens on the rest of the elements in the language. 2) Add something to def to disambiguate it, like def!(...). This is actually the same as the #1 (in #1, the something is '('), just with a different element that doesn't have to be matched. 3) Use a different word for def. lambda has been suggested, and I personally don't think it's too many characters. I think that #1 is the best, but a user may get confused by the fact that: def a; ...; end and def(a); ...; end are 2 completely different things. Nobu says that it conflicts with adding singleton methods, but I'm not sure what he means. Perhaps he's referring to the problem without parens. - Evan > > > though I don't know if that's where the conflict is. > > > David > > -- > Rails training from David A. Black and Ruby Power and Light: > INTRO TO RAILS June 9-12 Berlin > ADVANCING WITH RAILS June 16-19 Berlin > INTRO TO RAILS June 24-27 London (Skills Matter) > See http://www.rubypal.com for details and updates! >