;really slow reverse
;put the last item of the list at the start of a new list, and recur over all but the last item of the list.
;butlast acts similar to next in that it returns null for a 1-item list.
(defn my-reverse
([a-list]
(cond (= a-list nil) nil
:else (cons (last a-list)
(my-reverse (butlast a-list))))))
(def
^{:arglists '([coll])
:doc "Return a seq of all but the last item in coll, in linear time"
:added "1.0"
:static true}
butlast (fn ^:static butlast [s]
(loop [ret [] s s]
(if (next s)
(recur (conj ret (first s)) (next s))
(seq ret)))))
Comments top
No comments for butlast. Log in to add a comment.