From: Brian Kendig
Subject: Setting value outside 'while' & changing it inside -- how?
Date:
Message-ID: <bskendigCrAIqx.H5D@netcom.com>
In my Lisp program, I have code that looks basically like this:
(setf foo (whatever))
(while foo
...
(setf foo (whatever)))
Problem is, when I try to byte-compile the program in Emacs Lisp, I get
errors in this particular snippet of code:
** assignment to free variable foo
** reference to free variable foo
Why is it complaining? What am I doing wrong? What is the "correct"
way to set a value before a loop, test it before every iteration of the
loop, and change its value at the end of every iteration?
--
_/_/_/ Brian Kendig Je ne suis fait comme aucun
/_/_/ ········@netcom.com de ceux que j'ai vus; j'ose croire
_/_/ n'etre fait comme aucun de ceux qui existent.
/ Be insatiably curious. Si je ne vaux pas mieux, au moins je suis autre.
/ Ask "why" a lot. -- Rousseau
In article <··················@netcom.com> ········@netcom.com (Brian Kendig) writes:
In my Lisp program, I have code that looks basically like this:
(setf foo (whatever))
(while foo
...
(setf foo (whatever)))
Problem is, when I try to byte-compile the program in Emacs Lisp, I get
errors in this particular snippet of code:
** assignment to free variable foo
** reference to free variable foo
You should create the variable before you assign to it, either with
defvar:
(defvar foo init-value)
(while foo
...
(setf foo (whatever)))
or with let:
(let ((foo init-value))
(while foo
...
(setf foo (whatever))))
beware of dynamic scoping in emacs; if you use the defvar approach, be
sure to prepend the variable name with the name of your package, ie
"dired-foo", "shell-foo", etc.
--
Ben Mesander #!/bin/ksh
This is not official USGS policy, etc. print I am not a perl hacker.