I am wondering whether this is a known issue.  I made the mistake of
extending a protocol to two interfaces, and then calling it with an
object that implements both.

(defprotocol Foo
  (foo [x]))

(extend-protocol Foo
  clojure.lang.Sequential
  (foo [x] "sequential")
  clojure.lang.Associative
  (foo [x] "associative")
  )

(dotimes [_ 10]
  (println (foo [])))

You might expect this to print "sequential", or you might expect it to
print "associative", or you might expect an exception. Any of the
these behaviors would seem reasonable to me.

However, what it actually does is behind door number 4 :)  It randomly
chooses one of "sequential" or "associative" for each run of the JVM.
Within a JVM, once it has chosen, it continues to choose the same
value forever, but in a new JVM process it chooses randomly again.

This caused me a long debugging / hair-pulling-out session because
within my slime repl, my code consistently behaved one way (which, by
luck, happened to match with my mistaken expectations at the time),
but at the same time my unit tests seemed to be passing or failing
without rhyme or reason as I frantically tweaked my code over and
over.

I don't know, or particularly care, which behavior clojure chooses in
the case of ambiguity like this, but it sure would be nice if it was
predictable.

- Chris

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