On Jan 21, 11:48 pm, Mark Engelberg <mark.engelb...@gmail.com> wrote:
> Thanks for the thread links.  This is basically what I suspected -- if
> you want to use structs in multimethods, you have to roll your own
> constructor which adds some kind of "type" tag to either the hashmap
> or the metadata.
>
> It just seems like a common case, so I was hoping there was a more
> convenient way.  But I guess that's what macros are for...

In that vein, there's this thread:

http://groups.google.com/group/clojure/browse_thread/thread/257caab7867aa09c?hl=en#

which may do something like what you would like.  This is also an
issue I'm interested in, and I was planning on making some group/blog
posts about it in the near future.

FYI, I usually follow the following pattern:

My "interface" files contain a bunch of (defmulti ...)s, which mostly
dispatch on the :class of the first argument

Then, my "class" files contain
(derive ::MyClass :namespace/ParentClass)
(defstruct my-class :class :a :b :c)
(defn make-my-class [a b c]
        (struct my-class ::MyClass a b c))
followed by a bunch of (defmethod ...)s

But this does involve a bit of repetition, and I'm not sure if this is
the most idiomatic way to do things currently.

-Jason


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to