Skip to content

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

Open
khchen wants to merge 2 commits into
ThakeeNathees:masterfrom
khchen:list_map_ctor
Open

[Design] add copy constructor of List and Map (BREAKING)#272
khchen wants to merge 2 commits into
ThakeeNathees:masterfrom
khchen:list_map_ctor

Conversation

@khchen

@khchen khchen commented Jul 8, 2022

Copy link
Copy Markdown
  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