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

Igor Bukanov igor at mir2.org
Fri Mar 16 18:37:13 PDT 2007


On 17/03/07, Vassily Gavrilyak <gavrilyak at gmail.com> wrote:
> File.open("file.txt") do  | file
>    file.process()
> end

and

> Well, I agree, it is available such way too.
> And it is avalivaible with try {} finally{} from long time ago.
> It's just the same issue of readability.
> The question - what is for doing here, where is the loop immediately come to
> mind when reading such construct.

Ruby's do construction is also a loop, not a lambda, almost exactly
corresponding to the generator example in JS, yet it was given as an
example to support the need for short lambdas in JS.

I think the issue here is that the generators are not yet widely used
in JS so the code like
for (var f in autoFile("file.txt"))
  processFile(f);
still looks strange.

But, compared with lambda proposal, that code is in fact shorter, much
more clear IMO and can be optimized better.

For that reason I think examples like this can not be used to support
the lambda shorthand. What can be used is a case like:

  var filtered = array.filter((\ elem) elem > 0)

versus

  var filtered = array.filter(function(elem) { return elem > 0; })

Regards, Igor



More information about the Es4-discuss mailing list