Fork me on GitHub
#sci
<
2023-11-15
>
Ingy döt Net14:11:01

What do I need to do to add slurp to eval-string*'s context?

borkdude15:11:25

(sci/init {:namespaces {'clojure.core {'slurp (sci/copy-var slurp (sci/create-ns 'clojure.core))}}})

Ingy döt Net18:11:55

That worked. I forgot to say thanks...

Ingy döt Net19:11:46

I looked at the bb main code that sets up the context for sci eval but it is rather massive.

Ingy döt Net19:11:09

What gets refered into the user ns automatically ?

Ingy döt Net19:11:31

It seems like I can copy-var things into the clojure.core ns and they are available in user at runtime

borkdude19:11:21

user=> (sci/eval-string "(ns-publics 'user)")
{}

borkdude19:11:29

yes, adding to clojure.core makes it available in every ns

Ingy döt Net19:11:48

$ 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")

Ingy döt Net19:11:32

is a glimpse of which vars get somehow refered into the user ns. does bb copy-var all the vars into clojure.core or ...?

Ingy döt Net19:11:57

sorry I can't phrase this better

borkdude19:11:03

what you list here is a list of namespaces, not vars

Ingy döt Net19:11:13

sure I get that

Ingy döt Net20:11:26

I'm trying to figure out how the vars from those namespaces made it into user's ns-refers

Ingy döt Net20:11:17

I could accomplish that by doing a copy-var from every interesting ns into clojure.core but that feels odd

borkdude20:11:26

why does it matter? I'm not sure what the problem is

borkdude20:11:40

You can check in babashka.main which vars are part of the user namespace

Ingy döt Net20:11:02

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

Ingy döt Net20:11:43

I looked at babashka.main before even asking here, but like I said it's quite massive

borkdude20:11:18

I'm not sure why you are looking at ns-refers

borkdude20:11:31

tbh I never use this function so I had to look up the docstring what it even does ;)

borkdude20:11:43

$ bb -e "(map ns-name (distinct (map :ns (map meta (vals (ns-refers 'user))))))"
(clojure.core clojure.repl clojure.pprint)

1
borkdude20:11:04

clojure.repl is referred because of doc

borkdude20:11:10

such that bb -e '(doc ..) works

borkdude20:11:14

and in a console REPL

borkdude20:11:28

but normally this isn't the case in non-REPL situations, only clojure.core

Ingy döt Net20:11:00

iirc ns-map == ns-publics + ns-refers

Ingy döt Net20:11:21

anyway your bb cmd above is exactly what I was curious about. thanks.