Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Polyglot Graal from ClojureScript

You need to first install GraalVM, and then set your PATH so that you get the GraalVM binaries (incluing the GraalVM version of node).

You can then install R and Ruby via

gu -c install org.graalvm.r
gu -c install org.graalvm.ruby

Then, use this small tweak to ClojureScript's Node REPL so you can pass arguments to node. An easy way to do this is via this deps.edn:

{:deps {org.clojure/clojurescript
        {:git/url ""
         :sha "3e13026898acaa0f89eaa6eaa3be9411e084cf2d"}}}

Then launch the node REPL as usual, but we'll pass in two extra GraalVM arguments, --polyglot and --jvm:

clj -m cljs.main -ro '{:node-args ["--polyglot" "--jvm"]}' -re node -r

Then have fun playing with multiple languages from ClojureScript!

cljs.user=> (reduce + [1 2 3 5 7 11])
cljs.user=> (.eval js/Polyglot "R"
cljs.user=> (.eval js/Polyglot "ruby"
  "[1,2,3,5,7,11].inject(0){|sum,x| sum + x }")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment