Can we remove labels from the next version of the spec?

I'm not a fan of labels, at least not as a built-in language
construct - I'd much prefer if the language was expressive enough to emulate such functionality when needed (that
includes useable syntax), not to mention reducing the
need for such features in the first place.
However, as long as Javascript has break and continue, ..

Am I missing anything? Or are there cases where labels allow you do something that's impossible without labels?

It seems that language features like lambdas have been shot
down because of their interaction with break and continue.
In brief, people want to be able to abstract over syntax phrases
like the one marked with -| .. |- here, by wrapping it in some
form of immediately called function and still have it behave as before:

   while (..) { .. -| break; |- .. }

[aside: as far as I understand Tennent, this has nothing to do
   with his principles of correspondence or abstraction, which
   are often misquoted and conjured with in the archives]

Now, if we want to wrap that phrase into a function (not a
syntax macro), then that function cuts through the while/break
construct. Still, we can refactor the code a little to make that
wrapping possible:

loop: while (..) { .. switch ( -| function() { return 'break'; } () |- ) {
           case 'break' : break loop;
           case 'continue' : continue loop;
           }
.. }

With this change, we are able to wrap code involving break
or continue into a function (and move that function definition
out of the loop body). Since the switch statement has its own
break-target, we need the loop label, even though the original
break did not have a label.

There are other ways to handle this situation, but this seemed
to be the most direct way of expressing the intention, given that labels are not first-class values in Javascript.

Better alternatives welcome,
Claus

_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to