Defining Local Variables in Lisp

For our simple game, we’ve defined global variables and functions. However, in most cases you’ll want to limit your definitions to a single function or a block of code. These are called local variables and functions.

To define a local variable, use the command let. A let command has the following structure:

 (let (variable declarations)
   ...body...)

The first thing inside the let command is a list of variable declarations . This is where we can declare one or more local variables. Then, in the body of the command (and ...

Get Land of Lisp now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.