defmulti is a defonce?

146 views
Skip to first unread message

hiskennyness

unread,
Apr 1, 2016, 12:10:45 PM4/1/16
to Clojure
I just killed two hours trying to figure out why my tweaks to the dispatch function of defmulti did not work. Finally got the feeling I had found a bug in Clojure, but then I found a comment somewhere saying it is a feature, effectively a defonce (and, yes, looking at the source I see it does not do anything if it is already defined).

Shucks, could we get a warning or some doc on this?

But I am a Lisper, I am used to this. The classic is the initform to a class-allocated variable in defclass. :)

-kt

Gary Trakhman

unread,
Apr 1, 2016, 12:16:24 PM4/1/16
to Clojure
I usually work around this by putting the dispatch in a separate def and referencing the var within defmulti.

(defmulti my-multi #'my-dispatch)

It's barely slower for the extra var dereference and very convenient for development.

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kenneth Tilton

unread,
Apr 1, 2016, 12:33:20 PM4/1/16
to clo...@googlegroups.com
Pure genius. :) And once I have the method working as I want I can swap in the code.

Thx! -kt

You received this message because you are subscribed to a topic in the Google Groups "Clojure" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojure/FDH6Tx1Gl8w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to clojure+u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Kenneth Tilton
Founder/Developer
TiltonTec
54 Isle of Venice Dr
Fort Lauderdale, FL 33301

@tiltonsalgebra


"In a class by itself." -Macworld


Reply all
Reply to author
Forward
0 new messages