Why no tail calls from generators?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Why no tail calls from generators?

Joe Gibbs Politz
Hi!  I tried searching the archives and a bit around the Web, but couldn't find a place where this was written down; I may just need a pointer.

What is the rationale for explicitly disallowing PTC in generators?  (Or, in the case of proposals like STC, why not allow users to opt in to TCO in generator bodies?)

Specifically, I'm referring to step 5 in IsInTailPosition that returns false (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-isintailposition) if the body is a generator body.

Thanks!
Joe P

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Why no tail calls from generators?

Bergi
Joe Gibbs Politz wrote:

> What is the rationale for explicitly disallowing PTC in generators?  (Or,
> in the case of proposals like STC, why not allow users to opt in to TCO in
> generator bodies?)

I'd guess that generator functions are already complicated enough, and
the `next()` call that at least has to wrap the result in `{value: …,
done:true}` would always have to stay on the stack.
However, it would be possible to do tail-recursive calls in generator
functions via

     return yield* f(…)

Kind regards,
  Bergi

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