と、思いきや、結局letブロック内で再帰か。(ってことだよね?)
(define loop-fact (lambda (n) (let loop ((count n)(result n)) (if (= count 1) result (loop (- count 1) (* result (- count 1))))))) (loop-fact 5);;=> 120 |
;;(- count 1) => let => m (define loop-fact (lambda (n) (let loop ((count n)(result n)) (if (= count 1) result (let ((m (- count 1))) (loop m (* result m))))))) (loop-fact 5);;=> 120 |
(define loop-fact (lambda (n) (let l ((x n)(y n)) (if (= x 1) y (let ((z (- x 1))) (l z (* y z))))))) (loop-fact 5);;=> 120 |
0 件のコメント:
コメントを投稿