Variable assignment in Lisp.
Hi,
I am exploring Clisp and my previous experience is extremely limited in the LISP programming language. My question is this : I have a list of numbers defined by say : (setq mylist '(34 78 5 231 873 76 43 82)) Now, for some reason I need to set the first value to 97 instead of 34 How do I do it the correct LISP way ? If the value I want to change is the first one I can use something like : (setq mylist (cons 97 (cdr mylist))) But how do I do if the value I need to modify is at an arbitrary rank (for example the 39th in a long list) ? |
If you are happy to destructively modify the list, then you can use setf. For example, the following would set the 39th element to be 97:
Code:
(setf (nth 39 mylist) 97) Code:
(defun nreplace (n l e) |
|
All times are GMT -5. The time now is 11:54 AM. |