rest vs drop

unsorted — cgrand, 23 February 2009 @ 18 h 20 min

Now that fully lazy sequences are in the trunk, (rest a-seq) and (drop 1 a-seq) aren’t equivalent anymore:

user=> (def s (map #(do (println %) %) (range 10)))
user=> (def d (drop 1 s))
user=> (def r (rest s))

As one can see rest needs to realize the first element of s while drop doesn’t. The corollary is that (drop n s) holds on the whole seq (including the nth first elements) while rest computes the first element and then discards it.


No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

(c) 2018 Clojure and me | powered by WordPress with Barecity