I am very new to LISP and was having some trouble using a manipulating arrays. There aren't many resources on it since it seems Lists are more widely used. I have the following code where I am attempting to look through an array and return the spot that the minimum value occurs (I don't know if my formatting is correct):
(defun FIND-MIN(x)
(setq ctr (aref x 0)) (setq pos 1) (setq finalpos 1)
(loop while (< pos (array-total-size x))
do
(
(if (< ctr (aref Z pos))
(progn
(setq ctr pos)
(setq finalpos pos))
(incf pos)
)
)
finalpos
)
My reasoning behind this is to first create some variables, ctr which is set to the first position by default and tracks the minimum value, a position counter (pos) to keep track of where I am in the array, and a finalpos variable to store where the minimum value occurs. Then I will loop until pos gets to the end of the array. At every step it checks if the element is smaller than ctr and if it is ctr is updated and finalpos is updated. pos is then incremented to continue the array. After each element is checked the program will return finalpos, which should be the location of the smallest element.
The error that I get from this is:
- SYSTEM::%EXPAND-FORM: (SETQ CTR (AREF X 0)) should be a lambda expression
I didn't think I needed a lambda expression since aref is just grabbing a single value (the first one) and pulling a single value is aref's job. Also please point out if my logic is flawed because this new language is very different to any that I have used before. Any and all help is greatly appreciated!