Clear a sequence in Nim
Asked Answered
S

1

8

What is the Nim equivalence of List.Clear in languages like java or c# for sequences? I see listed in system the proc setLen, but im not sure it does what i want. From the description:

f the current length is greater than the new length, s will be truncated. s

Does it mean everytime i set any seq len to 0 it will create a new instance of seq?

Scraggly answered 30/6, 2015 at 10:48 Comment(0)
L
12

setLen resizes the seq without allocating a new one, so usually x.setLen(0) is fine. If you want to allocate a new seq and let the garbage collector clean up the old one, you can do x = @[] instead.

Lipography answered 30/6, 2015 at 11:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.