3 ms·
Common Lisp takes expressions for default arguments, and has the "fixed" behavior; when one wants a persistent value, they do either: (let ((my-list '(1 2
by remexre 5y ago
Common Lisp takes expressions for default arguments, and has the "fixed" behavior; when one wants a persistent value, they do either:
(let ((my-list '(1 2 3)))
(defun foo (&optional (l my-list))
(setf (car l) 'hello)
l))
or, more often, just make it a special variable of some sort:
(defvar *my-list* '(1 2 3))
(defun foo (&optional (l *my-list*))
(setf (car l) 'hello)
l))
This seems to work fine, and brings attention to "I have an object that supports mutation, and I'm actually going to mutate it," which is an unusual enough case to be worth calling out.
- lispm 5y agoYou are modifying literal data, which is not a good idea.