Some questions brought up by the text game in ch 5, particularly the describe-location function:
(defun describe-location (location nodes)
(cadr (assoc location nodes)))
As I understand it, what's happening is we're defining a function named describe-location that takes location and nodes as arguments, so for example if I call
(describe-location 'garden *nodes*) it goes to the *nodes* parameter, pulls out the 'garden bit (garden (you are in a beautiful garden. there is a well in front of you)) and lops off "(garden " because of the cadr returning only (you are in a beautiful garden. there is a well in front of you)
1. I think I get the read vs evaluate bit, but it's rather tenuous. Am I correct that first Lisp reads the whole thing, then evaluates from the inside out [first finds, (assoc location nodes) then "cadr's" it then returns the result as the value of describe location]?
2. cadr is the same as (car (cdr ()) which is the same as from the rest take the first which is equivalent to get rid of the first symbol and from the rest take the first?
3. Do we use cadr because its just less typing (more elegant and downright cool?) than (first (rest())?
4. Why not just use cdr since, in this case anyway, we know there are only two symbols, the location and the description. Would cdr not do the same as cadr in this instance?
regards, Richard