Hi, I’m using sci for a simple template system and would like to inject some “state” into the sci context every time a user evals a string using sci. I would like some pre-made functions to be able to access this state. Right now I’m doing the following (minimal example):
(def some-global-changing-state (atom {:hello :there}))
(let [env @some-global-changing-state
eval-fn (fn [expr env]
(sci/eval-string expr {:namespaces {'user {'env env}}}))]
(eval-fn "(defn hello! [] (:hello env)) (hello!)" env))
Is there a way to define the hello! function outside of the string and still have it access the dynamic changing state? I’ve looked at the Vars section of the Readme but was unable to adopt them to my usecase.Yes, just add the hello function to the user namespace under the hello symbol just like you did for env
Thanks, that worked! Very simple actually 😅