我尝试了Rosettacode上的一些示例,并在提供的Ackermann示例中遇到了问题:当“未修改”运行时(我用拉丁字母替换了utf-8变量名),我得到了以下结果(类似但现在可以复制):
$ perl6 t/ackermann.p6
65533
19729 digits starting with 20035299304068464649790723515602557504478254755697...
Cannot unbox 65536 bit wide bigint into native integer
in sub A at t/ackermann.p6 line 3
in sub A at t/ackermann.p6 line 11
in sub A at t/ackermann.p6 line 3
in block <unit> at t/ackermann.p6 line 17
在第三行中注释掉proto声明:
$ perl6 t/ackermann.p6
65533
19729 digits starting with 20035299304068464649790723515602557504478254755697...
Numeric overflow
in sub A at t/ackermann.p6 line 8
in sub A at t/ackermann.p6 line 11
in block <unit> at t/ackermann.p6 line 17
什么出了问题?程序没有分配很多内存。自然整数是否受到限制?
我从 Ackermann函数的代码中替换了 为 m,替换了 为 n,以更好地进行终端交互以防止复制错误,并尝试注释掉proto声明。我还向Liz提出了问题;)
use v6;
proto A(Int \m, Int \n) { (state @)[m][n] //= {*} }
multi A(0, Int \n) { n + 1 }
multi A(1, Int \n) { n + 2 }
multi A(2, Int \n) { 3 + 2 * n }
multi A(3, Int \n) { 5 + 8 * (2 ** n - 1) }
multi A(Int \m, 0 ) { A(m - 1, 1) }
multi A(Int \m, Int \n) { A(m - 1, A(m, n - 1)) }
# Testing:
say A(4,1);
say .chars, " digits starting with ", .substr(0,50), "..." given A(4,2);
A(4, 3).say;
.ask timotimo Have you got any suggestions for P6 code that would stress cpu and memory in interesting ways?
或类似的内容。 - raiph