Subject: bug#59140: 29.0.50; iter-yield from lambda

From: Max Brieiev <[email-masked]>
Date: Sun, 17 Sep 2023 09:32:31 +0300

Michael Heerdegen <[email-masked]> writes:

> Max Brieiev <[email-masked]> writes:
>
>> For example, this:
>>
>>     (iter-defun my-generator ()
>>       (funcall (lambda () (iter-yield 5))))
>>
>> would be expanded by iter-defun macro into this:
>>
>>     (...
>>       (let ((gen (iter-lambda () (iter-yield 5))))
>>         (iter-next (funcall gen))))
>>
>> Does it make sense?
>
> Does it?  Isn't the `let' expression equivalent to just `5'?  With other
> words: you don't yield from an outside generator, as far as I
> understand (or am I wrong? what's the content of your "..."?).
>
> Michael.

You are right, the code is wrong, it should probably return a generator
instead. What I attempted to show is how lambda would be turned into
`iter-lambda`, conceptually. "..." is some expansion performed by
`iter-defun`. In my intuition, if `iter-yield` is encountered inside a
lambda, then it would be converted into generator, and then advance the
created generator to the first yield expression, such that the following
`iter-next` would resume execution from the suspnension point. But I
might be wrong, the topic of generators is new to me, and I need to
study it.