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

FR: add Clone methods for mutable aggregate types #446

Open
brandjon opened this issue Jan 6, 2023 · 3 comments
Open

FR: add Clone methods for mutable aggregate types #446

brandjon opened this issue Jan 6, 2023 · 3 comments

Comments

@brandjon
Copy link
Collaborator

brandjon commented Jan 6, 2023

For *List, *Dict, and *Set, it'd be nice to have convenience methods to shallow-copy them, so an application doesn't have to use an explicit loop or call the Slice method.

@adonovan
Copy link
Collaborator

adonovan commented Jan 6, 2023

s/shallow/deep/ ?

@brandjon
Copy link
Collaborator Author

brandjon commented Jan 6, 2023

I forgot that Java's clone is deep, not shallow, so what I'm talking about would probably be called Copy.

Naming aside, I imagine it's more convenient/straightforward to have a shallow copy operation, since that's what you end up with if you try to copy things straightforwardly in Python and Starlark code (mylist = list(other)), and it's equivalent to the Slice workaround. A deep copy operation is much more difficult to describe, particularly in the presence of application-defined types, so I don't think we can robustly support it without adding an extension point of some kind for application types.

@adonovan
Copy link
Collaborator

adonovan commented Jan 6, 2023

I see the confusion: the Copy method would create a new List/Dict/Set with the same elements. From Go's perspective, that's a deep copy of the collection data structure (not just a struct copy), but from Starlark's it's a shallow copy, since the elements are the same.

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

No branches or pull requests

2 participants