Define (make-balance initial-balance) to return a function that takes 0 or 1 arguments. If that function is called with 0 arguments, it returns the current balance. If called with 1 argument, which should be a number, it adds that number to the current balance, and returns the new balance.
> (setq bal (make-balance 100))Solution:
<>
> (funcall bal 10)
110
> (funcall bal -50)
60
> (funcall bal)
60
(defun make-balance (bal)
(let ((balance bal))
#'(lambda (&optional (amt 0))
(setf balance (+ amt balance)))))
No comments:
Post a Comment