5 ms·
Pluto, a Modern Lua Dialect
- kwertyoowiyop 3y agoThe landing page ought to show some examples of the differences between Lua and Pluto.
- jadodev 3y agoDirect link to all the new features: https://pluto-lang.org/docs/category/new-features https://pluto-lang.org/docs/category/new-features
- trynumber9 3y agoI genuinely think adding "classes, class inheritance" to Lua is a downgrade. There are many different systems, which you'll still encounter when using other Lua libraries anyway. Why add another? Requiring C++17 to build is also a downgrade. The lambda shorthand looks fine. Typing might be useful. But it says that's WIP so I'll have to try it out more than the examples. Default arguments, named arguments, the added general operators and safe navigation operators are generally useful and positive changes.
- nine_k 3y agoI would say that nearly every Pluto feature not marked as special on the https://pluto-lang.org/docs/Compatibility https://pluto-lang.org/docs/Compatibility page would be a fine addition to mainline Lua. These are small quality-of-life improvements, battle-tested in other languages, with nearly zero new conceptual load. Compiler message improvements would be great to port, too. I see Pluto as a research project of sorts, trying new things. Trying incompatible and controversial things in such a project is the point.
- deleted 3y ago[deleted]
- whalesalad 3y agoInteresting that it contains a PHP-based build system https://pluto-lang.org/docs/Getting%20Started#php-scripts https://pluto-lang.org/docs/Getting%20Started#php-scripts
- mdaniel 3y ago"Interesting" is not the word I would use for that Where does `$file` come from in `for_each_obj` <https://github.com/PlutoLang/Pluto/blob/0.8.0/scripts/compile.php#L7-L11 https://github.com/PlutoLang/Pluto/blob/0.8.0/scripts/compil...> ... from `scandir` of "src" of course: https://github.com/PlutoLang/Pluto/blob/0.8.0/scripts/common.php#L56-L65 https://github.com/PlutoLang/Pluto/blob/0.8.0/scripts/common... Here's hoping you didn't want to alter the intermediate output directory away from "int" or change the CPPFLAGS for your own setup I'm certainly no php ninja, but I'd put good money that a similarly homegrown bash build system would be about an equal number of lines of code but 1/10000th the WTF and not require an apt-get install before trying to contribute to the project
- cardanome 3y agoAs a PHP dev, even I am perplexed by this. I normally just use Bash. Then again, writing maintainable Bash is a pain so I don't totally hate it. Definitely have wrestled with a fair share of write-only Bash scripts where I was tempted to rewrite them in PHP.
- winrid 3y agoGood Python or even PHP is eons better to work with than Bash.
- srhtftw 3y agoJust tried it online¹ to see how it deals with a long standing problem² I have with Lua and I'm pleased to see actual improvement in the form of a warning: script.pluto:1: warning: function was hinted to return string but actually returns nil [type-mismatch] 1 | function foo(x: number): string | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ here Unfortunately the underlying table was corrupted when the code ran and only 1 foo was generated in the output. I would have preferred it to have refused to run at all (will need to look in the docs to see if there's a way to get that behavior with configuration). The purist in me wants more but the practical side of me appreciates that this is definitely an improvement over current Lua. ¹: https://pluto-lang.org/web/#code=function%20foo(x%3A%20number)%3A%20string%20%0A%20%20if%20x%20%3D%3D%202%20then%20return%20nil%20else%20return%20%22foo%22%20end%0Aend%0A%0Ax%20%3D%20%7B%20foo(1)%2C%20foo(2)%2C%20foo(3)%20%7D%0A%0Afor%20i%2Cv%20in%20ipairs(x)%20do%0A%20print(i%2Cv)%0Aend https://pluto-lang.org/web/#code=function%20foo(x%3A%20numbe... ²: https://news.ycombinator.com/item?id=38030778 https://news.ycombinator.com/item?id=38030778
- djur 3y agoIt looks like you can set any warning to cause an error with a pragma: https://pluto-lang.org/docs/New%20Features/Compiler%20Warnings#changing-warning-states https://pluto-lang.org/docs/New%20Features/Compiler%20Warnin...
- naniwaduni 3y agoIt's not "corruption" when you don't understand the semantics of the functions you're calling—ipairs stops at the smallest integer index that doesn't have a value. You can still find that the key 3 exists with pairs; you can't find the key 2, because it's not in the table. The language just doesn't distinguish "key present with no value" in a table, which is frankly a bizarre thing to want with typechecking in the same breath.
- srhtftw 3y agoYou make a good point: since "pairs" returns all the values as it should, calling the table "corrupted" may be too harsh. It's been so long now I can't recall why the original code I found this problem in used "ipairs" instead of "pairs". It's simply not safe to use "ipairs" on a table containing a nil and the code that did that was wrong. I think working with newer languages like Typescript have made me unsatisfied with languages like Lua which provide no clear way to prevent this sort of mistake, so I like that dialects like Pluto are showing ways Lua could be improved.
- haberman 3y agoIdeally a new Lua dialect would be capable of compiling to both Lua and LuaJIT. The language is effectively forked, with the fastest implementation (LuaJIT) and the official implementation (Lua) living in seemingly irreconcilable worlds.
- giraffe_lady 3y agoEh it's not just luajit and luajit didn't create that problem either. It's a symptom of lua actually succeeding at its design goal of being easily embedded as an extension language. A handful of incompatible runtimes are more popular than the most recent puc lua, including I believe the older official lua 5.2 released in 2011. I've done a fair bit of professional lua development and I don't think I've ever written standalone up-to-date puc lua except maybe for some tooling & scripts. It's such a small language and used in such a way that the runtime, distribution method, and available APIs have much more impact on your use (and compatibility) than the version. Virtually everyone shipping a lua environment is also shipping changes to it that make it a unique target, if only extensions to the standard library. This is why I think syntax layer-only approach like fennel's is the correct choice for improving on lua. It mirrors lua's runtime semantics exactly, and allows you to access the implementation peculiars on their own terms and so can just be run on top of any lua system. https://fennel-lang.org https://fennel-lang.org
- PsyNyde 3y agoi don't think this maintains the simplicity that lua offers.
- marwis 3y agoNeeds compiled binary size comparison somewhere on the website
- cardanome 3y agoThe Nil-Coalescing Operator they add is actually redundant. Instead of their new fancy syntax: print(message ?? "The message was nil.") The idiomatic way would be: print(message or "The message was nil.") The or operator works just fine. (Edit: Note that this works because empty strings, lists and the number 0 are all truthy in Lua) Generally not a big fan of adding additional syntax and operators for minimal gain. I feel like most changes are nice to have but not really worth the disadvantage of not being able to use LuaJIT. Honestly, the most interesting goal for me is is having a beefier Python-style standard library. Now, if we had that together with LuaJIT levels of performance that would be an absolute Python killer. The only actual problem with Lua (that can't be fixed without forking) is that new variables are global by default but you can cope with that. Just have your linter check that you are always using the "local" keyword. Couldn't find if Pluto is fixing that. Edit: Oh they provide a "let" alias for "local", case in point, little changes with not much value.
- DemocracyFTW2 3y agoNo it's not the same; `x ?? 'foo'` evaluates to `x` when `x` is not `nil` and to `'foo'` otherwise; `x or 'foo'` evaluates to `x` when `x` is not one of `nil` or `false`, and to `'foo'` otherwise. This idiom seems to have been made widely popular by Perl folks, and while it has always been a good trick up your sleeve when you're 16 and want to impress the other kids, it's never been a good, correct way of doing things seriously, especially not across different scripting languages when every single one has its own Byzantine rules of what counts as truthy and what as falsey (like empty strings or empty lists). It is an especially pernicious idiom because of the widespread clout with which it tends to be transmitted; turns out it's one of the Falsehoods Clever Programmers Think They Know Better About. They don't.
- ledauphin 3y agoi can see you are probably a polyglot, working in several languages with regularity. it would certainly be frustrating to have to juggle these semantics as you switched back and forth. however, languages are just that - they have their own meanings, and unfortunately they can't all be the same across languages (or they'd all be the same language).
- user8501 3y agoTestes? Do you mean tests?
- omoikane 3y agoThe compound operators[1] are also in Playdate's variant of Lua[2]. The "continue" statement[3] is the one I really wish was available everywhere. [1] https://pluto-lang.org/docs/New%20Operators#compound-operators https://pluto-lang.org/docs/New%20Operators#compound-operato... [2] https://sdk.play.date/2.1.1/Inside%20Playdate.html#_lua_enhancements https://sdk.play.date/2.1.1/Inside%20Playdate.html#_lua_enha... [3] https://pluto-lang.org/docs/New%20Features/Continue%20Statement https://pluto-lang.org/docs/New%20Features/Continue%20Statem...
- teamonkey 3y agoAlternatively, Luau is a well-supported Lua variant with type checking and performance improvements, aimed more towards being a sandboxed embedded scripting environment. https://luau-lang.org/ https://luau-lang.org/
- nikolay 3y agoPlus, it's widely used, thanks to Roblox!
- m0llusk 3y agoNot a planet!
- kragen 3y agoi 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.
- harpiaharpyja 3y agoOdd syntax choices. The ones that stand out for me are "enum class" for scoped enums, and ":" as the delimiter in switch statements. It doesn't seem really well thought out.
- nine_k 3y agoI frankly find the whole idea of the switch statement unfortunate. The switch statement in C has a really understandable compiled representation: linear code where you can jump into in the middle. It was fine in 1970. But in 2023 I'd expect introduction of pattern matching instead, which generalizes the idea much better. Python pulled this off successfully. Java pulled it off successfully. Lua could, too.
- celeritascelery 3y agoI looked into the jump table optimization. The normal Lua version is here[1] and it uses the opcode as a index into a static array to jump to the label. The “faster” Pluto version is here[2] and it just uses a switch statement on the labels. I would naively assume that these would compile to the same code because the lua version is just manually creating the jump table and the pluto version is leaving it to the compiler. How could the compiler optimize the switch so that would outperform the manual jump table (by a decent margin)? [1] https://github.com/PlutoLang/Pluto/blob/main/src/ljumptabgcc.h https://github.com/PlutoLang/Pluto/blob/main/src/ljumptabgcc... [2] https://github.com/PlutoLang/Pluto/blob/main/src/ljumptab.h https://github.com/PlutoLang/Pluto/blob/main/src/ljumptab.h
- shamesssles 3y ago[flagged]
- imbnwa 3y agoYuescript https://yuescript.org https://yuescript.org
- bawolff 3y agoOne thing i like about lua, is that it is a very intentionally designed language with what it does or does not support. Many of the things pluto adss seem to be things that lua intentionally omitted as a design choice.
- npage97 3y agoRequiring c++17 seems like a big change from standard lua.
- vodou 3y agoPLUTO is already a reference language for test and operations procedures for satellites and spacecrafts. https://ecss.nl/standard/ecss-e-st-70-32c-test-and-operations-procedure-language/ https://ecss.nl/standard/ecss-e-st-70-32c-test-and-operation...
- ratdeptrai 3y agoPerhaps even more relevant, it's already the name of a persistence library for Lua. Probably unmaintained at this point, but it's been around for decades (version 1.2 was released in 2004). Unless names are invented words, collisions are inevitable at this point. http://lua-users.org/wiki/PlutoLibrary http://lua-users.org/wiki/PlutoLibrary https://github.com/hoelzro/pluto https://github.com/hoelzro/pluto
- teo_zero 3y agoWhy perpetrating the mistakes of our venerable predecessors, in the form of automatic fallthrough for switch statements?
- landswipe 3y agoThis is interesting, but lua needs a refresh. I think berrylang shows a lot of promise now https://berry-lang.github.io/ https://berry-lang.github.io/. The documentation has improved a lot and while it doesn't have a 'luajit' yet it has a lot of really interesting optimisation/reduction techniques.
- ratdeptrai 3y agoWhat is lacking is any space for community. No mailing-list or other place to discuss the direction of the project. No documentation expressing what is the overall reason or rationale behind the project, or who are the main contributors, how decisions are made, no roadmap. There seems to be zero braking force on adding new features to the syntax and libraries. While I agree with 90% of them, I can find no discussion of why they were added, what arguments against adding were considered, how the decision was made, and by whom. I have created my own (as yet unreleased) fork of Lua, adding some of these same features. I could abandon it and instead use (and contribute to) Pluto, but I am frightened by the mystery surrounding its origins, governance, and seeming lack of community input into the future direction.