@sogaiu just for the record, the joker
REPL breaks if I use in-ns
. The reason is that on other REPLs, in-ns
would allow some commands like ns
to exist.
If you're on joker
REPL, using in-ns
in a namespace that doesn't exist, it will not allow any other command - even the declaration of a new namespace...
So, I think for convenience I'll stick with ns
to change into a namespace.
ah, i didn't know that, thanks for mentioning it. if (ns my-ns) is used, doesn't that lead to bringing in clojure.core? if the "official" ns for a namespace (what's typically at the top of a file) is later executed that tries to exclude things from clojure.core, does unmapping of those things happen automatically? i guess i should go check this 🙂
i think what i described does happen -- i just did a little test using :refer-clojure :exclude [+] in an ns and i defined + in the file to be something else (e.g. *). if i use (ns my-ns) before loading or requiring, + is from clojure.core. if i load or require the file, + behaves based on the contained definition.
that sounds expected, right?
@mauricio.szabo fwiw, as expeced, a subsequent load-file does override the initial clojure.core/+ def with the custom one. i'm really not sure what a good approach would be -- i don't know if loading a ns before "switching" into it is a good option.
Yes, I also don't know. I'm somehow used to the refresh workflow (both with require or with clojure.tools.namespace), and with ClojureScript by just saving files, so with alternative REPLs I have no idea what's to be expected.
Okay, things are really a mess on these REPL worlds 😞
Plank creates a new namespace everytime you use (ns <something>)
, so I need to use in-ns
😞
Lumo does the same
perhaps the various cljs implementations are mostly similar? have you had a look at what shadow-cljs does?
Could you do it conditionally, based on whether the ns already exists? Run find-ns
and if it finds one, use in-ns
, else use ns
?
That may be a good idea. I'll test it right now
The sad part is that this code: (if (find-ns 'foo.bar) (in-ns 'foo.bar) (ns foo.bar))
Works on almost every REPL, the big except being ClojureScript...
groan