local

Peter Michaux petermichaux at gmail.com
Thu Aug 21 08:21:11 PDT 2008


On Thu, Aug 21, 2008 at 6:31 AM, Brendan Eich <brendan at mozilla.org> wrote:

> More helpful would be
> comments on the utility of let blocks (a.k.a. let statements) and let
> expressions. Also comparisons to the several let forms in Scheme (Jon
> Z. posted something a while ago on this topic).

I was reading the resulting ticket a few days ago.

http://bugs.ecmascript.org/ticket/375

I think that the let statement

let (x = 2, y = x) {
  print(y);
}

should desugar to exactly

(function(x, y) {
  print(y);
})(2, x)

Also the let expression

z = let (x = 2, y = x) x + y;

should desugar to exactly

z = (function(x, y) x + y)(2, x);

The reasons for these particular desugarings is this is exactly what
JavaScript programmers are writing today. It is common to see
something like the desugared let statement above when looping and
attaching event handlers to DOM elements, for example.

I also think that since the name is "let" that the above desugaring
makes sense as the closest analogy to Scheme's let. It doesn't make
sense to me to have JavaScript's let be Scheme's let* or letrec. All
these lets are purely sugar coatings and I'm not opposed to having
Scheme's let* and letrec added to JavaScript as they introduce even
sweeter sugar for some situations. I suppose let* would need to be
renamed.

Peter


More information about the Es-discuss mailing list