Alan Malloy <a...@malloys.org> writes: > Stuff like this always worries me. It may happen to work now, but I > doubt if that's a guarantee. extend-protocol's contract is that you > give it a Symbol, which it resolves into a Class. It surely isn't > expecting a Class as an argument, because you can't enter that as a > source-code literal. If you give it a Class, it could conceivably do > something dreadful like try to call (resolve s) on it to figure out > what Class you mean, and that will fail when passed a Class.
I'm not entirely happy with it either, but I don't think the situation is quite that dire. The docstring for `extend-protocol' doesn't say anything about *how* it divides up the stanzas for extended types, and as pointed out elsewhere in this thread the implementation uses seq vs not-seq, not symbol? vs not-symbol?. The docstrings for `extend-type' and `extend' explicitly say that they take a "type/class" -- I'd interpret that to mean that they can be called with anything which resolves to a type/class via normal resolution methods, including a literal value generated via #=. > For that matter, trying out your example, it doesn't seem to work for > me. The first fix is to use java.lang.Class instead of just Class, > since reader evaluation happens in a no-frills environment. Apologies -- I just modified the OP's original example without thinking it all the way through or running the code. One does need to specify java.lang.Class/forName, which is what I've been doing in my own source. > But after that, it seems the extend-protocol just silently does > nothing: (Addressed by another poster.) -Marshall -- 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