Lisp practice fuction not returning what I expected
Posted: Tue Jan 12, 2010 2:52 pm
Hi all,
I've written a function to rate games and return a list of the games with their rating, but I am having trouble getting it to return the list properly. It either returns the list with their ratings as 0 or as 1, never more like it should. I have worked on this function for a while now and no matter how many times I've rewritten it, and tried imagining what it is returning, I just can't seem to get it to work! It makes sense in my head, but doesn't seem to work in Lisp. The code is below:
I'm still getting practice with lists which is why I haven't used global variables or classes. I managed to get Lisp working with my other methods the way I wanted to, but this one is just being stubborn. I would really appreciate any help.
I've written a function to rate games and return a list of the games with their rating, but I am having trouble getting it to return the list properly. It either returns the list with their ratings as 0 or as 1, never more like it should. I have worked on this function for a while now and no matter how many times I've rewritten it, and tried imagining what it is returning, I just can't seem to get it to work! It makes sense in my head, but doesn't seem to work in Lisp. The code is below:
Code: Select all
(setf game-list '(((title "New Super Mario Bros. Wii") (genre "Platform") (platform "Wii") (price 20))
((title "Quake") (genre "First Person Shooter") (platform "PC") (price 5)))
Code: Select all
(defun rate (a-list &optional title genre platform price)
(setf rated-games nil)
(dolist (elem a-list)
Code: Select all
(rate game-list nil "Platform" "Wii" nil)