sci

jyn 2025-08-19T20:06:01.665409Z

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.

jyn 2025-08-19T20:07:24.220779Z

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.

borkdude 2025-08-19T20:15:40.117589Z

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

jyn 2025-08-19T20:15:58.188779Z

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

jyn 2025-08-19T20:19:35.989549Z

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

jyn 2025-08-19T20:20:36.779139Z

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

borkdude 2025-08-19T20:23:38.883469Z

:bindings is just short-hand for:

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

borkdude 2025-08-19T20:24:18.749989Z

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

👍 1
borkdude 2025-08-19T20:24:53.002359Z

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

❤️ 1
borkdude 2025-08-19T21:17:02.781789Z

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

👍 2