Expression closures - use-cases for shortcut lambda syntax(blocks)

Vassily Gavrilyak gavrilyak at
Wed Mar 21 15:55:55 PDT 2007

I totally agree with both proposals, they will work. I will argue though :-)

Generators are the same as functions, that's true.
And I understand you, Igor, as a primary generators author. Everything
looks like 'for' :-).
The same with me, everything looks like 'function' :-). We already
talked about this, shortly.
I understand that everything can be done with generators. Just why
with this cool
new concept, and not plain old function? I still have problems
explaining generators even to most experienced members of our team.
Functions were accepted almost in no time.

Macros are deferred, and rightly so, I do not see many major use-cases
for macro in ES
(as there are still no use for macros in Ruby, language just good enough).
I would like having macros probably, but why use this heavy artillery
when simple function
 will do?
Especially when those functions are already here and they are doing
everything and doing
 just right. Only a LITTLE clumsy.
Why add new concepts into the language? And your example looks
almost the same as mine, the only difference is in using = instead of =>
You removed parens somehow in withStatement, with just a little magic.
What if I want to add another function argument after this block (2
function arguments)?
Seems I can't, syntax problem, two blocks, and no possibility to do
this in one macro
(that was already discussed in this thread, Dave told about something similar).
So we will need macro overloading by arguments counts or types, or
something like this.
I won't talk about well-known problems with macros from Lisp (why
people avoid them?).
Why complicate things? How I can explain this magic to newbie? I
explained function
shortcuts very easy, in one statement. No magic here. Just plain
functions you already
know, written with short syntax you have already seen and used for
arrays, objects, strings and regexps (and dates  in ES4).  It's clear
what they do, clear how to write, read and debug them (reusing

You can defer functions to ES5 and you have all the rights to do so,
you are the language designers. Just I do not understand the reasons.
Every other language seems wanting to
provide something in this area (C#, Java, even C++ discussed this) or
already provided (Ruby etc). It was hard to do for designers of those
languages, but user asks them and
they just provide what users ask.
ES had good functions almost from the start (thanks Brendan).
Use-cases for them are clear from other languages and from ES itself.
Why not just reuse their experience? We will also reuse developers
knowledge this way.

Those were pros. Cons? I see only technical problems with lookahead
parser, though lookahead is already here.
Readability arguments - it seems nobody provided more readable code
with current syntax.
Project policy - one can always disable usage of shortcuts for a team.
What else?

Best regards,

On 3/21/07, P T Withington <ptw at> wrote:
> On 2007-03-21, at 13:44 EDT, Vassily Gavrilyak wrote:
> > ---------- Forwarded message ----------
> > From: Vassily Gavrilyak <gavrilyak at>
> [...]
> >
> > There are also versions with try-finally, even more painful.
> > The same about every other use-cases.
> Another solution would be to add macros to the language, so that the
> try/finally version was cleaner.  That's the lispy way:
> macro withPreparedStatement {
>    withPreparedStatement (??prepared:variable = ?statement:expression
> on ?connection:expression) ?body:statement =>
>     { let ?prepared = ?connnection.prepare(?statement);
>       try {
>         ?body
>       } finally {
>         ?connnection.deallocate(?prepared);
>       }
>     }
> }
> function doSomethingWithNewPeople()
> {
>    withPreparedStatement(selectStatement =
>        "SELECT code, name from people where status='new'" on
> connection) {
>      withPreparedStatement(insertStatement  =
>          "INSERT INTO young(name,age) values (?,?)" on connection){
>        connection.transaction(function(tx) {
>          for (let [name, age] in selectStatement.executeQuery()) {
>            if (name.match(/.*Joe/) && age % 2)
>              insertStatement.execute(name, age);
>          }
>        });
>      }
>    }
> }
> :)
> [Yes I know the macro idea has been deferred.]

More information about the Es4-discuss mailing list