lua-users home
lua-l archive

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

2013/7/7 Andrew Starks <>:

> nil makes a fantastic "empty" sentinel value and a pretty spotty
> (inconsistent) "delete" verb.

> As a delete verb, nil sets a variable name to itself, which means its not
> set to what it was set to before. This gets the job done by side effect,
> quite nicely, but is fundamentally different than deleting something.

> This is always true, except when setting a non-existent field name to nil,
> in which case the field name is left unassigned. If he field name existed
> and then was set to nil, the normal behavior applies. This is, as you said,
> true only by coincidence, but it's still true.

> As empty: nil is *assigned* to a variable name, making that variable name
> very important and busy: cock-blocking access to the same name, further up
> the stack. Without delete, there are some un-doable, very useful and really
> important things to understand about your "variable that is now part of your
> program and does exist and is set to nil."

> [Since adding `delete` is comic gold (not sure why, but it was well written
> so I'm assuming I'm treading on thin ice (wrong)), I'll stay away from
> that...]

There's a lot of philosophy and poetry in the above. However, Lua does
not have the concepts 'assign' and 'delete', only 'name', 'value' and
'garbage collection'. A value is associated with one or more names
without being stored in a space reserved for any of them. Once it is not
associated with any name, it becomes a candidate for garbage collection.

Think of it this way. Values in tables are pieces of luggage. Names are
stickers. You can pull off a sticker. Once a piece of luggage has no
sticker left, it is thrown out of the store. When you need a name again,
you make a new sticker for it.

Values in local variables are stickers on lockers. You can empty out
a locker. An empty locker keeps its sticker, but there are only so many

'delete' was proposed to go with 'has'. What you are deleting is not
the value, nor even the name, but the 'has' property associatd with
the name.