5 ms·
Clojure Scripting on Node.js
- foreigner 4y agoIf 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 https://www.npmjs.com/package/polyglot-tag Embed any scripting language in a Node.js template literal!
- CMCDragonkai 4y agoThis 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 4y agoHa ha you mean like this: https://www.npmjs.com/package/pipe-tag https://www.npmjs.com/package/pipe-tag
- reil_convnet 4y agoI 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.
- weikju 4y agoAlthough 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?
- solardev 4y agoWhat is this? What is Clojure and why do you need it in node?
- reil_convnet 4y agoClojure 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.
- mping 4y agoClojure 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.
- Barrin92 4y agoClojure is a lisp on the jvm. javascript compilers exist because people wanted to use clojure in web related projects.
- smcn 4y agoIt's not a javascript compiler as Clojure is a hosted language.
- Barrin92 4y agoclojurescript absolutely compiles to javascript, as per the official docs: https://clojure.org/about/clojurescript https://clojure.org/about/clojurescript
- smcn 4y agoBut that's not what nbb is.
- Borkdude 4y agoNbb isn't a compiler, but a Clojure interpreter. Clojure is a hosted language, but can be compiled or interpreted. The ClojureScript compiler compiles Clojure to JavaScript, but nbb only interprets Clojure.
- Borkdude 4y agoAuthor here. Ask me anything on nbb.
- arunix 4y agoWhat's the difference between this and Clojurescript?
- Borkdude 4y agoThe 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 https://blog.michielborkent.nl/aws-lambda-nbb.html
- ballpark 4y agoWhat kind of differences/limitations are there when interpreting Clojurescript (nbb) as opposed to compiling it (shadow-cljs, lein, self-hosted?, other things?)?
- zimablue 4y agoJust 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 4y agoThere 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.
- zimablue 4y agoBut the slow-starting, big-bundle default one still works right? For someone developing an electron app maybe it would be a useful option.
- deleted 4y ago[deleted]
- charesjrdan 4y agoI 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 4y agoI'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 4y agoNbb 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.
- piperswe 4y agoIs this similar to Lumo (https://github.com/anmonteiro/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 4y agoNbb still has faster startup time with any system-installed Node.js than lumo with its v8 snapshot.