[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Signature of iterator factories
- From: Jim Pryor <lists+lua@...>
- Date: Sun, 1 Nov 2009 22:25:33 -0500
At this point, I'm sure too much code would break to introduce any
changes. But if we were designing iterators from scratch,
wouldn't it be nice to give them this signature instead:
generator(control_variable, state_var1, ...)
That way, we could pass multiple state_vars when we need to. I know,
just pack all your state information into a table, or have your
generator be a closure with the extra state information as upvalues.
Easy enough to program. But it's a shame to bring in that overhead just
because we can't write iterators taking more than one state_var.
I don't know the VM architecture, maybe there are low-level reasons for doing
it the way it is.
What's the standard nomenclature for these things anyway?
"pairs" is example of what? an "iterator factory"?
"next" is an example of what? a "generator"? an "iterator function"?
the triple (next, tbl, control_var) is what? an "iterator"?