lua-users home
lua-l archive

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


X = trunk.branch.leaf

 

If “leaf” is nil, “X” will be set to nil, but if “branch” or “trunk” is nil, this is an error “attempt to index a nil value”. Surely it would be architecturally more consistent (and practically more useful) if an attempt to index a nil value evaluated to nil?

 

From a recent piece of code I’ve written:

 

a = tb[p1]; if not a then return end

a = a[p2]; if not a then return end

a = a[p3]; if not a then return end

a = a[p4]; if not a then return end

 

It would have been neat to be able just to write:

 

a = tb[p1][p2][p3][p4]

if not a then return end

 

- John Hind

Attachment: smime.p7s
Description: S/MIME cryptographic signature