Debian Codegraph @

benchmarks/rnrs-benchmarks/fibc.ss

raw
1 ;;; FIBC -- FIB using first-class continuations, written by Kent Dybvig
2
3 (library (rnrs-benchmarks fibc)
4 (export main)
5 (import (rnrs) (rnrs-benchmarks))
6
7 (define (_1+ n) (+ n 1))
8 (define (_1- n) (- n 1))
9
10 ;;; fib with peano arithmetic (using numbers) with call/cc
11
12 (define (addc x y k)
13 (if (zero? y)
14 (k x)
15 (addc (_1+ x) (_1- y) k)))
16
17 (define (fibc x c)
18 (if (zero? x)
19 (c 0)
20 (if (zero? (_1- x))
21 (c 1)
22 (addc (call-with-current-continuation (lambda (c) (fibc (_1- x) c)))
23 (call-with-current-continuation (lambda (c) (fibc (_1- (_1- x)) c)))
24 c))))
25
26 (define (main)
27 (run-benchmark
28 "fibc"
29 fibc-iters
30 (lambda (result) (equal? result 2584))
31 (lambda (x c) (lambda () (fibc x c)))
32 18
33 (lambda (n) n))))