Re: Scope Question
- From: Brian <quickbasicguru@xxxxxxxxx>
- Date: Tue, 29 Apr 2008 15:26:02 -0700 (PDT)
dstein64 wrote:
Suppose I have a recursive function that is searching for elements inThis counter function should give you an idea:
a tree. How can I store a list such that it is not reset on each
recursive call to the search function?
In general, how can I initialize a variable within a function that
will not be reset on each recursive call to that function? I hope my
question is clear. If not, please let me know. Thanks.
(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.
.
- Follow-Ups:
- Re: Scope Question
- From: Kaz Kylheku
- Re: Scope Question
- From: dstein64
- Re: Scope Question
- References:
- Scope Question
- From: dstein64
- Scope Question
- Prev by Date: Scope Question
- Next by Date: Re: Scope Question
- Previous by thread: Scope Question
- Next by thread: Re: Scope Question
- Index(es):
Relevant Pages
|