Created
February 19, 2011 23:55
-
-
Save marcinkoziej/835525 to your computer and use it in GitHub Desktop.
This defines multimethods, and the other implements them
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns a | |
(:use m)) | |
(defmethod foo :a [o] (str "a-method for " o)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns m | |
(:require a)) | |
(defstruct ob :baz :bar) | |
(defmulti foo :baz) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The problem:
I would like to put defmethods in separate files, depending on dispatch value (:baz).
I'd like to be able to add new implementations (files) for new :baz values, so my methods are extensible.
In this example I'd like to be albe to
(use 'm)
(foo (struct ob :a 123))
but this will not work, since there is a circular dependency.
On the other hand when I'll remove (:require a) from m.clj, I will have to do
(use 'm 'a)
(foo (struct ob :a 123))
and if I add new implementations in b.clj, I will have to change all my files to: (use 'm 'a 'b)
How should one handle this use case?