On Feb 5, 7:44 pm, David Nolen <dnolen.li...@gmail.com> wrote:
> >  The fly in the ointment is: what happens if both
> > protocols specialize frob? Then Clojure will complain that it can't
> > tell which method to call. In order to resolve that problem, we must
> > use prefer-method to declare that one protocol or the other is
> > preferred.
>
> > But what if I want to make another thing:
>
> > (make-thing {:models [::thing]
> >                   :protocols [::idea ::thing]
> >                   :inits {:name "test-thing2" :number 2}})
>
> make-thing could tag your thing with a runtime tag and define a prefer on
> this runtime tag.

It's not quite that simple. Prefer-method accepts three arguments: a
multifunction and two dispatch values. It establishes that the method
associated with the first dispatch value is to be preferred over the
one associated with the second.

When make-thing returns, no method is associated with the tag computed
for the new thing; it's a brand new tag for which no defmethod exists.

If make-thing calls prefer-method, what tags should it use as
arguments? If it calls

  (prefer-method frob ::idea ::thing)

that simply replaces the previous global definition:

  (prefer-method frob ::thing ::idea)

...clobbering the definition for any previously-existing objects.

It could use the newly-computed tag for the thing:

  (prefer-method frob newly-computed-tag ::thing)

...but that accomplishes nothing. The result is the same as if prefer-
method were never called, since no method is defined for the dispatch
value of newly-computed-tag.

Instead, make-thing would have to find the method that is currently
defined for the tag value of ::idea and install it as the method for
the tag value newly-computed-tag. Then, the subsytem would have to
ensure that if the method on ::idea were ever changed, it also changed
the method on newly-computed-tag, but only if no user code had
subsequently defined a method for newly-computed-tag.

Ick.




--~--~---------~--~----~------------~-------~--~----~
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