3 ms·
i haven't tried it, but here's my possibly erroneous impression from looking at the web pages the good: - string interpolation - a continue statement - cond
by kragen 3y ago
i haven't tried it, but here's my possibly erroneous impression from looking at the web pages
the good:
- string interpolation
- a continue statement
- conditional expressions
- augmented assignment
- frozen tables
- some kind of static typing?
the bad:
- much worse documentation
- no luajit
- you can't compile without c++‽ that's the opposite extreme from 'retains the easy embeddability of Lua'
- and wtf, a build system in php? the nope level is rising rapidly
- you still index from 1
- variables are still global by default
- misspelling a variable or property still gives you nil instead of throwing an exception
- aping c++/java syntax and semantics for classes and class instantiation
- redundant aliases for operators
- a redundant mechanism for private fields
- dwim for for-in on a table
it seems like a c++ or perl programmer didn't understand what was good about lua and decided to make it look like perl
- nmz 3y agoAt least for continues and frozen tables, lua already semi offered them via goto and setting __newindex in a metatable. Conditional expression which I imagine is ternaries can be done with a constructor and the condition in the field a la {nil,"b"}[cond and 1 or 2]
- kragen 3y agooh thanks! i generally use lua 5.1, because that's what minetest and luajit use, and lua 5.1 doesn't have goto. though i see luajit has added it!
- ratdeptrai 3y ago> - misspelling a variable or property still gives you nil instead of throwing an exception Isn't that the whole point of "frozen tables", which you listed as "good"? For globals, freeze `_G` and/or `_ENV`. https://pluto-lang.org/docs/New%20Features/Table%20Freezing https://pluto-lang.org/docs/New%20Features/Table%20Freezing
- nmz 3y agoThat sounds more like a setmetatable(tbl,{__index = function () error"got nil" end}) variables are harder but you can make a wrapper function that errors whenever you get nil. I cannot even imagine how pattern matching will work when it always returns nil, not to mention tables are full of nil sometimes, it would be an incredible waste to have a table full of false instead of nil.
- kragen 3y agoagreed about the property thing, though it sort of makes nil even less of a first-class value than it already is what do you mean about pattern matching
- nmz 3y agoWhenever a pattern match fails, be it string.match or string.find, it returns nil. Could it return false instead?
- kragen 3y agooh, hmm, interesting. the concern is that if you store that nil in a variable (as opposed to using it immediately for control flow) you can't get it out again if loading a variable that has been set to nil continues to behave the same way as loading a misspelled variable? i may be falling into the trap of trying to make language x more like language y that i'm more familiar with, but i think that if a language has one or more nil values, it's usually worthwhile to draw a distinction between a variable that has one of those values and a variable that doesn't exist at all. lua gets some simplicity out of conflating these situations, because it means it doesn't need a separate mechanism for causing variables to cease to exist (you can simply assign nil), and sometimes it can simplify your code by leaving initialization implicit. but i think that the result is that lua is a lot more bug-prone languages that do draw a distinction between not existing, and existing with a null value, include smalltalk, ruby, c, c++, python, javascript, perl, python, tcl, java, the bourne shell (except perhaps very early versions), pascal, common lisp, scheme, golang, rust, octave, and most assembly languages. conflating the two is not completely unique to lua; awk, basic, and arguably fortran 77 do that, though the nil value they give previously nonexistent variables is a numeric 0 rather than Γ the bourne shell and by default perl also allow reads from nonexistent variables with well-defined semantics, and perl and js also allow reads from nonexistent table slots (hash and array slots) with well-defined but sometimes startling semantics. but none of these have the behavior shared by lua, awk, basic, and arguably fortran 77, where there's no way to tell the difference between a nonexistent variable and a variable that has had the null value assigned to it so i think that lua's design choice here should be regarded as an experimental innovation, like java's checked exceptions; and, specifically, a failed one so there would be no problem with pattern matching returning nil and storing it in a variable