at-loc-p is being passed a list, but is declared to take a single object (atom). This seems like it should crash, but instead the list is scrolled though. Does the the #' grant this power to cycle over a list?
In C++ this would need some type of for-loop. I have commented in Step 1 and Step 2 below.
Can anyone clue me in on how the single elements of objs are being passed through? I am confused by this property of LISP.
;; object - objects
(defparameter *objects* '(whisky-bottle bucket frog chain))
;; object - object locations
(defparameter *object-locations* '((whisky-bottle living-room)
;; function returns list of objects at location
(defun objects-at (loc objs obj-locs)
(labels ((at-loc-p (obj) ;; Step 2: at-loc-p somehow runs once for each obj in objs, but only takes a single obj
(eq (cadr (assoc obj obj-locs)) loc)))
(remove-if-not #'at-loc-p objs))) ;; Step 1: remove-if-not passes the full list of objs to at-loc-p above
(princ (objects-at 'living-room *objects* *object-locations*))