lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> Geoff Leyland
> Sent: 16 December 2009 21:58


> iterates through obj's "default" list, in a default order and only ever
> provides one value to the iteration?

Yes, in that there is one default iteration order and method per metatable
(Class), but that iteration can produce as many values as you want and in
any order. The main thing is you can use closure-based iterators thus
avoiding the need to expose the index.

> 
> I can see where you're coming from in terms of simple syntax, but
> that's a fairly constrained interface and I tend to find that I need
> things like:
> 
> for v, u, w in obj:give_me_several_values() do ... end
> for v in obj:choose_an_order() do ... end
> for v in obj:choose_a_set_of_elements() do ... end
> 

Of course, what is being suggested does not *preclude* you from doing this
also, '__iter' just *allows* the specification of a default iterator, it
does not *enforce* it, or preclude supplying additional iterator factories
as well. Mainly it is intended for writing object oriented collections like
Set, List, Dictionary etc. which would have a "natural" iteration strategy.