The issue of "what to call" and "when to call it" has been debated
in the common lisp world a long time ago. There are solutions
to these questions in the discussions around the CLOS facility
(Steele, "Common Lisp: The Language", chapter 28)

Prior to that there was a discussion of the same issues on the
Symbolics machine along with whoppers and wrappers.

Unfortunately all of my records of such discussions were on
pre-web email so I do not have copies. There may be some
people on this list who do.

A lot of thought went into the decisions. It might be worthwhile
reading about the choices they made.

Similarly I saw a discussion of the error handling facility.
Common lisp has a condition system that might be useful to follow.

The advantage of using already existing ideas is that it will
make it easier and less surprising to the existing lisp community.
It will also give a firm basis for discussing ideas.

Tim Daly


On 10/25/2010 5:54 AM, Mark Nutter wrote:
I tried to have a go at this, but then I realized it's a bit difficult
to specify. For example, if you have

(defmethod bar [42 _] ..) ; and
(defmethod bar [_ 16] ..)

which one should be called when you give it (bar 42 16)?

Mark

On Sat, Oct 23, 2010 at 5:16 PM, Paul Richards<paul.richa...@gmail.com>  wrote:
Hi,
I have a multimethod which is dispatched on two arguments:

(defmulti bar (fn [x y] [x y]))
(defmethod bar [1 2] ..)
(defmethod bar [3 4] ..)

Is there a way I can define methods on this which use "wildcards"?

E.g.:

; To match any call with 42 as the 1st argument
(defmethod bar [42 _] ..)

; To match any call with 16 as the 2nd argument
(defmethod bar [_ 16] ..)

The above syntax doesn't seem to work, neither does using ':default'
in place of the '_'.

If this is not possible, is there a common pattern I should implement instead?

--
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
Note that posts from new members are moderated - please be patient with your 
first post.
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