lua-users home
lua-l archive

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


Am 27.01.2016 um 19:34 schrieb Dirk Laurie:
> 2016-01-27 19:11 GMT+02:00 Stephan Hennig <sh-list@posteo.net>:
> 
>> 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[1]), (2,t[2]), ..., up to the
>     first nil value.
> 
> The notation t[1] 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
gettable_event().


> 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 ...

Best regards,
Stephan Hennig