Want this course?
Gotcha: length checks
How do you check the length of an infinite list? Well, you can’t directly. But very often the question is not “What’s the length?” but instead an indirect question like “Is the length greater than 10?”. When asked like that, you can convert the infinite list into an appropriate finite list and ask for the length of that.
(defn big-list? [ls] (> (count (take 1001 ls)) 1000)) (defn empty-list? [ls] (zero? (count (take 1 ls)))) (defn has-10? [ls] (= 10 (count (take 11 ls))))