- For instance, can you write a generator function which returns an iterator function?
My understanding of an iterator function tells me it's code that returns an item from a list -- which sounds like dynamic code. I don't believe C can do that easily.
- What about closures?
C does have scoped variables, where a variable only exists within a pair of braces. When I was writing C code that got cross-compiled to 68000 assembler, I could see that the compiler just assigned space on the stack for that type of variable by moving the stack pointer down, and once the scope ended, the stack pointer was just adjusted back up.
C also has the static keyword, which says the variable is to be stored in the lexical scope, meaning it's created at the beginning of the run (perhaps on the stack, but not anywhere that's going to get re-used), and only initialized once, if that initialization happens during declaration. So my guess is that closures are possible -- but keep in mind I studied engineering and not computer science, so that opinion is just what I've picked up since I left university.
|Replies are listed 'Best First'.|
Re^6: What technical benfits perl offers over python + few more questions.
by afoken (Canon) on Nov 14, 2021 at 16:53 UTC
Re^6: What technical benfits perl offers over python + few more questions. (generator/iterator/closure)
by LanX (Sage) on Nov 13, 2021 at 20:20 UTC
by talexb (Chancellor) on Nov 13, 2021 at 21:55 UTC