You are previewing Land of Lisp.

Land of Lisp

Cover of Land of Lisp by Conrad Barski M.D. Published by No Starch Press
O'Reilly logo

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 ...

The best content for your career. Discover unlimited learning on demand for around $1/day.