On 05/03/2017 04:08 AM, oldk1331 wrote: > The construct is wrong: > > + construct l == ref l > > That causes shared structure, and 'ref copy l' will not work either. > This problem is coupled with the other thread "copy of AssociationList". > > Namely, we should implement 'deep copy' of List of Record and > use that in 'construct' and 'copy': > > deepcopy(x : List Record(...)) : List Record(...) == > y := empty() > while not empty? x repeat > y := concat(copy first x, y) > x := rest x > reverse! y > > construct l == ref deepcopy l > copy l == ref deepcopy deref l > > BTW, I think we can use List Record instead of Reference List Record > as Rep.
As I said in the other thread, we should first make some convention explicit and write it into a "programming guideline" document. Aside, of course, you know that one cannot have such a deepcopy function if the "..." is not explicitly known. Again, I think deepcopy is not needed. As the semantics for deepcopy I would like to have: "no part of the original shares memory with any part of the copy". This could even leaad to problems if the user is not careful. Suppose I have R ==> Record(x: Integer) r: R := [0] l: List R := [r, r] l2 := deepcopy l (first r).x := 1 (first r2).x := 2 should result in l = [[1], [1]] and l2 = [[2], [0]]. Maybe that might confuse some people. OK, users should anyway be very careful with destructive functions, so that issue is not a big argument. Ralf -- You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/fricas-devel. For more options, visit https://groups.google.com/d/optout.
