Readit News logoReadit News
weikju · 4 years ago
Although I have not used nbb, babashka itself has been super useful for avoiding the slower JVM startup time while still using Clojure to automate some tasks at the command line.

Yet, despite many projects using bb + a bb.edn tasks file as a replacement for Make, I find myself still reaching for Make, out of familiarity at least, perhaps to avoid the extra dependency on bb itself?

Borkdude · 4 years ago
Author here. Ask me anything on nbb.
arunix · 4 years ago
What's the difference between this and Clojurescript?
Borkdude · 4 years ago
The main difference is that nbb lets you execute a .cljs file straight away, without a compilation step. As such, it doesn't need any JVM tooling. You can create an AWS Lambda with only a couple of lines of code:

https://blog.michielborkent.nl/aws-lambda-nbb.html

ballpark · 4 years ago
What kind of differences/limitations are there when interpreting Clojurescript (nbb) as opposed to compiling it (shadow-cljs, lein, self-hosted?, other things?)?
charesjrdan · 4 years ago
I love babashka but always find nbb scripts hard because everything returns a promise which makes the normal REPL workflow tricky.. maybe I’m doing it wrong though
agentwiggles · 4 years ago
I'm not sure if this applies to nbb, but there's a command line flag for the node repl (`--experimental-repl-await`) which allows you to use await in the repl, allowing you to kind of sidestep the normal annoyance of handling promises.
Borkdude · 4 years ago
Nbb has nbb.core/await for top level await which is handy for REPL usage. Furthermore it has promesa which is a library for dealing with promises.
zimablue · 4 years ago
Just as an FYI for the interested, there is a self-hosted version of clojurescript now, it enables macros in the same runtime with some caveats but the main downside (AFAIK) is increased bundle size, which is less relevant for node.js.
Borkdude · 4 years ago
There was a self-hosted CLJS project for Node.js which is now abandoned. It was called lumo. It came with a custom image of Node.js with lumo built-in for better startup times since the JS bundle of self-hosted CLJS is quite large resulting in not so great startup out of the box. Nbb is just a library that you can use with any Node.js version. That said, it might be worth revisiting the self-hosted CLJS approach at some point.

Deleted Comment

zimablue · 4 years ago
But the slow-starting, big-bundle default one still works right? For someone developing an electron app maybe it would be a useful option.
reil_convnet · 4 years ago
I am not the developer of this library. I just have been using it for a small project and thought others might find it interesting as well.
solardev · 4 years ago
What is this? What is Clojure and why do you need it in node?
St_Alfonzo · 4 years ago
Clojure/Clojurescript is a functional lisp dialect and therefore brings you more and other ways to write programs, since it defers much from javascript/typescript. But I think another question would be "why do you need nbb for clojurescript?". The minimal answer is: clojure has slow startup time, and clojurescript need some tooling to produce runnable code. With nbb (or bb for clojure) you can run Clojurescript as a scripting language in the terminal, like python or shell, and still use some libraries both from the nodejs or clojure(-script) ecosystem.
Borkdude · 4 years ago
Author here. Nbb is a scripting environment for Clojure running on Node.js. Clojure is a Lisp that emphasises functional and data oriented programming. Scripts are executed using an interpreter, so there is no build/compile step necessary, which is convenient for small applications.

If you're more curious, check out the README which has a list of videos and articles on this.

reil_convnet · 4 years ago
Clojure is a lisp dialect (One of the most loved languages according to surveys). You can use nbb to write clojure instead of js in Node.
elias94 · 4 years ago
https://tryclojure.org/ in case you want to try it!
Barrin92 · 4 years ago
Clojure is a lisp on the jvm. javascript compilers exist because people wanted to use clojure in web related projects.
smcn · 4 years ago
It's not a javascript compiler as Clojure is a hosted language.
mping · 4 years ago
Clojure is a lisp like language hosted on top of the JVM. By running on top of node you get a faster startup which is desirable for short lived apps.
piperswe · 4 years ago
Is this similar to Lumo (https://github.com/anmonteiro/lumo)? I would assume Lumo has a faster start time since it boots from a V8 snapshot, but otherwise I'd assume the two projects are similar (except that, of course, lumo is EOL)
Borkdude · 4 years ago
Nbb still has faster startup time with any system-installed Node.js than lumo with its v8 snapshot.
foreigner · 4 years ago
If anyone is interested in mixing other languages in node, check out this silly little library I threw together: https://www.npmjs.com/package/polyglot-tag

Embed any scripting language in a Node.js template literal!

CMCDragonkai · 4 years ago
This is actually really nifty. However can you change it to be asynchronous instead? Right now the polyglot runs synchronously.

What about the stdout/stderr... It ultimately has to give you back a child process. Could there be a spawn version that gives you the child process too?

foreigner · 4 years ago
Ha ha you mean like this: https://www.npmjs.com/package/pipe-tag