[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: [manual] ipairs vs. #
- From: Stephan Hennig <sh-list@...>
- Date: Wed, 27 Jan 2016 21:48:51 +0100
Am 27.01.2016 um 19:34 schrieb Dirk Laurie:
> 2016-01-27 19:11 GMT+02:00 Stephan Hennig <email@example.com>:
>> The fact that iterating over table elements via ipairs and iterating over
>> table indices 1 to #t are not equal operations has been discussed on
>> this list before. But it is neither mentioned in the section describing
>> ipairs nor in the section describing the # operator. I think this fact
>> deserves more visibility in the manual.
> The manual is very cute at saying enough, but only barely.
The Lua dichotomy: Verbose language, terse manual.
> In this case it says
> will iterate over the key–value pairs (1,t), (2,t), ..., up to the
> first nil value.
> The notation t implies that __index is respected,
That implication may be inferred from
An access to an indexed variable t[i] is equivalent to a call
gettable_event(t,i). (See §2.4 for a complete description of the
gettable_event function. This function is not defined or callable
in Lua. We use it here only for explanatory purposes.)
a) All the "not defined or callable" and "only for" trigger the
irrelevance bell. Instead of soft-pedalling, this section needs to put
a strong emphasis on the importance of gettable_event() for
understanding table operations.
b) Peeking at §2.4, I can't find any discussion of a function named
> the failure to mention #t means that __len is ignored. Terse, but it
> has always been like that.
I'm not an adherent of the terse manual cult. Those haunting doubts it
could be even less verbose ...