Shammer's Philosophy

My private adversaria

Using find-if instead of remove-if-not

This is a continuous article of remove-if と remove-if-not を理解する - Shammerism and find と remove-if-not - Shammerism. Lisp functions end-with -not would be deprecated in the future, so I have to get used to use functions which are not finished with -not instead of ones which end-with -not.

At first, I try to use find-if. I couldn't use those functions which end-with -if because I couldn't understand the description of CLHS like CLHS: Function FIND, FIND-IF, FIND-IF-NOT. But, it was until today. Here is my first sample.

? (defparameter x '(("Code" "200") ("Host" "localhost")))
X
? x
(("Code" "200") ("Host" "localhost"))
?  (find-if #'(lambda (n) (equal "Code" n)) x :key #'car)
("Code" "200")
?

The sample overwriting the value is below.

? x
(("Code" "200") ("Host" "localhost"))
? (setf (cadr (find-if #'(lambda (n) (equal "Code" n)) x :key #'car)) "201")
"201"
? x
(("Code" "201") ("Host" "localhost"))
?