I'm having fun with The Land of Lisp. I've been trying to write the game that the book describes. I'm kind of stuck with the last function in this code:
Code:
(defparameter *nodes* '((living-room (you are in the living-room.
a wizard is snoring loudly on the couch.))
(garden (you are in a beautiful garden.
there is a well in front of you.))
(attic (you are in the attic.
there is a giant welding torch in the corner.))))
(defun describe-location (location nodes)
(cadr (assoc location nodes)))
(defparameter *edges* '((living-room (garden west door)
(attic upstairs ladder))
(garden (living-room east door))
(attic (living-room downstairs ladder))))
(defun describe-path (edge)
`(there is a ,(caddr edge) going ,(cadr edge) from here.))
(defun describe-paths (location edges)
(apply #'append (mapcar #'describe-path (cdr (assoc location edges)))))
(defparameter *objects* '(whiskey bucket frog chain))
(defparameter *object-locations* '((whiskey living-room)
(bucket living-room)
(chain garden)
(frog garden)))
(defun objects-at (loc objs obj-locs)
(labels ((at-loc-p (obj)
(eq (cadr (assoc obj obj-locs)) loc)))
(remove-if-not #'at-loc-p objs)))
Code:
CL-USER> (objects-at 'living-room *objects* *object-locations*)
(WHISKEY BUCKET)
Where does it say in the objects-at function to GO OVER all the elements of the obj-locs list? eq? No. cadr? No. Assoc? No.
Where does the obj variable take its value from? And what is it?
I believe I understand the function's separate parts but as a whole I don't think I know how exactly it filters *object-locations* to extract the objects in the living room.
Thanks for your patience (beware: newbie)