This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-03-04
Channels
- # announcements (4)
- # asami (38)
- # babashka (20)
- # beginners (188)
- # cider (1)
- # clara (11)
- # clj-kondo (103)
- # cljs-dev (15)
- # cljtogether (1)
- # clojure (138)
- # clojure-australia (5)
- # clojure-europe (33)
- # clojure-france (1)
- # clojure-losangeles (5)
- # clojure-nl (4)
- # clojure-norway (11)
- # clojure-serbia (3)
- # clojure-uk (11)
- # clojurescript (45)
- # community-development (3)
- # conjure (22)
- # core-async (18)
- # datomic (44)
- # defnpodcast (4)
- # deps-new (1)
- # depstar (49)
- # events (2)
- # fulcro (33)
- # girouette (2)
- # honeysql (37)
- # jackdaw (5)
- # jobs-discuss (16)
- # kaocha (3)
- # leiningen (4)
- # lsp (77)
- # malli (55)
- # membrane (4)
- # off-topic (61)
- # polylith (5)
- # quil (5)
- # reagent (33)
- # reitit (12)
- # remote-jobs (1)
- # reveal (4)
- # rewrite-clj (2)
- # sci (16)
- # shadow-cljs (22)
- # sql (1)
- # test-check (27)
- # tools-deps (44)
Is there a way to keep ns transitions around between evaluations?
(def sci-ctx (sci/init {}))
(defn eval-form [form]
(sci/with-bindings {sci/ns @sci/ns}
(sci/eval-form sci-ctx form)))
(eval-form '(do (in-ns 'foo)
(ns-name *ns*)))
;=> foo
(eval-form '(ns-name *ns*))
;=> user ;; not foo anymore!
@denik with-bindings
implies that the binding is restored when the body has ended. If you want to implement some kind of REPL then it's best to have the loop inside the with-bindings
@borkdude I don’t have traditional REPL but more something like REP where a client sends new forms and triggers the next evaluation cycle
nice, might have found a simpler solution:
(def sci-ctx (sci/init {}))
(def current-ns (atom @sci/ns))
(defn eval-form [form]
(sci/with-bindings {sci/ns @current-ns}
(let [ret (sci/eval-form sci-ctx form)]
(reset! current-ns @sci/ns)
ret)))
(eval-form '(do (in-ns 'foo)
(ns-name *ns*)))
;=> foo
(eval-form '(ns-name *ns*))
;=> foo
@denik It just occurred to me that I took the same approach here: https://github.com/babashka/xterm-sci/blob/29f2311fe5f9e9900092e44d00b357368cd5c77d/src/xterm_sci/core.cljs#L14 https://babashka.org/xterm-sci/