2017-03-06 16:52:06 -05:00
|
|
|
(load "../lang/dlambda.lisp")
|
|
|
|
|
|
|
|
(defun interest-compounder (initial-principal initial-interest-rate)
|
|
|
|
(let ((private) (public)
|
|
|
|
(principal initial-principal)
|
2017-03-07 11:37:27 -05:00
|
|
|
(interest-rate initial-interest-rate)
|
|
|
|
(years-passed 0))
|
2017-03-06 16:52:06 -05:00
|
|
|
|
|
|
|
(setf private
|
|
|
|
(eval
|
|
|
|
(dlambda
|
|
|
|
|
2017-03-07 11:37:27 -05:00
|
|
|
(:add-years (years)
|
|
|
|
(if (> years 0)
|
|
|
|
(setf years-passed (+ years-passed years))))
|
|
|
|
|
2017-03-06 16:52:06 -05:00
|
|
|
(:percent-of-number (n percentage)
|
|
|
|
(if (> percentage 0)
|
|
|
|
(/ (+ (* n percentage) 50) 100)
|
|
|
|
(/ (- (* n percentage) 50) 100)))
|
|
|
|
|
|
|
|
(:compound-interest (years)
|
|
|
|
(if (> years 0)
|
|
|
|
(progn
|
|
|
|
(setf principal
|
|
|
|
(+ principal
|
|
|
|
(call private :percent-of-number principal interest-rate)))
|
|
|
|
(call private :compound-interest (- years 1))))))))
|
|
|
|
|
|
|
|
(setf public
|
|
|
|
(eval
|
|
|
|
(dlambda
|
|
|
|
|
2017-03-07 11:37:27 -05:00
|
|
|
(:get-years-passed ()
|
|
|
|
years-passed)
|
|
|
|
|
2017-03-06 16:52:06 -05:00
|
|
|
(:get-principal ()
|
|
|
|
principal)
|
|
|
|
|
|
|
|
(:get-interest-rate ()
|
|
|
|
interest-rate)
|
|
|
|
|
2017-03-07 11:37:27 -05:00
|
|
|
(:set-interest-rate (new-interest-rate)
|
|
|
|
(setf interest-rate new-interest-rate))
|
2017-03-06 16:52:06 -05:00
|
|
|
|
|
|
|
(:move-forward-years (years)
|
2017-03-07 11:37:27 -05:00
|
|
|
(progn
|
|
|
|
(call private :add-years years)
|
|
|
|
(call private :compound-interest years))))))))
|