【发布时间】:2019-07-21 18:50:49
【问题描述】:
这是my previous question的后续行动。
我终于可以在这里重现错误了:
my @recentList = prompt("Get recentList: e.g. 1 2 3: ").words || (2,4,6);
say "the list is: ", @recentList;
for @recentList -> $x {
say "one element is: ", $x;
say "element type is: ", $x.WHAT;
say "test (1,2,3).tail(\"2\") : ", (1,2,3).tail("2");
say ( (10.rand.Int xx 10) xx 15 ).map: { @($_.tail($x)); };
}
只要我使用默认列表,只需在提示符处按回车键而不输入任何内容,结果就可以了。但是如果我输入一个数字,它会给出这个错误:
Get recentList: e.g. 1 2 3: 2
the list is: [2]
one element is: 2
element type is: (Str)
test (1,2,3).tail("2") : (2 3)
This type cannot unbox to a native integer: P6opaque, Str
in block at intType.p6 line 9
in block <unit> at intType.p6 line 5
如果 tail("2") 有效,为什么 tail($x) 会失败?另外,在我的原始代码中,tail($x.Int) 不会纠正问题,但在这里可以解决。
【问题讨论】:
-
酷。 :) 第 1 步是让代码显示问题。第 2 步是打高尔夫球。到目前为止,我有
(1 xx 1).tail('1')。 :) -
好的,回到这个问题。
say Any.tail('0')显示()但say Any.tail('1')产生This type cannot unbox to a native integer: P6opaque, Str。这已经足够高尔夫了。接下来,一些代码探索......