From: "Jarl Friis" <jarl(a)diku.dk>
> > BTW: I found another situation where defvar could/should
not be
replaced
> > dy defconst nor defcustom: When some information has to be
stored
> > internally from function call to function call (like the kill-ring and
> > search-ring). In OO-terms one can think of them as private members.
>
> defvar is public. If you want a private variable binding, use let.
Yes, but when you want to store information from one function call to the
next one, there are only global public space to use, so defvar is it.
Oh, I'm failure as a teacher, that's for sure. Maybe you just needed a
better example. How about if I use one of your examples, the kill-ring?
Edit your simple.el. Delete the defvars for kill-ring and
kill-ring-yank-pointer, and wrap the next three defuns in a let, like this:
(let ((kill-ring nil)
(kill-ring-yank-pointer nil))
(defun kill-new (string &optional replace)
...)
(defun kill-append (string before-p)
...)
(defun current-kill (n &optional do-not-move)
...))
Untested, and it may not work, because in real life kill-ring is not
private, and other stuff may depend on it being public. But I hope it makes
the concept clear.
PFK