Andy Wingo (2014-08-20T08:42:44.000Z)
On Tue 19 Aug 2014 08:48, Claude Pache <claude.pache at gmail.com> writes:

> Le 19 août 2014 à 06:47, Kevin Smith <zenparsing at gmail.com> a écrit :
>
>     It appears that the current state of affairs is that the argument
>     supplied to the first call of `next` on a newborn generator is
>     "ignored and inaccessibe".
>     
>     Is there any way that the generator function can have access to that
>     lost data?
>
> This can be worked around. Basically, ask the generator to advance to
> the first `yield` at instantiation, and retrieve the value of the
> "first" `next()` with that `yield`. For example:

This has the disadvantage of starting computation in the generator, of
course, before it has been asked for.

While this workaround might serve the purpose of "observables", for lazy
sequences it's not quite right.  It effectively turns an "even" sequence
into an "odd" one (in the sense of Wadler's paper[1]), as for iterables you
would have to stash the first return value away somewhere, so you end up
with iterators being a pair whose car is strict and whose cdr is lazy.

Andy

[1] "How to add laziness to a strict language, without even being odd"
    http://homepages.inf.ed.ac.uk/wadler/papers/lazyinstrict/lazyinstrict.ps
domenic at domenicdenicola.com (2014-08-26T18:23:33.513Z)
On Tue 19 Aug 2014 08:48, Claude Pache <claude.pache at gmail.com> writes:

> This can be worked around. Basically, ask the generator to advance to
> the first `yield` at instantiation, and retrieve the value of the
> "first" `next()` with that `yield`. For example:

This has the disadvantage of starting computation in the generator, of
course, before it has been asked for.

While this workaround might serve the purpose of "observables", for lazy
sequences it's not quite right.  It effectively turns an "even" sequence
into an "odd" one (in the sense of Wadler's paper ["How to add laziness to a strict language, without even being odd"](http://homepages.inf.ed.ac.uk/wadler/papers/lazyinstrict/lazyinstrict.ps)), as for iterables you
would have to stash the first return value away somewhere, so you end up
with iterators being a pair whose car is strict and whose cdr is lazy.
domenic at domenicdenicola.com (2014-08-26T18:23:12.570Z)
On Tue 19 Aug 2014 08:48, Claude Pache <claude.pache at gmail.com> writes:

> This can be worked around. Basically, ask the generator to advance to
> the first `yield` at instantiation, and retrieve the value of the
> "first" `next()` with that `yield`. For example:

This has the disadvantage of starting computation in the generator, of
course, before it has been asked for.

While this workaround might serve the purpose of "observables", for lazy
sequences it's not quite right.  It effectively turns an "even" sequence
into an "odd" one (in the sense of Wadler's paper[1]), as for iterables you
would have to stash the first return value away somewhere, so you end up
with iterators being a pair whose car is strict and whose cdr is lazy.

Andy

[1] "How to add laziness to a strict language, without even being odd"
    http://homepages.inf.ed.ac.uk/wadler/papers/lazyinstrict/lazyinstrict.ps