3 ms·
IMO this is like saying a high-level language is syntactic sugar for assembly. Generators allow you to write a state machine as a procedural function whose loc
by btown 3y ago
IMO this is like saying a high-level language is syntactic sugar for assembly.
Generators allow you to write a state machine as a procedural function whose local variables are automatically suspended when you yield and restored when the caller returns control to the generator. They compile this down to, as you said, an object with a call method. But that transformation is as nontrivial as any compilation/transpilation project.