setf and nth problem
Posted: Tue Sep 28, 2010 9:26 pm
Hi guys i am having a lot of trouble with this relatively simple piece of code. I cant for the life of me figure out whats wrong with it
Basically the program figures out how to get exactly half of an 8 liter paint time using the 8 liter tin, 5 liter, and a 3 liter tin,
To express this problem i made the list (eight-tin five-tin three-tin). so the initial state would be (8 0 0)
i believe that it is one of these two functions that are giving me the problem:
1) room-in-three gives back how much room there is in the 3 liter can
2) fix-three makes it so the 3 liter can is not negative or holding more than 3 liters
When i run an a-star search i get this error
*** - NTH: 3 is not a list
Can anyone explain why this is happening, i have been staring at the screen for an hour looking for a syntax mistake but cant find any.
Any help would be greatly appreciated.
Cheers
Basically the program figures out how to get exactly half of an 8 liter paint time using the 8 liter tin, 5 liter, and a 3 liter tin,
To express this problem i made the list (eight-tin five-tin three-tin). so the initial state would be (8 0 0)
i believe that it is one of these two functions that are giving me the problem:
1) room-in-three gives back how much room there is in the 3 liter can
2) fix-three makes it so the 3 liter can is not negative or holding more than 3 liters
Code: Select all
(defun room-in-three (a)
(- 3 (nth 2 a)))
Code: Select all
(defun fix-three (a)
(cond ((< (nth 2 a) 0) (setf (nth 2 a) 0))
((> (nth 2 a) 3) (setf (nth 2 a) 3))))
*** - NTH: 3 is not a list
Can anyone explain why this is happening, i have been staring at the screen for an hour looking for a syntax mistake but cant find any.
Any help would be greatly appreciated.
Cheers