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

Yuh-Ruey Chen maian330 at gmail.com
Wed Mar 21 23:19:30 PDT 2007


Vassily Gavrilyak wrote:
> > 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
> >
> _______________________________________________
> Es4-discuss mailing list
> Es4-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es4-discuss
>   

As I've mentioned before, Python has a "with" statement that seems to
cover this issue, but I'm not that familiar with Python 2.5 features so
I'm not really sure.

In any case, we can come up with a construct that explicitly evaluates a
generator only once. Something like (reusing do keyword):

do (let tx in connection.transaction()) { ... }

But this still has a slight connotation of a loop (do...while). Or
reusing the let syntax:

let (tx in connection.transaction()) { ... }

One possible disadvantage of this let syntax is that tx can't be an
existing variable, i.e. tx is always a new variable within the block's
scope. I say possible, since I don't see any use case that requires
relaxing this restriction.

Just some brainstorming...
-Yuh-Ruey



More information about the Es4-discuss mailing list