perl6数组赋值:指针还是副本?

lis*_*tor 3 arrays pointers clone variable-assignment perl6

在perl6中,我想将一个数组分配给另一个数组并使得结果数组成为不同的实体,但似乎既没有直接赋值也没有克隆可以做我想要的.有没有办法用一个表达式复制数组而不是编写循环例程?

To exit type 'exit' or '^D'
> my @a=<a b c d e>
[a b c d e]
> my @b = <1 2 3 4 5 6 7>
[1 2 3 4 5 6 7]
> my @c = @a
[a b c d e]
> @c[3]
d
> @c[3]=3;
3
> @c
[a b c 3 e]
> @a
[a b c d e]
> @c === @a
False
> @c == @a
True          # this is unexpected, @c and @a should be different, right?
> my @x=@a.clone
[a b c d e]
> @x[3]=3
3
> @x
[a b c 3 e]
> @x === @a
False
> @x == @a
True         # unexpected, @x and @a should be distinct things, right?
>
Run Code Online (Sandbox Code Playgroud)

非常感谢你 !!!

lisprog

Mat*_*tes 5

你不幸与@b相提并论可能帮助你搞清楚:)

==是数字比较,因此当您要求将列表作为数字进行比较时,它会选择元素的数量作为表示.Perl 5或6中的运算符强制涉及的类型.如果要测试数组的元素是否相同,请尝试eqv运算符.

比较数组的长度,以下是正确的:

@a == @c == @x == 5
Run Code Online (Sandbox Code Playgroud)

尝试:

my @a = <a b c d e>;
my @b = <1 2 3 4 5>;
@a eqv @b;
Run Code Online (Sandbox Code Playgroud)

您可能想查看这些运算符周围的一些文档.智能匹配~~运营商可能更符合您的期望==.

https://docs.perl6.org/routine/$EQUALS_SIGN$EQUALS_SIGN https://docs.perl6.org/routine/$TILDE$TILDE