Created
October 15, 2016 13:29
-
-
Save hmenn/f8470d2dda34f938441c859b99922cca to your computer and use it in GitHub Desktop.
replaces first occurence with new value and returns array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defun replace-first (i1 i2 l) | |
| (cond | |
| ((endp l) nil) ; end of list | |
| ((equal i1 (first l)) (cons i2 (rest l))) ; found. combine cells with cons | |
| (t (cons (first l) (replace-first i1 i2 (rest l)))) ; recursive rest call | |
| ) | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment