simple shorter function syntax
Sam Ruby
rubys at intertwingly.net
Sun Jul 25 17:16:52 PDT 2010
On Sun, Jul 25, 2010 at 7:57 PM, Maciej Stachowiak <mjs at apple.com> wrote:
>
> Good point about the escaping hazard. I think # may look funny to people
> because it is a "noisy" symbol and also because it is a comment delimiter in
> many languages. Two other characters totally disallowed in the syntax are @
> and `, I wonder if either of those would be more visually pleasing:
> [0, 1, 2, 3].map( #(x) {x * x} )
> [0, 1, 2, 3].map( `(x) {x * x} )
> [0, 1, 2, 3].map( @(x) {x * x} )
> I also wonder if using a strictly binary operator might be workable without
> creating syntax ambiguities:
> [0, 1, 2, 3].map( ^(x) {x * x} )
> [0, 1, 2, 3].map( *(x) {x * x} )
> [0, 1, 2, 3].map( %(x) {x * x} )
The ruby syntax for the above is as follows:
[0,1,2,3].map {|x| x*x}
(try it in 'irb' to see what I mean)
While I don't believe that would fly here, perhaps adding parens
around the function would:
[0,1,2,3].map({|x| x*x})
- Sam Ruby
More information about the es-discuss
mailing list