On 06/28/2016 04:07 AM, oldk1331 wrote: > In Stack if bags.spad: > Rep := Reference List S > parts s == deref s > > That's shared structure, not copy, thus > > (11) -> x := stack [1,2,3,4] > > (11) [1,2,3,4] > Type: Stack(PositiveInteger) > (12) -> y := parts x > > (12) [1,2,3,4] > Type: List(PositiveInteger) > (13) -> y.1 := 5 > > (13) 5 > Type: PositiveInteger > (14) -> x > > (14) [5,2,3,4] > Type: Stack(PositiveInteger) > > > I think this is wrong. We should mention that parts do not share > structure with its argument in the doc (in aggcat.spad).
The documentation says: http://fricas.github.io/api/HomogeneousAggregate.html#l-homogeneous-aggregate-parts parts: % -> List S if % has finiteAggregate parts(u) returns a list of the consecutive elements of u. For collections, parts([x, y, ..., z]) = (x, y, ..., z). Do I understand correctly that you mean that in (14) x should still show [1,2,3,4]? Actually, I would have expected [5,2,3,4] and in fact, if you had called z := foo!(y) for an arbitrary "bang" function that modifies its first argument, I would even have expected that I cannot use the value of x anymore, because the internal datastructure might have been modified so badly that it becomes invalid as an element of the respective domain. setelt!(y, 1, 5) is special and behaves (on purpose) nicely to the datastructure so that at least access to x afterwards does not lead to a crash of the program. But still it might lead to an element that is no longer in the respective domain. But otherwise, it is exactly as I said before, using "destructive" operations is dangerous, since it's usually unknown if arguments (hier in the creation with the "stack" constructor) are copied or not. If you rather mean that "parts" should be specified to return a copy of the internal datastructure, I think that would in general be too much copying. That is why there is a "copy" function. > There's a "buggy?" comment in parts$Tree, but I think the > implementation is correct. What exactly do you mean? The specification is coming form HomogeneousAggregate (as above). Tree is no Collection(X), so the second sentence does not apply. -- 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.
