[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Signature of iterator factories
- From: "Juris Kalnins" <juris@...>
- Date: Tue, 03 Nov 2009 13:40:54 +0200
On Mon, 02 Nov 2009 05:25:33 +0200, Jim Pryor <email@example.com>
But if we were designing iterators from scratch,
wouldn't it be nice to give them this signature instead:
generator(control_variable, state_var1, ...)
If <dreaming> about iterators that could have been...
for var_1, ···, var_n in explist do block end
-- could be equivalent to the code:
local f, s, ... = explist -- all values returned by explist
while true do
local s, ..., var_1, ···, var_n = f(s, ...) -- call f with all values
returned by previous iteration, assign leftmost n to control variables
if s == nil then break end
I.e. for would not throw away extra values returned by iterator. When it
returns nothing, loop would end.
This would have made writing iterators for nested data structures (like
filesystem) so easy...