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

[Design] add copy constructor of List and Map (BREAKING) #272

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

khchen
Copy link

@khchen khchen commented Jul 8, 2022

  1. List/map constructor can accept a list/map, works as copy constructor.
  2. The original list constructor is abandoned, it do the same thing as list literal .
  3. List constructor can accept a integer, returns a preallocated list (filling in null).
  4. List join (+ operator) should always returned a new list, instead the old one.

Example:

l1 = [1, 2, 3]
l2 = l1
l3 = List(l1)
l1[0] = 4
print(l1); print(l2); print(l3)

m1 = {1: 1, 2: 2, 3: 3}
m2 = m1
m3 = Map(m1)
m1[1] = 4
print(m1); print(m2); print(m3)

print(List(3))

Output:

[4, 2, 3]
[4, 2, 3]
[1, 2, 3]
{2:2, 1:4, 3:3}
{2:2, 1:4, 3:3}
{2:2, 1:1, 3:3}
[null, null, null]

@khchen khchen changed the title Add copy constructor of List and Map (BREAKING). [Design] add copy constructor of List and Map (BREAKING) Jul 18, 2022
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

Successfully merging this pull request may close these issues.

1 participant