KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I want to change the nth element of a list and return a new list. I've thought of three rather inelegant solutions: (defun set-nth1 (list n value) (let ((list2 (copy-seq list))) (setf (elt list2 n) value) list2)) (defun set-nth2 (list n value) (concatenate 'list (subseq list 0 n) (list value) (subseq list (1+ n)))) (defun set-nth3 (list n value) (substitute value nil list :test #'(lambda (a b) (declare (ignore a b)) t) :start n :count 1)) What is the best way of doing this?
Tags (comma-separated)
Save Edits
Cancel