sci

2024-08-30T20:54:11.781069Z

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.

borkdude 2024-08-30T20:55:45.836719Z

the host's *ns* var isn't used in SCI, since it's completely separated from the host environment

borkdude 2024-08-30T20:55:50.552869Z

sci/ns is used for this

2024-08-30T20:56:31.673879Z

So how do I differentiate if I have a function that I want to use in both Clojure and Sci?

borkdude 2024-08-30T20:57:49.564099Z

maybe introduce some dynamic var that indicates whether you're running in SCI and then use sci/ns instead of *ns* or so?

2024-08-30T20:57:56.172189Z

huh okay

2024-08-30T21:00:08.579039Z

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

phronmophobic 2024-08-30T21:01:48.398989Z

Can you just have ns-qualify use sci/ns instead of *ns*?

2024-08-30T21:02:18.944529Z

lol it's in the library spec.alpha, i can't touch it from within sci

2024-08-30T21:02:42.509059Z

i know borkdude is gonna say "this is a bad idea, don't do it" but i'm having fun 😉

borkdude 2024-08-30T21:02:48.451849Z

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 work

borkdude 2024-08-30T21:03:03.598209Z

or rather the other way around binding [*ns* sci/ns]

borkdude 2024-08-30T21:03:20.851429Z

or create a clojure namespace object from the sci/ns thing

borkdude 2024-08-30T21:03:23.581979Z

you'll figure it out

2024-08-30T21:07:55.089739Z

hmm bummer

2024-08-30T22:33:47.193179Z

i think that to make this work, spec.alpha would need to be globally available in sci, like clojure.core is

2024-08-30T22:35:42.215219Z

that's probably a non starter, so an alternative would be a function in bb.spec.alpha that instruments macros