lisp - Let being called multiple times in recursion -
lisp - Let being called multiple times in recursion -
i trying declare local variable utilize within recursive function, allow seems beingness called each time function recurses. want allow function called 1 time declare variable , give value nil, i'd update value of local variable within recursive function without beingness wiped each recurse.
here simplified framework of code.
(defun recursive-function (l1 l2) (let ((?x nil)) (cond (... ... ... ;trying update value of ?x here (setf ?x 5) (recursive-funtion (rest l1)(restl2)) ;recursive phone call made ))))
what you've written you've said don't want; local variable within of recursive function should updating each pass. if i've understood correctly, you'll need like
(defun recursive-function (l1 l2) (let ((?x nil)) (labels ((actual-recursion (a b) (cond (... ... ... (actual-recursion (rest a) (rest b)))))) (actual-recursion l1 l2))))
so each recursive phone call doesn't create new binding of ?x
.
recursion lisp common-lisp let
Comments
Post a Comment