Next: , Previous: Tak, Up: Benchmark Sources


4.3.6 Ctak

     ;;;; A version of the TAK function that uses continuations
     (define (ctak x y z)
       (call-with-current-continuation
        (lambda (k)
          (ctak-aux k x y z))))
     
     (define (ctak-aux k x y z)
       (cond ((not (< y x)) (k z))
             (else (call-with-current-continuation
                    (ctak-aux
                     k
                     (call-with-current-continuation
                      (lambda (k) (ctak-aux k (- x 1) y z)))
                     (call-with-current-continuation
                      (lambda (k) (ctak-aux k (- y 1) z x)))
                     (call-with-current-continuation
                      (lambda (k) (ctak-aux k (- z 1) x y))))))))
     
     (define (id x) x)
     
     (define (mb-test r x y z)
       (if (zero? r)
           (ctak x y z)
           (id (mb-test (- r 1) x y z))))
     ;;; call: (ctak 18 12 6)