lua-users home
lua-l archive

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


> On Wed, Mar 14, 2018 at 3:01 PM, Roberto Ierusalimschy <
> roberto@inf.puc-rio.br> wrote:
> 
> > How do you store a 'while' in a table?
> 
> If you mean that 'undef' is a keyword on par with 'while', then perhaps it
> could be used with a syntax that is not a value-like, for example:
> 
> undef table[index]
> 

Answering that again:

Yes, I mean that 'undef' is a keyword on par with 'while'. And
't[k]=undef' is a new construction, with the same semantics of
'undef t[k]', that looks like an assignment but it is not an assignment.

Once again: 't[k]=undef' looks like an assignment, but it is not an
assignment. It means "remove the key 'k' from table 't'".

Yes, we could use a syntax that is not a value-like. But that would make
all programs that use that syntax unable to run (or even compile) in older
versions of Lua.

The proposed syntax would allow programs written for 5.4 to run on 5.3
without changes (pending metamethods), and would also allow programs
written for Lua 5.3 to be written with undef (only as an idiom), so
that they would more easily migrate to a future version of Lua where
nil-in-table would be the default semantics (if ever there will be such
version).

So, 't[k]=undef' looks like an assignment on purpose, because in older
versions of Lua the semantics of removing an item from a list was done
through an assignment. But only because it looks like an assignment
it does not mean it is an an assignment.

Just to be sure: 't[k]=undef' looks like an assignment, but
it is not an assignment. It means "remove the key 'k' from table 't'".

-- Roberto