From "Practical Common Lisp", chapter 6 "Variables":
"Practically speaking, you should use DEFVAR to define variables that will contain data you'd want to keep even if you made a change to the source code that uses the variable. For instance, suppose the two variables defined previously are part of an application for controlling a widget factory. It's appropriate to define the *count* variable with DEFVAR because the number of widgets made so far isn't invalidated just because you make some changes to the widget-making code."
I don't get it: I write some app, and the code for a widget factory. Let's suppose I write a function:
Now, let's suppose that I have found a bug. I have to stop my app, fix the bug, compile my app again and run it. There are two possibilities: my app either is able to read (from some configuration file) the number of times the make-a-widget function was called, or it isn't. In the first case:
So, what's the point?
"Practically speaking, you should use DEFVAR to define variables that will contain data you'd want to keep even if you made a change to the source code that uses the variable. For instance, suppose the two variables defined previously are part of an application for controlling a widget factory. It's appropriate to define the *count* variable with DEFVAR because the number of widgets made so far isn't invalidated just because you make some changes to the widget-making code."
I don't get it: I write some app, and the code for a widget factory. Let's suppose I write a function:
(defun make-a-widget ...<some stuff here>...)
The function returns a new widget, but it also counts, how many times it was called. I get it.Now, let's suppose that I have found a bug. I have to stop my app, fix the bug, compile my app again and run it. There are two possibilities: my app either is able to read (from some configuration file) the number of times the make-a-widget function was called, or it isn't. In the first case:
(defvar *counter* my-read-value)
In the second case:(defvar *counter* 0)
In both cases DEFVAR will refer to an unbound variable, so the default value will be used.So, what's the point?