Clojure library for graalvm's polyglot functionality. Requires JDK11+ or a graalvm runtime.
clj-polyglot.core
- eval fn + seralization/deserialization fnsclj-polyglot.js
- JavaScript contextThis library was used to build tonal-clj
TODO: extend this library to support other graalvm languages
Consider a JavaScript API like tonal:
import { Note, Interval, Scale } from "@tonaljs/tonal";
Note.freq("a4").freq; // => 440
We can interface with this library like so:
(require '[clj-polyglot.core :as poly])
(require '[clj-polyglot.js :as poly.js])
(def tonal-src
(slurp "https://cdn.jsdelivr.net/npm/@tonaljs/tonal/browser/tonal.min.js"))
(def ctx
(poly.js/js-ctx tonal-src))
(def tonal
(poly.js/from ctx "Tonal"))
(def api
(poly.js/import tonal :Note [:midi :freq]))
(defn freq [note]
(poly/eval api :freq note))
(freq "A4") ;; => 440
Consider a JavaScript API like asciichart
var asciichart = require ('asciichart');
asciichart.plot([1,2,3]);
(def asciichart-src
(slurp "https://cdn.jsdelivr.net/npm/asciichart@1.5.21/asciichart.js"))
(def ctx
(poly.js/js-ctx asciichart-src))
(def asciichart
(poly.js/from ctx "asciichart"))
(def api
(poly.js/import asciichart [:plot]))
(def plot [values]
(poly/eval api :plot values))
(plot [1 2 3])
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close