Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear a sequence in Nim

Tags:

seq

nim-lang

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?

like image 351
Arrrrrrr Avatar asked Jun 30 '15 10:06

Arrrrrrr


1 Answers

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.

like image 109
def- Avatar answered Nov 02 '22 11:11

def-