Closed thacuber2a03 closed 4 months ago
@thacuber2a03 Here is what the language specification says about append
:
... If
len(a) + len(x) <= cap(a)
, it [the dynamic array] is altered and returned. Otherwise, a new dynamic array is constructed and returned.
Thus, the normal way to use append
is:
a = append(a, x)
If you lose the returned value and don't check cap(a)
, you'll never know what happens to the argument a
.
If you want to save the result to a dynamic array other than a
and keep a
intact regardless of cap(a)
, you can use copy
:
b = append(copy(a), x)
oh, I forgot about that, dang it
although, now that this issue is here, @vtereshkov why did you choose that form and not append(&array, value)
?
on an empty dynamic array, it seems to only append the first two elements and stop therebug seems consistent on both master and stablewasn't a bug, I just didn't notice that