[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Syntactic sugar for function parameters
- From: "Gavin Kistner" <gavin.kistner@...>
- Date: Tue, 6 Feb 2007 17:38:27 -0700
From: Ivan-Assen Ivanov
> throughout our code we frequently use the following construct:
>
> foobar( function() ..... end )
>
> where the anonymous function body is often very small.
As a data point (and not a suggestion), Ruby's syntax for this is:
foobar{ ... }
And if you want parameters:
foobar{ |a,b| ... }
The terseness of these near-lambdas[1] is one of Ruby's greatest
accomplishments, IMO. That massive amount of typing reduction makes you
approach problems for a very different, non-iterator way.
[1] They're called "blocks" in Ruby. I call them near-lambdas because
they are closures, but they aren't really first-class functions with
that particular syntax, in the sense that you can't directly write:
foo = { |a,b| ... }