From: Eric Mahurin Date: 2005-08-07T11:55:32+09:00 Subject: Re: new block notation --- Daniel Brockman wrote: > You can convert a lambda to a block by using the `&' syntax > (as in `&lambda {...}'), and the other way around by calling > Proc.new or using the `def foo(&block)' syntax. This gives an idea for an alternative to the ->(..){..} syntax. When calling a method, the unary "&" converts a lambda to a block and in the method/lambda/block definition the "&" converts a block to a lambda. Well, how about making the unary "&" in front of a block converting it to a lambda? f = &{...} # equivalent to f = lambda{...} This is not really a unary "&" operator but rather a &{...} construct, but it does flow with the current unary "&" syntax, kind of. This would distinguish a lambda from hash like the ->(..){..} syntax does. You'd still need to resolve the issue of block arguments taking defaults (or not). Any of the solutions that did this within the {..} would work. I like the { args code } syntax the best. Or { args code } where a delimiter (or pair) that doesn't create ambiguities is chosen (| is used now and creates ambiguities with default values). I just realized an ambiguity with the ->(..){..} syntax. Currently it can be used to define a lambda or a block. If you have this: def test(lam=nil,&block) ... end test ->(..){..} This looks ambiguous as to whether lam or block should get the lambda/block. I assume block wins, but I don't have the latest 1.9 installed on this machine. I guess the same ambiguity exists with the older 1.9 that allowed plain {...} for lambdas. This says to me that you should have distinguishable different syntax between block and lambda as it is now: { ... } # hash method-call { ... } # block lambda { ... } # lambda &{ ... } # proposed lambda Simply replacing lambda with "&" keeps this distinction. The new ->(..){...} syntax creates ambiguities between block and hash since this can be either. ____________________________________________________ Start your day with Yahoo! - make it your home page http://www.yahoo.com/r/hs