The extend-type macro silently fails when used to extend an array type:

=> eval `(extend-type ~(class (into-array Object [42])) Xfer (look
[this#] (aget this# 0)) (mutate* [this# f# args#] (aset this# (apply
f# (aget this# 0) args#) 0))))
nil
=> (def foo (into-array Object [42]))
#'user/foo
=> (seq foo)
(42)
=> (mutate foo * 2)
#<CompilerException java.lang.IllegalArgumentException: No
implementation of method: :mutate* of protocol: #'user/Xfer found for
class: [Ljava.lang.Object; (NO_SOURCE_FILE:0)>

If you're curious what I was doing, I'm looking to slap together a
little demonstration of data races screwing up invariants and the
exact same (polymorphic) code not causing the same problem if refs are
used instead -- hence a protocol to mutate a thread-unsafe mutable
cell that can also be extended sensibly to refs (and, for that matter,
atoms).

-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

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