Re: Scope Question
- From: dstein64 <DStein64@xxxxxxxxx>
- Date: Tue, 29 Apr 2008 15:39:00 -0700 (PDT)
This counter function should give you an idea:
(let ((count 0))
(defun counter ()
(incf count)))
(that is, make it a closure)
If your recursive function was in a LABELS, you would bind your
variable outside of the LABELS form. Implementing the function with a
locally defined function would probably be best because it means you
might need to do less setup/cleanup.
I forgot to mention that I would like the variable to reset itself on
each call to the function (but not on the recursive calls. So in your
example, I would like count to be reset to 0 each time counter is
called from the program. Although there is no recursion in that
example, I would not like count to be reset each time counter is
called recursively by counter.
.
- Follow-Ups:
- Re: Scope Question
- From: Nathaniel Calloway
- Re: Scope Question
- From: Brian
- Re: Scope Question
- References:
- Scope Question
- From: dstein64
- Re: Scope Question
- From: Brian
- Scope Question
- Prev by Date: Re: Scope Question
- Next by Date: Re: Iteration in lisp
- Previous by thread: Re: Scope Question
- Next by thread: Re: Scope Question
- Index(es):
Relevant Pages
|