Created
November 21, 2014 06:19
-
-
Save kuanyui/db54d8b34b1e34b24c16 to your computer and use it in GitHub Desktop.
[Lisp] Non-destructively replace #N element in list. (recursion way)
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 rep-elt (list &optional n new) | |
(cond ((null n) | |
list) | |
((> n 0) | |
(cons (car list) (rep-elt (cdr list) (1- n) new))) | |
((eq n 0) | |
(cons new (cdr list)) | |
))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment