12 ms·
Gravity: An embeddable programming language without any external dependencies
- dang 6y agoSee also from 2018: https://news.ycombinator.com/item?id=17373545 https://news.ycombinator.com/item?id=17373545
- astatine 6y agoI imagine this would be an alternative where embedded Lua gets used. A comparison with Lua would have been great to see. The 200K runtime, for example, indicates that this might weigh in somewhat heavier than Lua.
- vorpalhex 6y agoAs someone who just worked on a project where I embedded lua, that's exactly what I was looking for. Why would I want to choose this over lua and what's the pro/con matrix?
- kevin_thibedeau 6y ago0-based array indexing and local scoping by default.
- theptip 6y agoAgreed, Lua seems to be the de-facto standard here, as it's so lightweight to embed. But the language has some pretty janky rough edges (e.g. only having Tables and no other data structures) so a modern alternative would be nice.
- runawaybottle 6y agoIsn’t that what makes it lightweight? It literally doesn’t have the extra weight.
- tastyminerals 6y agoOnce you get to know Lua tables and then metatables, you will question the existence of different data structures :)
- jmiskovic 6y agoYes, Lua tables are incredibly versatile tool. I'm not a fan of global-scope-by-default and of verbosity, but other than that it's a fantastic language.
- craftinator 6y agoI think global by default is one of the reason Lua shines in the embedded world. Not many other arenas where that is good practice.
- zem 6y agoeditor scripting, perhaps
- centimeter 6y agoGlobal scope by default isn't good practice in embedded. Global scope isn't synonymous with static allocation, but unfortunately that goes over the head of many people. Best practice in embedded is to have locally scoped statically allocated data passed around by reference.
- craftinator 6y agoIt really depends on the application. For smaller, more targetted embedded applications, global scope is fine. If every function needs to have access to a common set of variables, there's really no need to be passing references around.
- cygx 6y agoIf such a comparison gets added, Wren[1] might also be of interest. [1] https://wren.io/ https://wren.io/
- ctas 6y agoThe similarity to Gravity is astonishing.
- deleted 6y ago[deleted]
- mythz 6y agoWren and Bob Nystrom are called out as major inspirations: https://github.com/marcobambini/gravity#special-thanks https://github.com/marcobambini/gravity#special-thanks
- fallat 6y agowren is so far my favorite small, simple language.
- Rochus 6y agoLua is indeed difficult to beat in this respect. If you need performance you can even embedd LuaJIT with a footprint still far under one megabyte. And if you don't like the Lua syntax, there are already good alternatives,e.g. the statically/strongly typed https://github.com/rochus-keller/Oberon https://github.com/rochus-keller/Oberon which directly generates LuaJIT bytecode (based on https://github.com/rochus-keller/LjTools https://github.com/rochus-keller/LjTools). Here is a fairly complete list of languages compiling to Lua: https://github.com/hengestone/lua-languages https://github.com/hengestone/lua-languages. Gravity could be one of these if need be.
- zeotroph 6y agoLuaJIT development has effectively halted, and only supports Lua 5.1 (5.3 is current, 5.4 imminent). I get the feeling that Lua is slowly on its way out because the academic nature of it never meant it had to be more than "good enough" outside it's core strengths. I think they should have kept a super-light "classic" Lua where ~= still means !=, there are only tables, and all the other quirks (but also speed). Then add official, optional support for classes, lists, dicts, sets. This probably can all be built on top of setmetatable, so be pure lua, but at least it comes as one consistent standard library and not in the form of a fractured ecosystem. All the mentioned compiles-to-lua Projects tried something similar, but never gained significant traction, probably because of the lack of an official blessing.
- Rochus 6y ago> LuaJIT development has effectively halted ... never meant it had to be more than "good enough" outside it's core strengths That's a wrong impression. Even the original author of LuaJIT still commits regularly and there are dozens of companies maintaining and using it in industrial scale applications, and there are a couple of forks which focus on specific use cases and are independently developed. Not to forget the hundreds of games using Lua as a scripting language. > only supports Lua 5.1 (5.3 is current, 5.4 imminent). Which is obviously enough for most people using it including me. I don't see any unique selling point which would force me to update to Lua 5.3 or higher. > and all the other quirks (but also speed). Well, do your research. LuaJIT is among the fastest JITs available (e.g. a factor ~1.5 faster in geometric mean than JS V8), but with a much smaller footprint.
- blacksqr 6y agoThe first thing I want to know about a new language is its performance. Then I can start thinking meaningfully about the tradeoffs of using it compared to other languages.
- flohofwoe 6y agoFor an embeddable language performance probably isn't the most important property for typical use cases. Ease of integration, interopability with the "host" language, the embedded size of the scripting engine or compiler etc..., all might be more important.
- carapace 6y agoFWIW, the first thing I want to know about a new language is it's "debug story": how deep in the mud am I when something goes wrong?
- mkchoi212 6y agoAfter having looked at it for a minute, it looks like a very simplified version of Swift. Looks great! Might try out the language on my Raspberry Pi and see how fast the thing is :p
- sigzero 6y ago"It is a class-based concurrent scripting language with a modern Swift like syntax."
- fra 6y agoHas anybody tried compiling this for an embedded target (e.g. Cortex-M4, arm-none-eabi)?
- gutino 6y agoThe fact that it sets null to uninitialized variables is mindblowing for lang created within the past 5 years. We all have learned that there "null" is there just to create bugs. Please Consider creating a Gravity 2.0 with this fixed as a compile error, you will save a lot of debugging time to your users.
- skrebbel 6y agoPure FP isn't the only acceptable programming paradigm, please stop pretending that it is. (For context: a language without null pretty much implies an Option type, which is mostly useless (or no better than null itself) without static typing. Once you're that far you're probably gonna want to get monads to make them workable and congratulations you're reinventing Haskell)
- baq 6y agoRust is quite far from pure FP.
- alipang 6y agoFound the guy who completely missed Kotlin, TypeScript and Scala.
- skrebbel 6y agoAll three of which have null? TypeScript even has two kinds of null. Scala even has monads as well! :-)
- neurotrace 6y agoTypeScript requires you to verify if the value is null-ish or not (assuming you're using the new default "strict mode"). I don't believe Gravity does
- enricozb 6y agoSince when does static typing imply monads...
- huhtenberg 6y agoSlightly off-topic, but that's one beautifully done website.
- mythz 6y agoCame here to say the same thing, that's some gorgeous docs for a hobby language, no doubt the primary author has excellent designer skills.
- tylerscott 6y agoAgreed, but I do see some heavy inspiration from the Twitter Bootstrap logo and design.
- yencabulator 6y agoThe full-page pointless obstruction you have to scroll past to see anything useful is the opposite of beautiful to me.
- CGamesPlay 6y agoTo be completely honest with you, I didn't even realize I could scroll. That full-page landing page did have what I wanted, a single-sentence summary and a "get started" button to take me to the documentation, which loaded impressively quickly. I just found out that it was because it was on the same page.
- ej12n 6y agouses docsify + https://jhildenbiddle.github.io/docsify-themeable/#/ https://jhildenbiddle.github.io/docsify-themeable/#/ in case anyone is interested.
- ctas 6y agoDid anyone use Gravity before and make a comment about the ecosystem / community growth perspective?
- creatornator 6y agoI never really used it, but I did make some contributions to the language. In looking through some of the ecosystem, it seemed like the library ecosystem left a bit to be desired, but the standard library does show promise. I think its extensibility (proven by my ability as a noob to make useful stdlib contributions) and use cases in embedded applications mitigates the lacking ecosystem somewhat.
- thickbiscuit 6y agoHow do you import a library?
- thickbiscuit 6y agoApparently you can’t. I guess they’re serious when they say “no external dependencies.” On the plus side there’s no need for a package manager.
- Koshkin 6y agoI am disappointed to see yet another language suffer from the same old semicolon cancer.
- ctas 6y agoCalling it cancer is a bit hard. But I agree that semicolons are likely unnecessary.
- carapace 6y ago(It's a play on "colon cancer", eh?)
- jayrhynas 6y agoApparently they're "completely optional"[1] but they chose to use them in all the examples ¯\_(ツ)_/¯ [1]: https://marcobambini.github.io/gravity/#/syntax https://marcobambini.github.io/gravity/#/syntax
- FpUser 6y agoI see no problem with semicolons. I guess it is mostly personal preferences. Мышкин ;)
- nurettin 6y ago>Features >multipass compiler irony is that this used to be a negative thing back in pascal days.
- baq 6y agoI used to mock Pascal. I feel mildly ashamed of this now. Turns out Pascal was simply a bit ahead of its time language-wise.
- a-nikolaev 6y agoThe documentation says: > Closures are self-contained blocks of functionality that can be passed around and used in your code. Closures can capture and store references to any constants and variables from the context in which they are defined. Closures can be nested and can be anonymous (without a name) I think, the term "closure" gains some unnecessary semantic meaning of a block of code / anonymous function. I might be wrong, but It is better to think about it as simply a technique for implementing lexical scoping. In other words, "lexical scoping" is a property of a language, while "closure" is only an implementation detail to make lexical scoping work. So the term closure does not have to leak in the description and semantics of the language itself. What is your opinion? Edit: I just think that such proliferation of terminology confuses people, making them ask questions like: "What is the difference between 1) function, 2) anonymous function, 3) lambda function, 4) closure?" Instead, focusing on the idea of a function (possibly without a name) + lexical scoping clarifies everything immediately.
- traes 6y agoClosures aren't necessary for lexical scoping, and in practice they're only real use (in imperative languages, obviously quite different in e.g. Haskell) is to pass around blocks of code combined with captured variables. I think this definition is quite reasonable.
- a-nikolaev 6y agoBut such a closure block is a function (it might be sugared like a ruby block or something like that, but it remains a function that captures its environment, thus implementing lexical scoping). Well, okay, if a language does not normally have lexical scoping, but has a special "closure" feature to implement it (dunno, maybe C++ lambdas may be regarded as such a special closure construct?) That could be a justification for the term closure on its own. But if the language has lexical scoping by default (e.g. Gravity says that it has lexical scoping in its overview), then, I think, there is no need in a separate notion of "closure" in the language semantics.
- codr7 6y ago
- ivoras 6y ago> Gravity has been developed from scratch for the Creo project in order to offer an easy way to write portable code for the iOS and Android platforms. ... so, now we CAN have scriptable / interpreted code in iOS?
- ricardobeat 6y agoYou always could, any of the thousands of React Native, Flutter or NativeScript apps are running a VM. What you can't do is run code that the user provides, or use it to sidestep app store updates (with plenty of exceptions for both rules).
- drdeca 6y agoThere are iOS apps that allow you to edit and run python code. The amount that it can do with the OS and stuff is fairly locked down, but in the version I used to have installed (incompatible with iOS 11, so I can’t use it anymore) iirc even allowed using import os to use some shell commands (though, of course, the shell was very locked down).
- klodolph 6y agoYou also can’t mprotect PROT_EXEC, which means no JIT.
- _bxg1 6y agoI think what you're thinking of is the JavaScript JIT situation. A JIT compiles and executes arbitrary, new, native code at runtime. A regular interpreter doesn't create native code.
- creatornator 6y agoI had the pleasure of contributing to Gravity a few years ago. I added builtin filter, map, reduce, reverse, and sort functions and tests to the array types. Marco was very receptive to my additions, and it felt very welcoming to newcomers. I learned a lot about different internal workings of interpreters making those contributions.
- vmchale 6y agoCool stuff! Thanks for sharing.