doall
in apply
to force evaluation of the arguments seq but it's not the case when the applied function is variadic.
When the pupil is ready to learn, a teacher will appear.
doall
in apply
to force evaluation of the arguments seq but it's not the case when the applied function is variadic.
but-last
to avoid name clash with butlast
which is a low-level function (it is used in the definition of defn
).(defn but-last
"Return a lazy sequence of all but the n last items in coll."
([coll] (but-last coll 1))
([coll n]
((fn this [s os]
(if os
(lazy-cons (first s) (this (rest s) (rest os))))) (seq coll) (drop n coll))))
(defn drop-lastand shared with us, mere mortals, a piece of wisdom:
"Return a lazy seq of all but the last n (default 1) items in coll"
([s] (drop-last 1 s))
([n s] (map (fn [x _] x) (seq s) (drop n s))))
I constantly have to remind myself to try to use a higher-order fn, because lazy-cons is so easyFrom now on, I'll try to question each lazy-cons.