(ns three.lisp.tower)
(def js (.getEngineByName (javax.script.ScriptEngineManager.) "nashorn"))
(defn jsc [code]
(let [prelude "{add: function(a,b){return a+b;}, inc: function(n){return n+1;}}",
link "(function(prelude){return (function(prelude){ %s })(prelude);})(%s)"
emit (fn [l p s] (format l s p))
js (fn [s] (.eval js s))]
(js (emit link prelude code))))
user=> (jsc "return Array(1,2,3).map(prelude.inc).reduce(prelude.add)")
9.0
#EnoughProcrastination
Aucun commentaire:
Enregistrer un commentaire