Newbie question in Common Lisp:
How to make my procedure to return distinct procedural object with its own local binding each time call? Currently, I use let to create the local state, but two function calls are sharing the same local state. Here is the code,
(defun make-acc ()
(let ((balance 100))
(defun withdraw (amount)
(setf balance (- balance amount))
(print balance))
(defun deposit (amount)
(setf balance (+ balance amount))
(print balance))
(lambda (m)
(cond ((equal m 'withdraw)
(lambda (x) (withdraw x)))
((equal m 'deposit)
(lambda (x) (deposit x)))))))
;; test
(setf peter-acc (make-acc))
(setf paul-acc (make-acc))
(funcall (funcall peter-acc 'withdraw) 10)
;; Give 90
(funcall (funcall paul-acc 'withdraw) 10)
;; Expect 90 but give 80
Should I do it in another way? Is my way of writing wrong? Can someone pls help me to clear this doubt? Thanks in advance.