some generator issues

Lars T Hansen lth at acm.org
Mon May 7 03:35:48 PDT 2007


On 4/22/07, Neil Mix <nmix at pandora.com> wrote:
> >>> Other methods rely on
> >>> some sort of generator manager (shift the responsibility to the code
> >>> handling the generators rather than within them) or using global
> >>> generator vars (which would force the generators to be specific
> >>> to the
> >>> script containing those vars), both of which aren't ideal in the
> >>> above
> >>> use case.
> >>>
> >>> I'm unaware of a Python solution to this issue.
> >>
> >> Hard to standardize an argument; don't want another keyword.
> >> Suggestions?
> >>
> >> /be
> >>
> >
> > I was thinking of adding another property to the arguments object.
> > Perhaps, arguments.generator. The value for this property would be
> > null
> > (or undefined) if the function isn't a generator function.
>
> Something like this would be great.  In practice, this particular
> suggestion might be a tad unwieldy:
>
> function foo() {
>         var gen = arguments.generator;
>         var command = new AsynchCommand();
>         command.onResult = function(result) {
>                 gen.send(result);
>         }
>         command.execute();
>         var result = yield;
>         // do something with the result
> }
>
> The unwieldy part being that you're required to set
> arguments.generator to a local var because otherwise the arguments
> object gets masked.

Using some ES4 facilities for structuring and desugaring it's not quite as
awful as it may look at first blush:

  function foo() {
     var command = new AsynchCommand();
     command.onResult = let (gen = arguments.generator) function(result)
gen.send(result);
     command.execute();
     var result = yield;
     // do something with the result
  }

--lars
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.mozilla.org/pipermail/es-discuss/attachments/20070507/cbc7c1ce/attachment-0002.html 


More information about the Es4-discuss mailing list