ikarus/benchmarks/new/r6rs-benchmarks/cpstak.ss

38 lines
945 B
Scheme

;;; CPSTAK -- A continuation-passing version of the TAK benchmark.
;;; A good test of first class procedures and tail recursion.
(library (r6rs-benchmarks cpstak)
(export main)
(import (r6rs) (r6rs-benchmarks))
(define (cpstak x y z)
(define (tak x y z k)
(if (not (< y x))
(k z)
(tak (- x 1)
y
z
(lambda (v1)
(tak (- y 1)
z
x
(lambda (v2)
(tak (- z 1)
x
y
(lambda (v3)
(tak v1 v2 v3 k)))))))))
(tak x y z (lambda (a) a)))
(define (main . args)
(run-benchmark
"cpstak"
cpstak-iters
(lambda (result) (equal? result 7))
(lambda (x y z) (lambda () (cpstak x y z)))
18
12
6)))