i want to expose a repl that has doc and source available. i've bound clojure.repl/doc successfully, but when i run it, i get this exception:
flower=> (doc vals)
-------------------------
java.lang.ClassCastException: sci.lang.Namespace cannot be cast to clojure.lang.Symbol
[user/ <repl> 1:1]
Some details omitted; set the environment variable FLOWER_HOST_TRACE=1 for a full trackback
i think what's going on is that repl/print-doc is calling ns-name—but the host ns-name in clojure.core, not the guest ns-name in sci.impl.namespaces.
do you have suggestions for what to do here? if it helps, here is the implementation of doc:
user=> (source doc)
(defmacro doc
"Prints documentation for a var or special form given its name,
or for a spec if given a keyword"
{:added "1.0"}
[name]
(if-let [special-name ('{& fn catch try finally try} name)]
`(#'print-doc (#'special-doc '~special-name))
(cond
(special-doc-map name) `(#'print-doc (#'special-doc '~name))
(keyword? name) `(#'print-doc {:spec '~name :doc '~(spec/describe name)})
(find-ns name) `(#'print-doc (#'namespace-doc (find-ns '~name)))
(resolve name) `(#'print-doc (meta (var ~name))))))
i guess i can bind my own version of doc that replaces the meta on (var name) and then falls back to clojure.repl/doc?@jyn514 SCI already comes with a version of doc. in Clojure doc comes from clojure.repl/doc which exists in SCI:
https://github.com/babashka/sci/blob/bd3555c7962d8ac5172f85c733b385b15c1e0691/src/sci/impl/namespaces.cljc#L1948
oh this is beautiful, ty!
one more question actually -- is there way to rebind a builtin variable under a different name? normally i would use (let [sci-var] (copy-var ...) {:namespaces {'user {'doc sci-var} 'clojure.repl {'doc sci-var}}}), but i can't do that here because it's a built-in instead of something i manually call copy-var on
sure, you can do this:
(def my-sci-var (sci/resolve ctx 'clojure.repl/doc))
and then add that to another nsooo beautiful, ty!
i think i will have to make a temporary context first and then add my-sci-var into that context, but that seems doable
just (sci/init {}) will do
oh huh i didn't realize i could reuse variables across contexts in that way