| 1 |
;;; CTAK -- A version of the TAK procedure that uses continuations. |
| 2 |
|
| 3 |
(library (rnrs-benchmarks ctak) |
| 4 |
(export main) |
| 5 |
(import (rnrs) (rnrs-benchmarks)) |
| 6 |
|
| 7 |
(define (ctak x y z) |
| 8 |
(call-with-current-continuation |
| 9 |
(lambda (k) (ctak-aux k x y z)))) |
| 10 |
|
| 11 |
(define (ctak-aux k x y z) |
| 12 |
(if (not (< y x)) |
| 13 |
(k z) |
| 14 |
(call-with-current-continuation |
| 15 |
(lambda (k) |
| 16 |
(ctak-aux |
| 17 |
k |
| 18 |
(call-with-current-continuation |
| 19 |
(lambda (k) (ctak-aux k (- x 1) y z))) |
| 20 |
(call-with-current-continuation |
| 21 |
(lambda (k) (ctak-aux k (- y 1) z x))) |
| 22 |
(call-with-current-continuation |
| 23 |
(lambda (k) (ctak-aux k (- z 1) x y)))))))) |
| 24 |
|
| 25 |
(define (main . args) |
| 26 |
(run-benchmark |
| 27 |
"ctak" |
| 28 |
ctak-iters |
| 29 |
(lambda (result) (equal? result 7)) |
| 30 |
(lambda (x y z) (lambda () (ctak x y z))) |
| 31 |
18 |
| 32 |
12 |
| 33 |
6))) |