Re: Scope Question



dstein64 <DStein64@xxxxxxxxx> writes:

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.

Is there a problem with passing count back as an argument? If you
don't want to expose count you can just wrap up the recursive part in
labels:

(defun print-10-times (str)
(labels ((recursive-part (times-left)
(when (> times-left 0)
(print str)
(recursive-part (- times-left 1)))))
(recursive-part 10)))

-Nat
.



Relevant Pages

  • Re: F8 and Yellow pattern for compile error
    ... I used *recursion* word as a pun. ... I wanted to *predict* when VBA would reset and when it wouldnt. ... >> recursive mode with VBA) to the code Line and herein lies my doubt. ...
    (microsoft.public.excel.programming)
  • Re: Scope Question
    ... How can I store a list such that it is not reset on each ... recursive call to the search function? ...   ... If you use a global variable for recursion context, ...
    (comp.lang.lisp)
  • Re: Scope Question
    ...   ... If your recursive function was in a LABELS, ... I forgot to mention that I would like the variable to reset itself on ... Although there is no recursion in that ...
    (comp.lang.lisp)
  • hp50G and recursion
    ... I just bought this calculator, ... sometimes it ends up with e reset. ...
    (comp.sys.hp48)