我正在尝试 nim,并在处理序列时与奇怪的行为作斗争。
如果我运行这段代码:
var
hobbies = @["Coding", "Creating", "Sports"]
echo hobbies
hobbies.add("Nature")
echo hobbies
hobbies.del(0)
echo hobbies
我期望这个输出,因为我认为它像队列一样工作:
@["Coding", "Creating", "Sports"]
@["Coding", "Creating", "Sports", "Nature"]
@["Creating", "Sports", "Nature"]
但我明白了:
@["Coding", "Creating", "Sports"]
@["Coding", "Creating", "Sports", "Nature"]
@["Nature", "Creating", "Sports"]
通过索引删除后
.del(0)
值"Nature"
切换到索引0。
订单不应该保留吗?
版本:
Nim Compiler Version 1.6.14 [Linux: amd64]
Compiled at 2023-06-29