[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Regarding the name 'pairs'
- From: steve donovan <steve.j.donovan@...>
- Date: Wed, 9 Sep 2009 13:14:13 +0200
On Wed, Sep 9, 2009 at 1:02 PM, Luiz Henrique de
Figueiredo<lhf@tecgraf.puc-rio.br> wrote:
> You can do that already:
> http://lua-users.org/lists/lua-l/2009-06/msg00221.html
I was toying with this for the Penlight list class, and indeed you can
get for i,v in ls do ... end going nicely. But I did not succeed in
getting a Python-style default iterator, that is, just over the
values; this needs an iterator with state.
The problem is that then your lists (whatever) need to be callable for
that particular use. This can make for confusion, in the case you
pass a list by mistake to a function expecting a 'callable'. I used
to enjoy making strings callable (so str(i,j) would work like
str:sub(i,j)) but it did cause interesting and obscure error messages
;)
(The string case is doubly dubious, because the string metatable is
shared by all. So all it takes is two people with the same bright
idea, and things fall apart!)