Is there an official API to make in-ns work? I see there’s sci/eval-string+, but that does not appear to mutate the ctx, even when using (with-ctx ctx) should it?
I was able to hack it via:
(ctx-store/with-ctx ctx
(let [{:keys [ns] :as ret} (sci/eval-string+ ctx form)]
(swap! (:env ctx) assoc-in [:namespaces 'clojure.core '*ns*] ns)
ret))but that seems to violate encapsulation
the official API is `
(sci/binding [sci/ns ...]
...)also eval-string+ takes {:ns ..}
as options
also when you feed the result of eval-string+ back into itself it remains in the same ns
Thanks. So I guess the way that doesn’t violate encapsulation is to store that :ns somewhere else and pass it through to repeated calls to sci/binding?
indeed
or just call eval-string+ with the same ns it returned
(let [ctx (sci/init {})
state (atom {})
new-state (sci/eval-string+ ctx "(in-ns 'dude)" @state)
_ (reset! state new-state)]
(sci/eval-string+ ctx "*ns*" @state) ;; should be dude
)
thanks