OSDN Git Service

add rec example
authorMIZUNO Hiroki <mzpppp@gmail.com>
Sat, 21 Jun 2008 04:47:24 +0000 (13:47 +0900)
committerMIZUNO Hiroki <mzpppp@gmail.com>
Sat, 21 Jun 2008 04:47:24 +0000 (13:47 +0900)
example/rec.scm

index b085943..d35c55f 100644 (file)
@@ -1,6 +1,7 @@
 ;; expected output
 ;;;  not rec
 ;;;  rec
+;;;  3628800
 (let ([f (lambda (n) (print "not rec"))])
   (let ([f (lambda (n) (if (= n 0)
                           (print "rec")
   (letrec ([f (lambda (n) (if (= n 0)
                           (print "rec")
                           (f 0)))])
-    (f 1)))
\ No newline at end of file
+    (f 1)))
+
+(letrec ([fact (lambda (n) 
+                (if (<= n 1)
+                    1
+                    (* n (fact (- n 1)))))])
+  (print (fact 10)))
\ No newline at end of file