| 1 |
(* TAKL -- The TAKeuchi function using lists as counters. *) |
| 2 |
|
| 3 |
fun list_n n = |
| 4 |
let fun loop (n, a) = |
| 5 |
if n = 0 |
| 6 |
then a |
| 7 |
else loop (n-1, n::a) |
| 8 |
in loop (n, []) |
| 9 |
end |
| 10 |
|
| 11 |
val l18 = list_n 18 |
| 12 |
val l12 = list_n 12 |
| 13 |
val l6 = list_n 6 |
| 14 |
|
| 15 |
(* Part of the fun of this benchmark is seeing how well the compiler |
| 16 |
can understand this ridiculous code, which dates back to the original |
| 17 |
Common Lisp. So it probably isn't a good idea to improve upon it. *) |
| 18 |
|
| 19 |
fun shorterp (x, y) = |
| 20 |
not (y = []) |
| 21 |
andalso (x = [] orelse shorterp (tl x, tl y)) |
| 22 |
|
| 23 |
fun mas (x, y, z) = |
| 24 |
if not (shorterp (y, x)) |
| 25 |
then z |
| 26 |
else mas (mas (tl x, y, z), |
| 27 |
mas (tl y, z, x), |
| 28 |
mas (tl z, x, y)) |
| 29 |
|
| 30 |
fun takl_benchmark (n) = |
| 31 |
run_benchmark ("takl", n, fn () => mas (l18, l12, l6), |
| 32 |
fn (x) => length(x) = 7) |
| 33 |
|
| 34 |
fun main () = takl_benchmark (takl_iters) |