summaryrefslogtreecommitdiffstats
path: root/examples/fact.scm
blob: af56eb78ba1ac3a9700370fa11282af54c3edbbd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
(define (fact n)
  (if (= n 0)
      1
      (* n (fact (- n 1)))))

(define (fact/cps n cont)
  (if (= n 0)
      (cont 1)
      (fact/cps (- n 1) (lambda (a) (cont (* n a))))))

(define num 11)

(display (string-append "fact: " (number->string (fact num))))
(display (string-append "fact/cps: " (number->string (fact/cps num (lambda (x) x)))))

 (define return #f) 
  
(display (+ 1 (call/cc 
        (lambda (cont) 
          (set! return cont) 
          1))))
(display (return 23))