Rudolf Adamkovič Personal site


Gotcha with destructive concatenation

As a rule of thumb,

always give mapcan a new list,

because it concatenates results destructively, so for example

(mapcan (lambda (x) (cons x '(a b c))) '(10 20 30))

crashes due to circularity, and must be written as

(mapcan (lambda (x) (copy-sequence (cons x '(a b c)))) '(10 20 30))
(10 a b c 20 a b c 30 a b c)

© 2025 Rudolf Adamkovič under GNU General Public License version 3.
Made with Emacs and secret alien technologies of yesteryear.