3 ms·
lua could be really nice if they fixed these: indexing starts at 1 but a[0]=1 does SOMETHING -- // # stupid -- comments! // 0 is truthy # I just love the s
by singularity2001 8y ago
lua could be really nice if they fixed these:
indexing starts at 1 but a[0]=1 does SOMETHING
-- // # stupid -- comments! //
0 is truthy # I just love the simple logical mathematical python way (0=ø=()=[]={}=false)
if undefined … -- treated as nil
function pseudoclass:new …
But by far the biggest complain is the packaging. luarocks SUCKS more than almost anything, at least for me.
luarocks install torch
Error: Your user does not have write permissions
sudo luarocks install torch
Error: No results matching query were found.
and on and on and on
(non-representative excerpt of my pains)
- cozuya 8y agojavascript could be really nice if they fixed these: 0 is falsey
- andrewmcwatters 8y ago> 0 is truthy Nope. 0 being falsy only makes sense in pointer-oriented languages where NULL is a null pointer at address 0. In Lua, 0 is a number. It's not a pointer address. Which leads to: > a={1} a[0]==nil a[1]==1 indexing starts at 1 but a[0]=1 does SOMETHING So does -1: should -1 be falsy, too? > if undefined … -- treated as nil Pardon? It is. Are you asking for an undefined keyword? Why? In the Lua C API, you already get `lua_isnoneornil` to begin with. > function pseudoclass:new … Lua is a prototypal language. > but by far the biggest complain is the packaging. You know, thank God. Because JavaScript is probably the closest thing to Lua and look how that turned out. The only thing holding it back is that the community doesn't need or want it. It's also small enough that perhaps no one has made a good package manager for Lua yet. But the `package` module in Lua already provides search paths, so it's fairly low effort. Frankly, I've never had a need for it. I don't want npm for Lua.
- oweiler 8y agoYou just need to remember that only false and nil are false.
- int_19h 8y agoUsing -- for comments is a long-established convention: Ada, Eiffel, SQL... 0 (and everything but nil and false) is truthy is also pretty common in the Lisp world. Side note: I actually find it ironic that Python of all languages does this implicit falseness thing on so many types, given that it puts "explicit is better than implicit" on its banner. I don't see the difference between treating an empty list as false when the context requires a Boolean value, and treating string '0' as numeric 0 when the context requires a numeric value. And it can be a source of bugs - while there are many cases where an empty list and None are semantically equivalent, that's not always true. And it can be something that's very easy to forget when reading code that is broken that way (e.g. during code reviews). I'd much rather have functions like `is_none_or_empty`, `is_none_or_zero` etc that make it clear what the check is actually doing.