From: Austin Ziegler Date: 2005-08-05T08:38:04+09:00 Subject: Re: new block notation (was: Re: ruby-dev summary 26468-26661) On 8/4/05, Yukihiro Matsumoto wrote: > In message "Re: new block notation (was: Re: ruby-dev summary > 26468-26661)" on Fri, 5 Aug 2005 07:55:54 +0900, Eric Mahurin > writes: >| So before, the experiment was this (no default args and >| ambiguities with Hash): >| >| f = { |a| ... } >| >| and now you are thinking about this: >| >| f = -> (a) { ... } >| >| To me, this suffers readability because there are too many >| symbols in a row: =-> ( Wasn't this kind of thing the primary >| problem with perl - too many punctuation characters made it >| difficult to read. > I don't agree. Punctuation symbol nor sequence of them itself is > not a problem. The problems can be caused by context dependent > interpretation of symbols, I think. Mmmm. I think that part of Perl's problem *is* overpunctuation. I do sort of like Ara's suggestion (e.g., f <- { |...| ... }) for lambdas, but understand that would probably cause as many problems as anything else (and I think that f = <- { |...| ... } is just ugly). >| It seems like you are between a rock and a hard place (preserving >| backwards compatibility) to solve this problem. I don't see one >| great solution. The best I can come up with is to use syntax like >| we have now except a) use symbols other than | that allow no >| ambiguity in the expressions (I think :+space would work), and b) >| force an argument list to not cause ambiguities. So you'd have >| this: >| >| f = { : a,b=1|2 : ... } >| f = { : * : ... } # equivalent to f = lambda { ... } > Unfortunately :+space causes conflicts as well. What about "|:"? That is: f = { | foo, bar = 1 | 2 |: ... } That might also make it possible to do: f = { foo, bar = 1 | 2 |: ... } dropping the first pipe, which would also be a nice visual indicator that this block has full method semantics rather than closure semantics (if that distinction iss important, necessary, or continued). Even with what I suggested to Eric about using Hashes more than Blocks, I think it would be nice to have a different syntax for blocks and hashes, and I think that it's probably easier to redo hashes for Ruby 2.0 than blocks. My personal vote would be for one of these: [: key => value :] [: key: value :] I'm not saying it'd be great -- it's easier for me to type "{" than "[:", but I think that I could learn to live with it. (Alternately, overload the [] syntax so that if it looks like a Hash inside, it *is* a Hash.) -austin -- Austin Ziegler * halostatue@gmail.com * Alternate: austin@halostatue.ca