The*_*vel 5 perl6 data-structures raku
对于我的项目,我需要构建一个树形结构。我正在寻找一种在树叶上生长的方法。我通过使用列表结构简化了失败的尝试:
my $root = a => (b => (c=> Nil));
my $here := $root;
while $here.value ~~ Pair {
$here := $here.value;
}
$here = d => Nil;
Run Code Online (Sandbox Code Playgroud)
这是行不通的,因为我当然不能更改Nil。无法分配一个不变的值如何进行这项工作?
谢谢,西奥·范·登·休维尔
我认为您收到的错误消息“无法分配给不可变值”是因为该值不是容器。这是我将叶节点设置为容器的示例:
my $root = a => (b => (my $ = (c => Nil)));
my $here := $root;
while $here.value ~~ Pair {
$here := $here.value;
}
$here = d => Nil;
Run Code Online (Sandbox Code Playgroud)
现在,没有错误消息了。