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

Yuh-Ruey Chen maian330 at gmail.com
Fri Mar 16 18:47:17 PDT 2007


Igor Bukanov wrote:
> You do not need function closure here in ES4, use generators instead
> (that already works in SpiderMonkey since Firefox 2.0):
>
> for (file in autoFile("hello", "r")) {
>    process(file);
> }
>   

This is a bit of a side note, but this type of usage of generators can
be misleading to novice programmers, so I'm not sure if it's any better.
If I were new to the language, I would interpret this as some type of
for loop that can process multiple files. The intent that you'd like the
code to show is that process(file) is called only once and is cleaned up
afterwards.

The Python guys have in fact talked a lot about this specific construct:

http://www.python.org/dev/peps/pep-0343/
http://www.python.org/dev/peps/pep-0340/ (rejected in favor of PEP 343)
http://www.python.org/dev/peps/pep-0310/ (rejected in favor of PEP 343)

- Yuh-Ruey Chen



More information about the Es4-discuss mailing list