Looking at a site like this makes me appreciate a language like Clojure more.
I was quite surprised a while ago when I learned that `sort` in Common Lisp can mutate somehow randomly.
> The sorting operation can be destructive in all cases.
I was quite surprised a while ago when I learned that `sort` in Common Lisp can mutate somehow randomly.
> The sorting operation can be destructive in all cases.
CL-USER> (defun abc-without (letter) (delete letter '(a b c)))
ABC-WITHOUT
CL-USER> (abc-without 'a)
(B C)
CL-USER> (abc-without 'b)
(A C)
CL-USER> (abc-without 'c)
(A)
This behaves strangely because it modifies the constant list (A B C) rather
than consing up a new one on each invocation (like calling LIST or COPY-SEQ
would), so by the end the list it passes to DELETE has been reduced to (A). (defun isort (sequence predicate &key (key #'identity))
(sort (copy-seq sequence) predicate :key key))