Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does REMOVE ever return the same sequence, in practice?

Tags:

common-lisp

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"
like image 458
Jacob Gabrielson Avatar asked Nov 21 '25 00:11

Jacob Gabrielson


1 Answers

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
like image 162
Rainer Joswig Avatar answered Nov 22 '25 14:11

Rainer Joswig



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!