lua-users home
lua-l archive

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


Hello,

Has it ever been proposed to restrict, by definition, #t and len(t) to plain sequences? In the sense of tables which list of ordinal keys is 1..#t (whatever the non-ordinal ones may be).
I don't know if this could be done easily. Maybe the language could maintain a flag "holy" ;-) set to true when a user explicitely sets t[n], with n<0 or n>#t. Then #t itself would return nil, for instance, which cannot bring confusion I guess.
In ordinary use cases of tables as sequences, they are fed by appending, so there is no issue. The problem is item change, which requires an explicite index. (*)

Denis

(*) Otherwise we could state that using an explicite ordinal index breaks the semantics of #; without even comparing its value to #t, which is costly since #t is not maintained.
The issue comes from the fact that Lua, like most (all?) PLs indeed, uses a notion of "set" that prevents making the difference between creating or putting a new value, on one side, and changing an existing one on the other.
________________________________

vit esse estrany ☣

spir.wikidot.com