Defining Global Functions in Lisp

Our guess-my-number game has the computer respond to the player’s request to start the game, and then to requests for either smaller or bigger guesses. For these, we need to define three global functions: guess-my-number, smaller, and bigger. We’ll also define a function to start over with a different number, called start-over. In Common Lisp, functions are defined with defun, like this:

(defun function_name (arguments)
  ...)

First, we specify the name and arguments for the function. Then we follow it up with the code that composes the function’s logic.

Defining the guess-my-number Function

The first function we’ll define is guess-my-number. This function uses the values of the *big* and *small* variables to generate ...

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.