Skip to content

Instantly share code, notes, and snippets.

@tolitius
Last active December 4, 2015 00:40
Show Gist options
  • Save tolitius/c17b2d4a98eabb591926 to your computer and use it in GitHub Desktop.
Save tolitius/c17b2d4a98eabb591926 to your computer and use it in GitHub Desktop.
cljs: ns-interns vs. ns-interns*
;; Bootstrapped ClojureScript
;; --------------------------
cljs.user=> (require '[cljs.js :as cljs])
cljs.user=> (def foo 42)
#'cljs.user/foo
cljs.user=> (cljs/eval-str (cljs/empty-state) "(ns-interns (quote cljs.user))" "interning" {:eval cljs/js-eval} identity)
{:ns cljs.user, :value {}}
cljs.user=> (cljs/eval-str (cljs/empty-state) "(ns-interns* (quote cljs.user))" "interning" {:eval cljs/js-eval} identity)
{:ns cljs.user, :value {foo #'cljs.user/foo}}
;; Replumb ClojureScript REPL ( https://github.com/ScalaConsultants/replumb )
;; --------------------------------------------------------------------------
cljs.user=> (require '[replumb.core :as replumb])
cljs.user=> (def foo 42)
#'cljs.user/foo
cljs.user=> (replumb/read-eval-call {:eval-fn js/eval} identity "(ns-interns* 'cljs.user)")
{:success? true, :form (ns-interns* (quote cljs.user)), :value "{foo #'cljs.user/foo}"}
cljs.user=> (replumb/read-eval-call {:eval-fn js/eval} identity "(ns-interns 'cljs.user)")
{:success? true, :form (ns-interns (quote cljs.user)), :value "{}"}
;; Regular ClojureScript REPL
;; --------------------------
cljs.user=> (defstate foo :start 42)
nil
;; corect meta
cljs.user=> (-> ((ns-interns 'cljs.user) 'foo) meta)
{:mount-state 42, :ns cljs.user, :name foo, :file "<cljs repl>", :end-column 14, :start (clojure.core/fn [] 42), :source "foo", :column 1, :line 1, :status #{:stopped}, :end-line 1, :order 1, :arglists (), :doc nil, :test nil}
cljs.user=>
;; no meta
cljs.user=> (-> ((ns-interns* 'cljs.user) 'foo) meta)
{:ns #object[cljs.core.Namespace]}
cljs.user=>
@mfikes
Copy link

mfikes commented Dec 4, 2015

Need to keep the state atom around and use it to build up analysis metadata. In script/noderepljs:

ClojureScript Node.js REPL server listening on 49696
To quit, type: :cljs/quit
cljs.user=> (require '[cljs.js :as cljs])
nil
cljs.user=> (def st (cljs/empty-state))
#'cljs.user/st
cljs.user=> (cljs/eval-str st "(def foo 42)" "" {:eval cljs/js-eval} identity)
{:ns cljs.user, :value 42}
cljs.user=> (cljs/eval-str st "(ns-interns (quote cljs.user))" "interning" {:eval cljs/js-eval} identity)
{:ns cljs.user, :value {foo #'cljs.user/foo}}
cljs.user=> 

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