Skip to content

Instantly share code, notes, and snippets.

@kuanyui
Created November 21, 2014 06:19
Show Gist options
  • Save kuanyui/db54d8b34b1e34b24c16 to your computer and use it in GitHub Desktop.
Save kuanyui/db54d8b34b1e34b24c16 to your computer and use it in GitHub Desktop.
[Lisp] Non-destructively replace #N element in list. (recursion way)
(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