354 points · by ianthehenry · 3y ago · 158 comments
> My favorite feature of Janet, though, is something that sounds really dumb when I say it out loud: you can actually distribute Janet programs to other people. You can compile Janet programs into statically-linked native binaries and give them to people who have never even heard of Janet before. And they can run them without having to install any gems or set up any virtual environments or download any runtimes or anything else like that.
The space is ripe for a lisp that is easily distributable. Yes, common lisp can be statically compiled, but their binaries (at least with sbcl) can get pretty big [1], even with compression. Making a lisp specifically good at using to make CLI or desktop tools with good c ffi support is compelling.
If you want small binaries, then you'd want tree-shaking, not an entirely new language. LispWorks is already capable of producing small, graphical hello world examples. Even then, a hello world is a rather silly benchmark for binary size, especially since it totally ignores the fixed cost of a language runtime and no serious person is distributing a hello world.
- a terraform distro is 59M
- a kubectl distro is 44M
getting rust installed on a windows machine required not just a rust distro, but a visual c++ library set over 1G.
at a certain employer, the size of the teams golang tool was well over 100MB.
So - 50MB to start with a full Lisp image? yeah, sure, no worries.
I've heard that some scheme things will compile out to C even.
https://github.com/LuaDist/srlua
The Lua runtime is 340kB on Windows and there's plenty of projects including the one above (srlua is made by the Lua maintainers) to produce statically linked and dynamically linked binaries.
But it's Lua, so while I loved the language, you have to put up with the tiny list of standard features which can make it a grind.
As someone who's playing with Lua to run an incredibly lightweight HTTP server[1] which requires just a few MB on disk and 1MB of RAM (while supporting stuff like JSON, HTTPS, Sqlite DB, Email, MQTT and a lot more), I would be curious what you think are the problems with Lua.
My SBCL binaries are ±28MB, with the complete Lisp runtime and debugger (cool, I can eval and load configuration files or connect to a remote app) and dozens of dependencies, including a web server.
1: http://www.sbcl.org/manual/#Function-sb_002dext-save_002dlis...
I'm sure I just missed it, but I haven't been able to find an answer to that question yet.
Edit: Probably pretty tiny based on this [0], right?
> The entire language (core library, interpreter, compiler, assembler, PEG) is less than 1MB.
Edit again: Found an example [1]:
> And the size is quite reasonable for a non systems language: the Pong example using Raylib is about 2.4MB on Mac OS Catalina.
Cons:
- 200MiB archives
Pros:
- I can develop a GUI doing some stuff on proprietary binary files, extracting & converting data, generating a handful of plots in a couple of days and have all my colleagues enjoy it without any issue.
If I run `raco exe` on this, I get a 57MB file. On mac, it's only linking system libraries. (For Idris2 programs, there is an Idris support library that is dynamically loaded.)
I haven't tested transporting it to another system (my test was on an arm mac, so I don't have another system to test that on).
on the other hand, i hear that commercial versions of common lisp can achieve better results. but seriously, is this such an issue for todays computers ? i have pdfs that are hundreds of mb
You're paying a higher initial capital cost for lower per-unit costs.
Given that they have similar goals, why not merge and join efforts? Would help in softening the rough edges and reducing the bus factor.
Then again I don't know much about the technical details here (when do you or don't you need your own runtime). It seems baffling to me with all the cruft and bloat in a modern windows install do you still have to install so many microsoft runtimes.
We just don't notice that typical C programs need libc and pthreads. Or that C++ programs on Windows require that cursed Microsoft Visual C++ Runime DLL which is always missing, but has few dozens of copies all over the system of the miserable Microsoft slave.
Go doesn't produce fully statically linked binaries by default. I used to make "from scratch" Go containers and, in general case, you need libc in them, unless you are willing to go through pain of statically linking with it.
Typical / practical Rust programs will also depend on libc and pthreads (but, sure, you can do w/o).
In theory you "can" do that with python too.
"Can" is a very different kettle of fish from "most people are inclined to".
Before you start screaming "cxFreeze/pyOxidizer/pyInstaller", NO. I have gone this route. It is incredibly painful. Python was built with the thought in mind that it would be interpreted. It wasn't engineered well for compilation. A significant amount of effort, often a significant percentage of the total effort, is spent shoehorning things into this as an escape hatch because requirements have changed. This is not the route to choose from the start. Same goes for Clojure and `native-image`. I'm glad the native image project exists, and we all hail babashka as a success story, but it doesn't mean its author didn't have to spend a ton of time with native-image. If you go this route, prepare to spend half your time with the build tool itself, and be prepared for "oh the language technically works with this, but not if I use library x" type disappointments right and left.
The best, most painless route is to go with a language which has thought about the end result of the build pipeline beforehand. Rust and Go are gold standard for this. If I want a Python that is statically compiled, I reach for Go.
So to hear that the language made a bunch of tiny little design decisions up and down the line with the idea of making static executables from the start is, from this DevOps engineer, incredibly compelling.
It takes ~2minutes TOTAL to download, install and compile Graal VM against Java sources to produce a ~11MB debug build native binary. Utterly painless and even measured. You can reduce that considerably further to ~4MB by seeing what modules contribute to the size using the Graal VM dashboard https://www.graalvm.org/dashboard/ and choosing to omit them with a flag.
Frankly, I found it easier to work with than your Rust+Go standard as I can easily see exactly which modules contribute to binary bloat-up and choose alternatives.
There are also excellent, first-class frameworks built from the ground up for Java native compilation like https://quarkus.io/.
But if you’re looking specifically to write small tools distributed as native binaries, Janet sounds like a much better choice.
anyone around knows how does it compare to Chicken?
But on a more serious note, I actually do care because I have around 4,500 packages installed on my system. If all of those were 100MB in size I'd have a problem.
With 50MB a piece that would be ~0.5TB. That is 50% of my system SSD.
(defn bottles [n]
(match n
0 "No more bottles"
1 "1 bottle"
_ (string n " bottles")))
(loop [i :down [99 0]]
(print
(bottles i) " of beer on the wall\n"
(bottles i) " of beer\nTake one down, pass it around\n"
(bottles (- i 1)) " of beer on the wall\n\n"))
https://rosettacode.org/wiki/99_bottles_of_beer#Janethttps://github.com/cmiles74/bencode/blob/master/src/bencode....
The code `(bottles i)` in the loop is calling the function `bottles` (defined at the top) with the argument `i`. The value of `(bottles 99)` is `(string 99 " bottles")` which evaluates to "99 bottles", as expected.
Gauche for example implements the latest (and IMO greatest) R7RS, its standard library is huge and "batteries-included" including a wide array of RFCs to the point of rivaling Python, and has a package manager in the form of Akku. Chicken has a similar story. Racket is arguably more useful "out of the box", but its community seems so heavily focused on using it for PL research that it's harder to justify using it for day-to-day programming. And there's Clojure as well, which I know comparatively less about, but is well-loved by its users.
Heck, even Common Lisp has a lot going for it, but the Standard and the conventional Lisp dev tools are kind of chaotic and idiosyncratic enough that it's understandable if people don't want to use it.
To be clear, Janet seems like a great little language. But as someone with limited time and energy who is interested in using it, I want to know why I should spend the time learning it, compared to Scheme
It's also easily embeddable in C programs the same way lua is, making it possible to use it as a config, extension, or scripting language in a larger program.
Aside from that having used it a fair bit I think it's got a very "practical" orientation. It provides immutable structures, but doesn't enforce immutability semantics the way clojure does. It has a good concurrency system but is cleanly single-threaded and performant by default. And imo the standard lib is a really good balance, neither forcing you to build EVERYTHING yourself (lua) or having the whole last 50 years of CS research in it (racket).
And here I immediately lost my interest. Anything that cannot do real concurrency is a toy in my book. There's no excuse for a language developed for practical computers in 21'st century to not be able to utilize concurrency which is practically built into every existing computer.
> It has a good concurrency system
Janet is much closer to Lua, in scope and applications, than it is to any Scheme or Common Lisp or Clojure implementations.
This language also completely converted me to PEGs for entire classes of problems, and I'm now often annoyed in other languages that don't have them. Libraries exist, but having it built in is so nice, and the s-exp syntax works much much better for them than almost anything else you could come up with.
A moderate issue I had was finding functions for what I wanted, since the docs were set up more tutorial style, then there was just a huge list of every function. Spent a lot of time skimming through that guessing what I could be looking for.
Another thing I ran into is the concurrency/fiber system still feels like a work in progress. There are several different ways to handle concurrency depending on how you want to combine the abstractions, and some parts of the (otherwise excellent) standard lib don't work well with it. It also combines nastily with a lot of C libraries, which is rough in a language that seems to expect you to use C bindings often. Understandable limitation and there's probably not a good clean solution.
Anyway this book looks great, I really hope it brings more people into janet. It's an excellent language for a lot of applications where people reach for the imo extremely overrated lua.
--
See also, from the same author: https://bauble.studio/ — interactive 3d sandbox in Janet
Previously discussed at: https://news.ycombinator.com/item?id=32738654
What I like about Janet is that anything seems possible with it, and that code from others is very approachable and understandable to me. In no other language do I ever find myself hacking on someone else's library to add a feature that I need. In Janet, it always seems easy.
Some stuff I created that I wouldn't quickly find myself doing in other languages:
- a wrapper around my web app that runs it like a CGI script (for ultra-cheap deploying on shared web hosts)
- a logging function (macro) that logs the input (both the unevaluated way it was called and what it evaluated to) + line number of the code that called it
- a framework for creating web apps (not public yet, but used in production on my website)
- (with Ian's help) a macro that I can use to create functions that require explicitly specified parameters
The fact the author points out, being able to distribute the program without requirements, is a big plus. Multiple times I have been doing some bash script that later I can't share with my non-techy friends until I translate it in some google sheets or something they can use. If Janet can let me do simple script stuff and let me share it just sending the binary as a file on some chat app, then I'm more than interested
I don't need sesquipedalian nomenclature in order to respect the content of a written work.
I love the writing style in both of them! It may not be for everyone, but I can appreciate works that use language to make topics less intimidating.
Thanks to both you and Ian for your writings.
Janet looks like a nice small, embeddable, fun language with a lively community!
The documentation and site felt like a close-knit community of insiders, which I wanted to become one of them :) hopefully this book shows the path!
A bunch of caveats to using it in practise, but it's still a little bit magical.
I don't think i'm the biggest fan of Janet, but I really appreciate his writing and may just read the whole book anyways.
Good one. PEGs feels like having a parsing superpower compared to regexes.
[1] Greenspoon's tenth rule
Is there an alternative shortcut for people without an esc key?
I’m on iOS and my keyboard doesn’t have one.
You can define the term for those unfamiliar, and you don’t have to dwell on it, but people who are turned off by LISPs will feel a little swindled if they get 3 book-pages in before finding out. And people who specifically like LISPs might pass this over without realizing what it is and miss out.
> And now you’re just wondering when I’m going to use the L-word. You want me to use it so you can go write a long screed about how Janet isn’t a real one. But I’m not going to give you the satisfaction. I’m not going to use that word until Chapter Fourteen.
> Note that Janet’s `nil` is not the empty list. If you don’t understand why I’m calling that out here, you can safely ignore this paragraph.
beautiful, succinct, and not a jab at lisp-y languages
It uses parens and prefix notation. Not every language that uses parens and prefix notation is a lisp, I guess, maybe, I don't care. But not wanting to have that argument is an excellent reason to never make this assertion about a language imo.
Considering that people can't even really decide on what constitutes LISP (Is Clojure a LISP?) I don't think there's any merit in this kind of resource to mention a term that's more likely to give people a false impression of what this really is or isn't.
Homoiconicity does not mean your syntax should be backwards. Look at Io language: it is basically a Lisp, but it has parens in the familiar places.
Same with Forth: it is a small and powerful language, but it's good for implementing low-level stuff. You will quickly run into desire to have normal(language(with, familiar, syntax)) for writing non-trivial programs.
Lisp is just less familiar, not necessarily wrong.