I'm currently reading the book Land of LISP
, and I'm just working through the first chapter. In there, there is a little program written where the computer guesses numbers between 1 and 100. Its code is as follows:
(defparameter *small* 1)
(defparameter *big* 100)
(defun guess-my-number ()
(ash (+ *small* *big*) -1))
(defun smaller ()
(setf *big* (1- (guess-my-number)))
(guess-my-number))
(defun bigger ()
(setf *small* (1+ (guess-my-number)))
(guess-my-number))
(defun start-over ()
(defparameter *small* 1)
(defparameter *big* 100)
(guess-my-number))
So far, I understand what happens, and Using 'ash' in LISP to perform a binary search? helped me a lot in this. Nevertheless there's one thing left that puzzles me: As far as I have learned, you use setf
to assign values to variables, and defparameter
to initially define variables. I also have understood the difference between defparameter
and defvar
(at least I believe I do ;-)).
So now my question is: If I should use setf
to assign a value to a variable once it had been initialized, why does the start-over
function use defparameter
and not setf
? Is there a special reason for this, or is this just sloppiness?