Does REMOVE ever return the same sequence in any real implementations of Common Lisp? The spec suggests that it is allowed:
The result of remove may share with sequence; the result may be identical to the input sequence if no elements need to be removed.
SBCL does not seem to do this, for example, but I only did a crude (and possibly insufficient) test, and I'm wondering what other implementations do.
CL-USER> (defparameter *str* "bbb") *STR* CL-USER> *str* "bbb" CL-USER> (defparameter *str2* (remove #\a *str*)) *STR2* CL-USER> (eq *str* *str2*) NIL CL-USER> *str* "bbb" CL-USER> *str2* "bbb"
Returning the original string could be useful. In case no element of a string gets removed, returning the original sequence prevents allocation of a new sequence. Even if a new sequence has been allocated internally, this new sequence could be turned into garbage as soon as possible.
CLISP for example returns the original string.
[1]> (let ((a "abc")) (eq a (remove #\d a)))
T
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With