Looking Around in our Game World

The first command we'd want to have is one that tells us
about the location we're standing in. So what would a function
need to describe a location in a world? Well, it would need to
know the location we want to describe and be able to look at a
map and find that location on the map. Here's our function, and
it does exactly that:

(defun describelocation (location map)
(second (assoc location map)))

The word defun means, as you might expect, that we're
defining a function. The name of the function is
describelocation and it takes two parameters: a location
and a map. These variables are local parameters of a function
and hence unrelated to the global location
and map variables. Note that functions in
Lisp are often more like functions in math than in other
programming languages: If you can remember back to your
prealgebra class, a math function is just a relationship
between a bunch of inputs (called the domain) to an output
(called the range.) In math, you would never have a function
that pops up a message box or prints stuff for the user to read 
Our function describelocation is a lot like that, because
it is a function that just calculates a value (in this case, the
description of a location on our map.) Let's imagine our
location is in the livingroom (which, indeed, it is...)

<< begin
< previous 
next >
end >>
