【发布时间】:2017-04-14 03:03:20
【问题描述】:
在 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?
>
非常感谢!!!
lisprog
【问题讨论】:
标签: arrays pointers clone variable-assignment raku