return when desugaring to closures

Lex Spoon spoon at google.com
Fri Aug 22 16:02:10 PDT 2008


On Thu, Aug 21, 2008 at 6:24 PM, Brendan Eich <brendan at mozilla.org> wrote:
>
>> This problem is especially disturbing because the problems are so
>> subtle.  Once you've convinced yourself that JavaScript's var is
>> problematic, it's really hard to summarize the argument concisely.
>> You can show coding examples where programmers get surprised, but many
>> will respond and simply say don't do that.  You can show
>> term-rewriting rules that should be but aren't equivalences, but
>> people's eyes glaze over.  I can give a rule of thumb, though, for
>> avoiding these problems to begin with: go with an existing design.
>> The desugaring of lets into functions and function calls is not some
>> obscure new invention, but a common one that has stood the test of
>> time well.
>
> No, it hasn't, because you are talking about JS functions, with |this|,
> arguments, and so on. I don't know why you changed the argument from
> decrying var binding to treating JS functions as if they were well-behaved
> lambda expresions or Scheme procedures.

You didn't really respond to my point.  Using lexical binding has
worked out well, and equating lexical binding with function calls has,
too.  There might be something about JavaScript that causes an issue.
You raised return, break, continue, and arguments before, and I
addressed those.  So is there anything that is really an issue with
the proposed desugaring?


>>  I fully agree that
>> different languages aren't necessarily comparable to each other.
>> However, those I named have the same semantics as JavaScript for the
>> relevant features: nested functions, function calls, parameters, and
>> the proposed let-bound variables.
>
> No, they do not. Common Lisp, Scala, and Smalltalk do not have the same
> semantics in detail as JS does with respect to functions, calls, parameters,
> and any let proposal I've seen or implemented.
>
> If you look from 100,000 feet, you could say they're all similar, but they
> are not the same. Just one example: Smalltalk has block objects, quoted code
> you can activate by sending a message. You could say that's just like a
> function, except where it is quite different
> (http://c2.com/cgi/wiki?SmalltalkBlockReturn).

Brendan, that is exactly the non-local return I was talking about.
The success of this construct in multiple languages proves that it is
at least workable.  Its repeated selection proves that others have
found it desirable.  Now, there might be something special about
JavaScript that would cause it not to work well.  What difference
would that be, though?

-Lex


More information about the Es-discuss mailing list