sci 2025-08-19

i want to modify the bindings available to an SCI context at runtime. is there a way to do that? basically i want sci/init, but reusing all the state from an existing context and only appending bindings.

oh and also i don't know the names of the bindings ahead of time, so i can't use ^:dynamic when i initially call sci/init. i'm not sure if sci/bindings works if the bindings aren't dynamic.

I think you want sci/merge-opts which creates a new context from an existing context

oh! that's absolutely it, thank you so much 🙂

hm, i'm not sure what i'm doing wrong but it doesn't seem to be working:

user=> (sci/eval-string* (sci/merge-opts cx {:bindings {'a :a}}) "a")
Execution error (ExceptionInfo) at sci.impl.utils/throw-error-with-location (utils.cljc:45).
Could not resolve symbol: a

oh wait i'm being silly i need to use copy-var probably

:bindings is just short-hand for:

user=> (sci/eval-string* (sci/merge-opts (sci/init {}) {:namespaces {'user {'a :a}}}) "a")
:a

I think it might be a bug that you're seeing with :bindings, just use the more explicit notation

👍 1

I'll log the bug and will take a look what's the issue

❤️ 1

bug is fixed on SCI master but at the same time I deprecated the :bindings option. just use :namespaces with 'user

👍 2