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

Vassily Gavrilyak gavrilyak at gmail.com
Wed Mar 21 16:06:37 PDT 2007


On 3/21/07, Igor Bukanov <igor at mir2.org> wrote:
> 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 gmail.com> 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.
Yes, they can leave and that's good. Connections are pooled,
statements can be reused later again.

> > 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
> leak:
>
> 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.
Hmm, maybe there is some idea here.... It looks nicer then closure
example, for this
 particularly usage. At least variable are written before statement,
not after as with functions and that's something I like. Maybe we can
get rid of for stigma somehow...
Need to think more about this.

Thanks,
Vassily

> Regards, Igor
> _______________________________________________
> Es4-discuss mailing list
> Es4-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es4-discuss
>



More information about the Es4-discuss mailing list