Re: Some expert comment please



In article <1185821750.897199.140250@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
anders <anders.u.persson@xxxxxxxxx> wrote:

I have write my "first" useful program,
i looks in a catalog för files ending on .tmp
and erase them, could make it on 1 line
with batch, but i like to use LISP.

So i came upp with follow
----------------------------------------------------------
(defvar *content* (directory "*.tmp"))

(dolist (file-name *content*)
(delete-file file-name))
----------------------------------------------------------

Any comment ?
Regarding should/should not,
This is better etc.

Tankfull for en expert comment.

DEFVAR only assigns the default value to a variable if it doesn't
already have a value. So if you use this code twice, the second time it
will try to delete the files that it deleted the first time, rather than
look up the current list of *.tmp files.

In general, DEFVAR should be used for global variables that you plan on
referencing from multiple places, or that the may want to assign to. If
you just want a temporary name within a piece of code, use LET to create
a local variable:

(let ((content (directory "*.tmp")))
(dolist (file-name content)
(delete-file file-name)))

--
Barry Margolin, barmar@xxxxxxxxxxxx
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
.