Hacker News new | past | comments | ask | show | jobs | submit login

Not ECMAScript Harmony! [1] And no, that isn't the definitive semantics of closing over mutable variables. It is one out of at least two possible semantics.

[1] http://brendaneich.com/2010/11/paren-free/ -- see the "Implicit Fresh Bindings" section.




Harmony's new for in construct implicitly introduces a fresh let binding per iteration, yes, but it doesn't fundamentally change the language semantics with regard to the kind of example Eich mentions. So while one can, in Harmony, write code that behaves in the way that people like Andrej Bauer expect, it doesn't mean that the language's closure semantics have suddenly changed.

It's also hard for me to see how one could have a 'definitive' semantics without having at least one alternative—not that I claimed that either JS's closure semantics were the only ones going. Presumably the alternative you mean is where the variables present in the local environment are copied on creation of a closure.

I'd also resist the idea that I claimed that JavaScript's closure semantics were in some way definitive, although I can see how one might infer that from what I did write. That being said, given the potential problems with the alternative, I would claim that they're a reasonable choice.


it doesn't mean that the language's closure semantics have suddenly changed.

Yes, but what are the issues with fresh let-bindings per iteration?

Presumably the alternative you mean is where the variables present in the local environment are copied on creation of a closure.

No, that's bad -- it leaves you unable to show that objects with mutable state are reducible to closures.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: