Advertisement
Guest User

Untitled

a guest
Sep 16th, 2011
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (defprotocol BlaBla
  2.   (bla [this]))
  3.  
  4. ;; This extend form does not compile
  5.  
  6. (extend-protocol BlaBla
  7.   (class 17)  (bla [this] (inc this))
  8.   (class "s") (bla [this] (reverse this))
  9.   (class \s)  (bla [this] "foo"))
  10.  
  11. ;; This is the exception:
  12. nth not supported on this type: Character
  13.   [Thrown class java.lang.UnsupportedOperationException]
  14. Backtrace:
  15.   0: clojure.lang.RT.nthFrom(RT.java:835)
  16.   1: clojure.lang.RT.nth(RT.java:785)
  17.   2: clojure.core$emit_hinted_impl$hint__5517$fn__5519.invoke(core_deftype.clj:710)
  18.   3: clojure.core$map$fn__3811.invoke(core.clj:2432)
  19.   4: clojure.lang.LazySeq.sval(LazySeq.java:42)
  20.   5: clojure.lang.LazySeq.seq(LazySeq.java:60)
  21.   6: clojure.lang.RT.seq(RT.java:466)
  22.   7: clojure.lang.RT.countFrom(RT.java:519)
  23.   8: clojure.lang.RT.count(RT.java:512)
  24.   9: clojure.lang.Cons.count(Cons.java:49)
  25.  10: clojure.lang.Compiler.analyze(Compiler.java:6207)
  26.  
  27. ;; After commenting the two last 2 method defs and reevaling...
  28. (extend-protocol BlaBla
  29.   (class 17)  (bla [this] (inc this))
  30.   ;;(class "s") (bla [this] (reverse this))
  31.   ;;(class \s)  (bla [this] "foo")
  32.   )
  33.  
  34. ;; ... I can now do:
  35. => (bla 17)
  36. 18
  37.  
  38. ;; So it seems to work fine if there's only one class-exp/method-def
  39. ;; pair... Why?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement