Fork me on GitHub
#clojurescript
<
2019-06-29
>
oskarkv02:06:23

Hm, I'm having trouble with multimethods in ClojureScript.

(def h (derive (make-hierarchy) :a :b))

(defmulti testmulti identity
  :hierarchy #'h)

(defmethod testmulti :b [x]
  (println "defmethod" x))
When I eval the defmethod after defmulti, I get "#object[Error Error: No protocol method IDeref.-deref defined for type cljs.core/PersistentArrayMap: {:parents {:a #{:b}}, :ancestors {:a #{:b}}, :descendants {:b #{:a}}}]"

oskarkv02:06:12

Am I doing something wrong?

oskarkv02:06:18

Oh, maybe it's because I wrote it wrong at first, and it's not cleared out by just evaling again.

oskarkv02:06:52

Is there a way to reload a clojurescript namespace, throwing away all the old definitions?

mfikes02:06:42

ClojureScript supports the :reload and :reload-all flags in require

oskarkv02:06:15

That doesn't seem to do anything about old defmultis

oskarkv03:06:10

Oh, I can do ns-unmap

Sam Ferrell03:06:39

Is it possible to require/import/make available an .edn file to a CLJS file at compile time?

mfikes03:06:22

Yes. You can write a side-effecting macro

Sam Ferrell03:06:48

hmm, any other pointers? i'm a beginner

mfikes03:06:08

(defmacro from-edn [file] (edn/read-string (slurp file)))

Sam Ferrell03:06:47

ah okay, i'll swing at that. thanks!

mfikes03:06:59

Assuming you have a file containing some edn, then this would make that value available in your code at compile time.

Sam Ferrell03:06:20

this is possible because macro expansion happens at compile time, and performs the side effect locally?

👍 4
mfikes03:06:28

It is better to avoid these sort of macros if you can, but, it is certainly possible to write them.

mfikes03:06:27

goog-define is often a better alternative

Jeremy09:06:12

Hi fine people. Does anyone know how to add nrepl middleware when using deps.edn? I'm trying to get a shadow-cljs clojurescript repl working in Cursive's local nrepl https://github.com/thheller/shadow-cljs/issues/517

pinkfrog10:06:05

hiccup or selmer ? which is the way to go?

Pick Feky14:06:01

i prefer hiccup.