Claus Reinke wrote:
And why not? Because yield is a statement

Yield is an expression.

Thanks for the correction. Yes, "yield expr" is an expression, syntactically.

It doesn't have the nice composition and code transformation properties that I usually associate with expressions, it imposes unusual restrictions
on its *context* and impedes functional abstraction:

1 though "yield" constructs expressions from expressions, it isn't a function (can't pass "yield" around or store it in a variable), nor is
   "yield expr" a function call.

Same for every other operator.

2 1 can be worked around, but not with the usual tools of function definitions and calls - "yield" forces use of "function*" and "yield*" for abstracting over expressions containing it.

So does 'return' and this is for a good reason: we are not adding deep continuations (as discussed up-thread).

3 "yield" is disappointingly similar to "this", in being implicitly bound to the next "function*" ("function", for "this"). Expressions referencing either "this" or "yield" cannot be wrapped in functions (btw, can generator bodies reference an outer "this"?), because this would
   cut the implicit binding.

No "binding" in the common sense of that word.

Again: same as 'return'.

For "this", workarounds include arrow functions or "bind", for "yield", the only workaround is "yield*"+"function*" (or diving even deeper,
   with hand-written iterators).

This rehashes a pointless lament that we don't have deep continuations.

Having to use different function mechanisms for the latter is by design, so it is a workaround only from the perspective of wanting to use uniform tools for functional abstraction.

For instance, we cannot write

   function* g() {  (function(){ yield 1 })() }
   function* g() {  function y(x){ yield x } y(1) }

but have to write

   function* g() {  yield* (function*(){ yield 1 })() }
   function* g() {  function* y(x){ yield x } yield* y(1) }

Same as 'return'.

We discussed escape continuations:

http://wiki.ecmascript.org/doku.php?id=strawman:return_to_label

This strawman is not on any roadmap. It did not fare well in past TC39 meetings and discussions.

and when I try to write a polyfill for for-of,

Don't do that!

New special forms require compilers.

/be

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

Reply via email to