Allen's lambda syntax proposal

Peter Michaux petermichaux at
Mon Dec 1 22:18:50 PST 2008

On Mon, Dec 1, 2008 at 9:33 PM, Allen Wirfs-Brock
<Allen.Wirfs-Brock at> wrote:

> The BGGA Java closure proposal attempts to support control abstractions that look like built in control constructs by allowing trailing literal closure arguments to appear after the parenthesized argument list (shades of Ruby).  If we did something similar in JavaScript you might then code your example as:
> withOpenFile(fileName)  { |handle|
>     doSomething(handle);
>     doSomethingElse(handle);
> };

I find the idea that a lambda comes after the argument list, but that
it is somehow still an argument, an inconsistent and bad idea. I've
used it in Ruby and don't like it there. In Ruby, I believe these
trailing {||} "blocks" are the only place where the {||} syntax will
create a lambda and so there is appeal to those who like the extremely
compact notation. They cannot get that compact notation elsewhere. In
ES we won't have that restriction.

One problem is if the argument list needs to take two lambdas, then
where would the second lambda go? One inside the arguments list and
one after? Why is one lambda more important or deserving of a special
place compared with the other lambda?

Some API designers won't like the trailing lambda syntax and some
will. Then we end up with inconsistent APIs. If all arguments go in
the argument list then this problem will not arise.

The following is better

withOpenFile(fileName, {|handle|

and the following is better still

withOpenFile(fileName, lambda(handle) {


More information about the Es-discuss mailing list