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 describe-location (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 `describe-location` and it takes two parameters: a location and a map. These variables are local parameters of a function and hence unrelated to the global `lisp-adventure-location` and `lisp-adventure-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 pre-algebra 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 `describe-location` 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 living-room (which, indeed, it is...)
<< begin < previous - next > end >>