I'm trying to create a new ISeq type, just to try to get the hang of 
extending sequences.  It's not working, though.  As far as I can tell, I've 
implemented all necessary methods.  However, I still get an error when 
attempting to create an instance of the type.

When I enter the following in the REPL:
(ConsCell. 1 nil)

The repl complains about the nth function not being supported.  However, 
I'm not sure how to go about implementing it.  Any ideas?

(deftype ConsCell [car cdr]
  clojure.lang.ISeq
  (first
    [this] (-> this .car))
  (next
    [this] (-> this .cdr))
  (more
    [this] (-> this .cdr))
  (cons
    [this obj] (ConsCell. obj this))
  (seq
    [this] this)
  (equiv
    [this other] false)
  (count
    [this]
    (if (nil? (-> this .cdr))
      1
      (inc (.count cdr))))

   ;; Can't implement nth here, since it's not a member of the interface
  ;(nth
    ;[this n]
    ;(if (zero? n)
      ;(-> this .car)
      ;(.nth cdr (dec n))))
  )

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