Exercise 1.4.16
More Appending
Like car
, cdr
, first
, rest
, last
and nth
, append
is functional. It will return a new list rather than mutating any of its arguments.
* (defvar *lst* (list 1 2 3 4 5))
*lst*
* *lst*
(1 2 3 4 5)
* (append *lst* (list 6 7 8))
(1 2 3 4 5 6 7 8)
* *lst*
(1 2 3 4 5)
* (append (list -3 -2 -1 0) *lst*)
(-3 -2 -1 0 1 2 3 4 5)
* *lst*
(1 2 3 4 5)
* (append (list 0) *lst* (list 6))
(0 1 2 3 4 5 6)
* *lst*
(1 2 3 4 5)
This means both that you may safely pass it any data you want appended without worrying about losing the original lists, and that if you want such behavior, you need to explicitly assign the result of append
yourself.