Skip to content

Instantly share code, notes, and snippets.

@hmenn
Created October 15, 2016 13:29
Show Gist options
  • Select an option

  • Save hmenn/f8470d2dda34f938441c859b99922cca to your computer and use it in GitHub Desktop.

Select an option

Save hmenn/f8470d2dda34f938441c859b99922cca to your computer and use it in GitHub Desktop.
replaces first occurence with new value and returns array
(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