2017-03-06 16:52:06 -05:00
|
|
|
(load "../lang/dlambda.lisp")
|
|
|
|
|
2017-03-08 11:14:44 -05:00
|
|
|
(let ((static))
|
|
|
|
|
|
|
|
(setq static
|
2017-03-10 15:08:42 -05:00
|
|
|
(dlambda
|
|
|
|
(:percent-of-number (n percentage)
|
|
|
|
(if (> percentage 0)
|
|
|
|
(/ (+ (* n percentage) 50) 100)
|
|
|
|
(/ (- (* n percentage) 50) 100)))))
|
2017-03-08 11:14:44 -05:00
|
|
|
|
|
|
|
(defun interest-compounder (initial-principal initial-interest-rate)
|
|
|
|
(let ((private) (public)
|
|
|
|
(principal initial-principal)
|
|
|
|
(interest-rate initial-interest-rate)
|
|
|
|
(years-passed 0))
|
|
|
|
|
|
|
|
(setq private
|
2017-03-10 15:08:42 -05:00
|
|
|
(dlambda
|
|
|
|
(:add-years (years)
|
|
|
|
(if (> years 0)
|
|
|
|
(setq years-passed (+ years-passed years))))
|
|
|
|
|
|
|
|
(:compound-interest (years)
|
|
|
|
(if (> years 0)
|
|
|
|
(begin
|
|
|
|
(setq principal
|
|
|
|
(+ principal
|
|
|
|
(call static :percent-of-number principal interest-rate)))
|
2017-11-17 17:57:14 -05:00
|
|
|
(recur (- years 1)))))))
|
2017-03-07 11:37:27 -05:00
|
|
|
|
2017-03-08 11:14:44 -05:00
|
|
|
(setq public
|
2017-03-10 15:08:42 -05:00
|
|
|
(dlambda
|
|
|
|
(:get-years-passed ()
|
|
|
|
years-passed)
|
2017-03-06 16:52:06 -05:00
|
|
|
|
2017-03-10 15:08:42 -05:00
|
|
|
(:get-principal ()
|
|
|
|
principal)
|
2017-03-06 16:52:06 -05:00
|
|
|
|
2017-03-10 15:08:42 -05:00
|
|
|
(:get-interest-rate ()
|
|
|
|
interest-rate)
|
2017-03-08 11:14:44 -05:00
|
|
|
|
2017-03-10 15:08:42 -05:00
|
|
|
(:set-interest-rate (new-interest-rate)
|
|
|
|
(setq interest-rate new-interest-rate))
|
2017-03-08 11:14:44 -05:00
|
|
|
|
2017-03-10 15:08:42 -05:00
|
|
|
(:make-contribution (contribution)
|
|
|
|
(setq principal (+ principal contribution)))
|
2017-03-08 11:14:44 -05:00
|
|
|
|
2017-03-10 15:08:42 -05:00
|
|
|
(:move-forward-years (years)
|
|
|
|
(call private :compound-interest years)
|
|
|
|
(call private :add-years years)))))))
|