vyper
vyper copied to clipboard
methods for modifying dynamic arrays
current master only has assignment between dynamic arrays, but people will expect to be able to modify arrays. we should implement modifier methods. to be familiar for python users:
method | behavior |
---|---|
.append() |
add an element to an array. (analogous to solidity push() , but it changes the runtime length of the array) |
.pop() |
pop the last element of an array. (analogous to solidity pop() but it changes the runtime length of the array |
(?).extend() |
(tent.) concat two arrays |
(?).pop(ix=?) |
(tent.) delete an element from the middle of an array |
I would like to also suggest a clear
method (or whatever you think it should be called).
I would like to also suggest a
clear
method (or whatever you think it should be called).
What would the semantics of this method be?
Ah, sorry. I mean a method that would remove all elements from the given array, resetting its length to 0.
Sorry, I guess it would be presumably be named whatever the analogous thing is in Python; I just suggested the first name that came to mind, I didn't think about what the naming convention here is!
You can set the length of a dynamic array to zero by either using an empty list literal or using the special empty function
my_array: DynArray[uint256, 7] = [ 1,2,3]
my_array.pop()
my_array = [] # set length to zero
my_array = empty(DynArray[uint256,7]) # same thing
Oh, sorry, I had no idea all that was legal! Disregard my request, then. Thanks!