That First Next Argument

Allen Wirfs-Brock allen at wirfs-brock.com
Thu Aug 21 09:35:41 PDT 2014


On Aug 21, 2014, at 12:04 AM, Andy Wingo wrote:

> On Wed 20 Aug 2014 19:55, Brendan Eich <brendan at mozilla.org> writes:
> 
>> Kevin Smith wrote:
>>>    function *echo() input {
>>>        while (true) yield input.value;
>>>    }
>> 
>> So input is bound to the next() actual parameter value on each
>> resumption. That's not bad shed-coloring!
>> 
>> Andy, Dave: WDYT?
> 
> I think changing things right now is the wrong thing to do.  Since this
> is a compatible extension, we don't have to think about this for ES6.
> Just putting that out there ;)
> 
> That said, first thoughts:
> 
>  * I assume "input" could then be captured by nested scopes.  This
>    would be a bit strange but could work.
> 
>  * Really you'd want to be able to destructure too, as you can in every
>    other part of the grammar that introduces names.  That's probably
>    not a great thing to do here, though.
> 
>  * I assume Kevin meant:
> 
>      function *echo input { while (true) yield input }
> 
> To me it smells, but perhaps that is just my grumpiness ;)
> 
> Explicitly being able to place the initial yield would be nicer, but
> then it's more difficult to ensure that the initial yield comes before
> other yields.
> 
> I say punt ;)
> 

I've been thinking about ways to explicitly place the initial yield.  One ideal is a reserved keyword sequence starting with 'yield`, such as `yield continue` to mark the initial yield point. If a generator function does not contain an explicit `yield continue`, then it is implicit at the start of the function body.

I don't think it is necessary to statically ensure that `yield continue` comes before any other `yield`.  It would simply be a runtime detected error if it does not.

Allen  






More information about the es-discuss mailing list