What do I need to do to add slurp to eval-string*'s context?
(sci/init {:namespaces {'clojure.core {'slurp (sci/copy-var slurp (sci/create-ns 'clojure.core))}}})
That worked. I forgot to say thanks...
I looked at the bb main code that sets up the context for sci eval but it is rather massive.
What gets refered into the user ns automatically ?
It seems like I can copy-var things into the clojure.core ns and they are available in user at runtime
user=> (sci/eval-string "(ns-publics 'user)")
{}yes, adding to clojure.core makes it available in every ns
$ bb -e '(->> *ns* ns-refers vals (map var-get) (map type) (filter type) (map str) (map #(str/replace % #".* (.*?)(\$.*|$)" "$1")) sort distinct pprint)'
("babashka.impl.clojure.core"
"babashka.impl.pprint"
"babashka.main"
"clojure.core"
"clojure.lang.AFunction"
"clojure.lang.LineNumberingPushbackReader"
"clojure.lang.MultiFn"
"clojure.lang.PersistentArrayMap"
"clojure.lang.PersistentList"
"clojure.lang.Ref"
"clojure.lang.Var"
"java.io.OutputStreamWriter"
"java.io.PrintWriter"
"java.lang.Boolean"
"java.lang.String"
"sci.addons.future"
"sci.impl.core_protocols"
"sci.impl.deftype"
"sci.impl.doseq_macro"
"sci.impl.fns"
"sci.impl.for_macro"
"sci.impl.hierarchies"
""
"sci.impl.multimethods"
"sci.impl.namespaces"
"sci.impl.protocols"
"sci.impl.proxy"
"sci.impl.read"
"sci.impl.records"
"sci.impl.reify"
"sci.impl.types"
"sci.impl.utils"
"sci.impl.vars"
"sci.impl.vars.SciUnbound"
"sci.lang.Namespace")
is a glimpse of which vars get somehow refered into the user ns.
does bb copy-var all the vars into clojure.core or ...?
sorry I can't phrase this better
what you list here is a list of namespaces, not vars
sure I get that
I'm trying to figure out how the vars from those namespaces made it into user's ns-refers
I could accomplish that by doing a copy-var from every interesting ns into clojure.core but that feels odd
why does it matter? I'm not sure what the problem is
You can check in babashka.main which vars are part of the user namespace
I just want to know if you (bb) copy-var each var into clojure.core
Or are there other namespaces that also get auto referred
I looked at babashka.main before even asking here, but like I said it's quite massive
I'm not sure why you are looking at ns-refers
tbh I never use this function so I had to look up the docstring what it even does ;)
$ bb -e "(map ns-name (distinct (map :ns (map meta (vals (ns-refers 'user))))))"
(clojure.core clojure.repl clojure.pprint)clojure.repl is referred because of doc
such that bb -e '(doc ..) works
and in a console REPL
got it
but normally this isn't the case in non-REPL situations, only clojure.core
iirc ns-map == ns-publics + ns-refers
anyway your bb cmd above is exactly what I was curious about. thanks.
ah cool