Is this intended functionality?
(ns user)
(let [ns-qualify (fn [s] (symbol (str *ns*) (str s)))
ctx (sci/init {:namespaces {'base {'ns-qualify ns-qualify}}})]
(sci/eval-string+
ctx
"(ns example
(:require [base :as b]))
(b/ns-qualify 'foo)"))
;=> user/foo
I expect it to be example/foo because it's called in the context of the namespace example, even tho it's an external function.the host's *ns* var isn't used in SCI, since it's completely separated from the host environment
sci/ns is used for this
So how do I differentiate if I have a function that I want to use in both Clojure and Sci?
maybe introduce some dynamic var that indicates whether you're running in SCI and then use sci/ns instead of *ns* or so?
huh okay
i'm asking of course because i've mostly hacked the macro spec checking into sci (cuz why not?) and have it working except that the spec.alpha function ns-qualify uses *ns*, and this difference makes all of the checks not work
Can you just have ns-qualify use sci/ns instead of *ns*?
lol it's in the library spec.alpha, i can't touch it from within sci
i know borkdude is gonna say "this is a bad idea, don't do it" but i'm having fun 😉
you can "fix" this by wrapping ns-qualify like this:
(fn [s] (binding [sci/ns *ns*] (ns-qualify ...))
not sure if this is going to work since SCI namespace objects are a bit different, but if you're lucky it'll workor rather the other way around binding [*ns* sci/ns]
or create a clojure namespace object from the sci/ns thing
you'll figure it out
hmm bummer
i think that to make this work, spec.alpha would need to be globally available in sci, like clojure.core is
that's probably a non starter, so an alternative would be a function in bb.spec.alpha that instruments macros