Debian Codegraph @

benchmarks.larceny/src/ntakl.scm

raw
1 ;;; NTAKL -- The TAKeuchi function using lists as counters,
2 ;;; with an alternative boolean expression.
3
4 (define (listn n)
5 (if (= n 0)
6 '()
7 (cons n (listn (- n 1)))))
8
9 (define l18 (listn 18))
10 (define l12 (listn 12))
11 (define l6 (listn 6))
12
13 (define (mas x y z)
14 (if (not (shorterp y x))
15 z
16 (mas (mas (cdr x) y z)
17 (mas (cdr y) z x)
18 (mas (cdr z) x y))))
19
20 ; Part of the fun of this benchmark is seeing how well the compiler
21 ; can understand this ridiculous code, which dates back to the original
22 ; Common Lisp. So it probably isn't a good idea to improve upon it.
23
24 '
25 (define (shorterp x y)
26 (and (not (null? y))
27 (or (null? x)
28 (shorterp (cdr x)
29 (cdr y)))))
30
31 ; But SML/NJ runs this benchmark about 15 times as fast when the
32 ; code above is rewritten as follows, so I tried it for Scheme also.
33
34 (define (shorterp x y)
35 (cond ((null? y) #f)
36 ((null? x) #t)
37 (else
38 (shorterp (cdr x) (cdr y)))))
39
40 (define (main . args)
41 (run-benchmark
42 "ntakl"
43 takl-iters
44 (lambda (result) (equal? result '(7 6 5 4 3 2 1)))
45 (lambda () (lambda () (mas l18 l12 l6)))))