Re: Scope Question



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.
.



Relevant Pages

  • Re: Cant resolve certain domains
    ... Server: svr-ad1.ppenet.com ... sun.com nameserver = cbru.br.ns.els-gms.att.net ... header flags: query, want recursion ...     HEADER: ...
    (microsoft.public.windows.server.dns)
  • Re: Godel proved maths inconsistent not incompleteness theorem
    ... Perhaps if you answered the following for CBL: ...   it is recursive. ... represented by the elements of the universal set and one of the axioms ... Recursion Theory doesn't use a set theory, ...
    (sci.logic)
  • Re: Run-time error 6 Overflow
    ... target cell that caused the change event. ... thought maybe the recursion caused that calculation to get pretty large. ...
    (microsoft.public.excel)
  • Re: Its A Big Language Survey
    ... will expell him from the group of compund loop ... Recursion and functional style usually results in a cleaner code, ... (defun collect (item/s) ...   (etypecase x ...
    (comp.lang.lisp)
  • Re: HP48 : recursion : more and more slower
    ...     DUP DO>STR DISPROW1 ... Are you sure the problem is recursion? ... I can't find any documentation on the memory layout. ... calculator moves the return stack when it starts to get large. ...
    (comp.sys.hp48)