Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

methods for modifying dynamic arrays #2611

Open
charles-cooper opened this issue Jan 21, 2022 · 6 comments
Open

methods for modifying dynamic arrays #2611

charles-cooper opened this issue Jan 21, 2022 · 6 comments
Assignees
Milestone

Comments

@charles-cooper
Copy link
Member

charles-cooper commented Jan 21, 2022

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
@haltman-at
Copy link

I would like to also suggest a clear method (or whatever you think it should be called).

@charles-cooper
Copy link
Member Author

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?

@haltman-at
Copy link

Ah, sorry. I mean a method that would remove all elements from the given array, resetting its length to 0.

@haltman-at
Copy link

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!

@charles-cooper
Copy link
Member Author

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

@haltman-at
Copy link

Oh, sorry, I had no idea all that was legal! Disregard my request, then. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants