2006-11-29 [長年日記]

_ lisp 遊び

skype でローンの話になり、ローン計算スクリプトを組むことに。(何やっているんだ)

利子を 0.02% として、利子をどれぐらい払いつづけなきゃいけないか計算。

先輩の組んだ common lisp でローン計算

#!/usr/local/bin/clisp
(defun view-month (n)
  (format t "~A years ~A month  " (floor (/ n 12.0)) (+ (mod n 12) 1)))
(defun calc-total (n total pay)
  (cond ((< total pay) 0)
        (t 
           (setq risi (/ (* total 0.02) 12))
           (setq total (- total (- pay risi)))
           (view-month n)
           (format t "nokori = ~A  risi = ~A~A" total risi #\Newline)
           (calc-total (+ n 1) total pay))))
(先輩のソースをパクリ)俺が組んだ scheme でローン計算 再起関数なので set quote(元来schemeにそんなものはない) で代入を行うよりも let* を使うことにしました。
#!/usr/local/bin/gosh
(define mod modulo)
(define (view-month num)
  (format #t "~A years ~A month  " (floor (/ num 12)) (+ (mod num 12) 1)))
(define (calc-total total pay num)
  (let* ((rishi (/ (* total 0.02) 12))
        (total (- total (- pay rishi))))
    (format #t "nokori = ~A rishi = ~A~A" total rishi #\Newline)
    (cond ((< total pay) #t)
          (else 
           (view-month num)
           (calc-total total pay (+ num 1))))))

_ 今日の徒歩量

3433歩

本日のツッコミ(全2件) [ツッコミを入れる]
_ pzstuszjzu (2008-04-22 20:16)

Wow, cool man, big thanks! <a href=http://ncriaeorbdp.com >http://ncriaeorbdp.com</a>

_ bcksukrpko (2008-04-23 00:42)

<a href=http://nerkepp.info/index11.html > http://nerkepp.info/index11.html </a><br>

[]

«前の日記(2006-10-31) 最新 次の日記(2006-12-01)»