sci

arohner 2025-09-25T14:29:56.033759Z

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?

arohner 2025-09-25T14:31:44.171499Z

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))

arohner 2025-09-25T14:32:06.312499Z

but that seems to violate encapsulation

borkdude 2025-09-25T14:33:51.431969Z

the official API is `

(sci/binding [sci/ns ...]
 ...)

borkdude 2025-09-25T14:34:33.660899Z

also eval-string+ takes {:ns ..}

borkdude 2025-09-25T14:34:35.886609Z

as options

borkdude 2025-09-25T14:35:00.306659Z

also when you feed the result of eval-string+ back into itself it remains in the same ns

arohner 2025-09-25T14:58:30.822529Z

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?

borkdude 2025-09-25T14:59:06.676539Z

indeed

borkdude 2025-09-25T14:59:15.590789Z

or just call eval-string+ with the same ns it returned

borkdude 2025-09-25T15:00:58.230889Z

(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
)
   

arohner 2025-09-25T15:03:48.393969Z

thanks