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

Igor Bukanov igor at
Wed Mar 21 12:57:00 PDT 2007

First, let me apologize about spreading FUD about Ruby do-blocks. They
are indeed full lambdas at least since 2002 even if the originally
they were indeed a body of do-loop integrated with generators.

Now back to to that Rubby example.

On 21/03/07, Vassily Gavrilyak <gavrilyak at> wrote:
> 2 leaks. Statements must be closed too. They are prepared, and
> sometimes you will need to use them again, sometime not. So you can't
> rely on some "external statement manager" here. GC will not help too.
> So, simple code provokes 2 bugs in ES.

Well, I did not know that the transaction destructor would leave the
prepared statements. In any case, a good library should reflect the
language so a direct translation of idioms from one language to
another may lead to ugly code.

> I agree with for (you mean generator here) and let, that is very nice
> addition to ES.
> Direct translation with proposed syntax will be this. Using only

If one really wants to go to the direct translation, then one have to
use the generators all the way down to much Ruby semantics as the
example does not require lambdas as the do-blocks-as-lambdas do not

function doSomethingWithNewPeople() {
    let selectSQL ="SELECT code, name from people where status='new'";
    let insertSQL = "INSERT INTO young(name,age) values (?,?)";
    for (let tx in connection.transaction()) {
        for (let selectStatement in connection.prepare(selectSQL)) {
            for (let insertStatement in connection.prepare(insertSQL)) {
                for (let [name, age] in selectStatement.executeQuery()) {
                    if (name.match(/.*Joe/) && age % 2)
                        insertStatement.execute(name, age);

Except for the loop stigma that is associated with for-in statement, I
do not see how this is worse than that Ruby's case. I suspect that do
blocks in Ruby do no have the loop stigma since from the date one Ruby
advocated such usage.

Regards, Igor

More information about the Es4-discuss mailing list