News for hackers. Stuff that matters.
Re:A History of Lua (2001) by citrin_ru on Wednesday August 10, 2022 @04:59AM (#32409404)
> magic nil behaviour

What is magic in Lua nil? nil being false makes nil different from other non-boolean types, but it is both intuitive and convenient (I don't know a language where null/nil/undef are true in boolean context). What makes Lua a bit different from other script languages is that 0, "0", "", {} e. t. c. are not false in Lua. But it allows to avoid mess with truthy/falsy values we have in other script languages.

Re:A History of Lua (2001) by edflsafoiewq on Wednesday August 10, 2022 @05:12AM (#32409462)
nil is like the absence of a value, reified into a value. Reading a variable that doesn't exist produces nil, and assigning nil deletes the variable.
Re:A History of Lua (2001) by DemocracyFTW2 on Wednesday August 10, 2022 @05:59AM (#32409710)
Having a value that, when assigned to a variable or property, elides or deletes it is actually a desirable feature in MHO. Arguably, JavaScript's `undefined` should act like that, or nowadays more probably a well-known symbol. It's at any rate a nuisance that introducing one cavalier 'simplicity' (you can access `d.x` even when it does not exist, but you'll get `undefined` as value) causes so much accidental complexity (now you have to distinguish between so many fringe conditions (does `d` have a key `x`? does `d.x == undefined` mean `x` is set on `d`?). OTOH if you don't have a value that deletes a key from an object, then you'll have to special-case that operation because `delete d.x`, apart from being revolting syntactically, only exists as a syntactical construct.
Re:A History of Lua (2001) by lenkite on Wednesday August 10, 2022 @06:21AM (#32409830)
Lua tables make no distinction between a table value being nil and the corresponding key not existing in the table necessitating hacks like: http://lua-users.org/wiki/StoringNilsInTables
Re:A History of Lua (2001) by edflsafoiewq on Wednesday August 10, 2022 @06:32AM (#32409893)
Yeah, that's the point of nil. If you're trying to store it in a table, you're just fighting the language. Is there a good motivation for doing that?
Re:A History of Lua (2001) by samatman on Wednesday August 10, 2022 @10:49AM (#32412940)
I've done this on two rare occasions: round-tripping 'null' in JSON and 'NULL' in database queries.

My solution, which was perhaps overly cute, was a table canonically named No, which is callable such that No(nil), No(false), and No(No) all return true.

So I could say

   if No(value) then
When I needed to do conditional logic which excludes those reified null values, which isn't often.
Re:A History of Lua (2001) by lloeki on Wednesday August 10, 2022 @05:45AM (#32409626)
> What makes Lua a bit different from other script languages is that 0, "0", "", {} e. t. c. are not false in Lua.

In Ruby only nil and false are falsey, everything else is truthy.

Re:A History of Lua (2001) by Banana699 on Wednesday August 10, 2022 @06:27AM (#32409864)
Same as Scheme.
Re:A History of Lua (2001) by actondev on Tuesday August 16, 2022 @11:27AM (#32484078)
nil is not fasley in Scheme. There is no falsey is sense that only #f is false :)