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

Basic Introduction Question 1: bad example of shallow vs deep copy #42

Open
dmaniry opened this issue Jan 9, 2019 · 1 comment
Open

Comments

@dmaniry
Copy link

dmaniry commented Jan 9, 2019

Question 1 threw me off when it introduced the concept of shallow vs deep copy, because the example would actually work with a shallow copy. It doesn't work with a plain assignment and then introduces deepcopy as a fix even though copy (which was introduced before) would have the same effect. The example should be reworked to actually require deepcopy or make a clearer distinction of the three options. Also there is a minor issue with the cell execution order being confusing, because you have to go 2 cells back to reinitialize a to see the fix working.

@dmaniry dmaniry changed the title Basic Introduction Question 1: shallow vs deep copy Basic Introduction Question 1: bad example of shallow vs deep copy Jan 9, 2019
@ChrisRackauckas
Copy link
Member

Yeah, the example should be more like:

a = Vector{Vector{Float64}}(undef,3)
a[1] = [1;2;3]
a[2] = [1;2]
a[3] = [3;4;5]
a

b = copy(a)
b[1][1] = 6
a

c = deepcopy(a)
c[1][1] = 10
a

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