Allen's lambda syntax proposal
Maciej Stachowiak
mjs at apple.com
Mon Dec 1 12:59:03 PST 2008
On Nov 29, 2008, at 10:30 PM, Brendan Eich wrote:
> At the TC39 meeting two weeks ago in Kona, we had a brief
> bikeshedding discussion about lambda syntax and why it matters.
> Observation: blocks in Smalltalk being lightweight means users don't
> mind writing them for control abstractions, compared to JS functions
> in ES3. In Smalltalk, ignoring JS, it's hard to beat [ and ] as
> overhead, although one must count the message selector and its
> punctuation too.
>
> Allen Wirfs-Brock put his proposal, which will not shock you who
> know Smalltalk or Allen, on the whiteboard:
>
> // Instead of lambda (a, b, c) { ... }, why not:
> { |a, b, c| ... } ?
I like the brevity, but having the formals inside the block and in ||
delimiters seems like it will look weird in an ECMAScript program. For
function declarations the parameters go in parentheses, and for calls
(presumably also for lambda calls), the arguments go in parens. If
brevity is important, why not lift the lambda syntax from modern pure
functional languages:
\(a, b, c) { ... }
That's backslash as a lambda operator. This has one more character
than your version, but will make formals and parameters look the same
for functions, lambdas, and calls, and will avoid putting the formals
inside the body which I think is confusing and visually hard to scan.
Regards,
Maciej
More information about the Es-discuss
mailing list