I have been searching everywhere for the following functionality in Lisp, and have gotten nowhere:
-
find the index of something in a list. example:
(index-of item InThisList) -
replace something at a specific spot in a list. example:
(replace item InThisList AtThisIndex) ;i think this can be done with 'setf'? -
return an item at a specific index. example:
(return InThisList ItemAtThisIndex)
Up until this point, I’ve been faking it with my own functions. I’m wondering if I’m just creating more work for myself.
This is how I’ve been faking number 1:
(defun my-index (findMe mylist) (let ((counter 0) (found 1)) (dolist (item mylist) (cond ((eq item findMe) ;this works because 'eq' checks place in memory, ;and as long as 'findMe' was from the original list, this will work. (setq found nil) (found (incf counter)))) counter))
You can use
setfandnthto replace and retrieve values by index.To find by index you can use the
positionfunction.I found these all in this index of functions.