Skip to content

Instantly share code, notes, and snippets.

@mfikes
Last active April 13, 2016 06:58
Show Gist options
  • Save mfikes/9868cb5d38ed18908fd2c472897608e0 to your computer and use it in GitHub Desktop.
Save mfikes/9868cb5d38ed18908fd2c472897608e0 to your computer and use it in GitHub Desktop.
Self-host turtles all the way down
$ planck
Planck 1.11
ClojureScript 1.8.44
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
    Exit: Control+D or :cljs/quit or exit or quit
 Results: Stored in vars *1, *2, *3, an exception in *e

cljs.user=> (require 'cljs.js)
nil
cljs.user=> (def st (cljs.js/empty-state))
#'cljs.user/st
cljs.user=> (cljs.js/eval-str st
       #_=>  "(ns turtle.core (:require cljs.js))"
       #_=>  nil {:eval cljs.js/js-eval :context :expr} identity)
{:ns turtle.core, :value nil}
cljs.user=> (cljs.js/eval-str st
       #_=>  (str "(cljs.js/eval-str (cljs.js/empty-state) "
       #_=>       "\"(+ 1 2)\"" ; deep
       #_=>       " nil {:eval cljs.js/js-eval :context :expr} (fn [x] x))")
       #_=>  nil {:eval cljs.js/js-eval :context :expr :ns 'turtle.core} identity)
{:ns turtle.core, :value {:ns cljs.user, :value 3}}
cljs.user=> 

The above uses the self-host ClojureScript API to invoke code that uses the self-host ClojureScript API to evaluate the sum of 1 and 2. Note that the 3 is :value in the :value of the map returned.

And, all of this is being done in a self-hosted ClojureScript REPL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment