On Wed, Aug 19, 2009 at 01:08, tmountain<tinymount...@gmail.com> wrote: [snip] > > Also, this is > a side question, but does anybody know if there's a faster (or better) > way to compare two lazy sequences than the following? > > (defn seq-identical? [seq1 seq2] > (zero? (compare (vec seq1) (vec seq2)))) >
A note on the naming: I wouldn't use "-identical?" as part of this name, as that's not what you're asking: (identical? x y) -- Tests if 2 arguments are the **same object** On Wed, Aug 19, 2009 at 01:17, CuppoJava<patrickli_2...@hotmail.com> wrote: > > And = should work I think: > (= [1 2 3] [1 2 3]) returns true. > Not only that, clojure's even smart enough to "do the right thing" when the two arguments are lazy: In the case of unequal sequences, it only evaluates as much of the sequence as is necessary to prove that they are unequal. [ (defn = "Equality. Returns true if x equals y, false if not. Same as Java x.equals(y) except it also works for nil, and compares numbers and collections in a type-independent manner. Clojure's immutable data structures define equals() (and thus =) as a value, not an identity, comparison." {:tag Boolean :inline (fn [x y] `(. clojure.lang.Util equiv ~x ~y)) :inline-arities #{2}} ([x] true) ([x y] (clojure.lang.Util/equiv x y)) ([x y & more] (if (= x y) (if (next more) (recur y (first more) (next more)) (= y (first more))) false))) // Ben --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---