3 ms·
> Weird that the yield statement is conflated with coroutines instead of iterators/generators. I think the conflict is between "yielding another value" and "yi
by LoganDark 3y ago
> Weird that the yield statement is conflated with coroutines instead of iterators/generators.
I think the conflict is between "yielding another value" and "yielding control back to the scheduler". Both of them use "yield" but they're different types of yield, and people use the same keyword for both, and either one can be implemented in terms of the other, and so on.
- jayd16 3y agoThey're not different though, right? Just two ways to think about what it means to return, no? How can you return a value without returning control to read that value? They're the same. Still, I don't think iterators and coroutines are necessarily the same. You can imagine a coroutine that doesn't return a value and only happens to share a thread or something.
- LoganDark 3y agoThat's the thing, since either one can be implemented in terms of the other, people conflate iterators/generators with coroutines as you've mentioned because they're easily interchangeable.
- ezekiel68 3y agoRegardless of the underlying mechanism that make them both work, programmers generally have a vastly different conception of yielding (that is, 'producing') a generated value as opposed to yielding (that is, 'ceding') execution time to the OS or a virtual machine.
- LoganDark 3y agoRight, difference between yield as in "crop yield" and yield as in "yield right of way".
- int_19h 3y agoThis is functionally identical to yielding a dummy value. If the language has a unit type (e.g. a 0-ary tuple) then you just use a value of that type.