[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Multiple values returned or vararg expression in numeric for loop
- From: Dirk Laurie <dirk.laurie@...>
- Date: Tue, 18 Sep 2012 10:24:13 +0200
2012/9/16 Fidelis Assis <fidelis.assis@gmail.com>:
> 2012/9/16 Petite Abeille <petite.abeille@gmail.com>:
>>
>> On Sep 16, 2012, at 7:59 PM, Fidelis Assis <fidelis.assis@gmail.com> wrote:
>>
>>> Anyway, I miss the short "for v in t".
>>
>> You can achieve the same effect by making your table 'callable' (i.e. __call) and return an appropriate iterator.
>
> Good, thanks for the suggestion. But doing this naturally with be even
> better :).
>
There's always a trade-off: extra convenience at the cost of reducing
error detection. At present, if you write " in tbl" it means at the very
least that you did not at that moment consciously decide whether it
should be "pairs" or "ipairs". In order to ensure that such inattention
is in fact correct, you should have consciously assigned an appropriate
metamethod to __call. This is sane behaviour which I would not like
to see sacrificed.
I think we've had before (but can't find) a discussion on an __iter
metamethod, with __call being the fallback if there is no __iter.
- References:
- Multiple values returned or vararg expression in numeric for loop, Egor Skriptunoff
- Re: Multiple values returned or vararg expression in numeric for loop, Michal Kolodziejczyk
- Re: Multiple values returned or vararg expression in numeric for loop, Roberto Ierusalimschy
- Re: Multiple values returned or vararg expression in numeric for loop, Dimitris Papavasiliou
- Re: Multiple values returned or vararg expression in numeric for loop, Luiz Henrique de Figueiredo
- Re: Multiple values returned or vararg expression in numeric for loop, Dimitris Papavasiliou
- Re: Multiple values returned or vararg expression in numeric for loop, Roberto Ierusalimschy
- Re: Multiple values returned or vararg expression in numeric for loop, Egor Skriptunoff
- Re: Multiple values returned or vararg expression in numeric for loop, Fidelis Assis
- Re: Multiple values returned or vararg expression in numeric for loop, steve donovan
- Re: Multiple values returned or vararg expression in numeric for loop, Fidelis Assis
- Re: Multiple values returned or vararg expression in numeric for loop, Petite Abeille
- Re: Multiple values returned or vararg expression in numeric for loop, Fidelis Assis