> Ok, now I see. In my interpretation the "!" had "in-place" > rather than "destructive" semantics. By this definition its > all my fault and not a bug. > > However, I think that this confusion is a little bit natural > as said above. So maybe we should try to shift from "destructive" > to "in-place" where this is appropriate and can be done easily? > > That would in any case reduce such pitfalls ...
Let's look at lists. A list is represented by a pointer to the first element. Each (list) element is represented by a record of two things (a) the actual value (or a pointer to the actual value) and (b) a pointer to the next element (or NIL if it's the last element). So we have something like L --> (v1, p1) p1 --> (v2, p2) p2 --> (v3, NIL) Now suppose the elements are reordered, for example, move the first element to the end of the list. The result is represented by the pointer R. Then we get. R --> (v2, p2) p2 --> (v3, p3) p3 --> (v1, NIL) L --> (v1, NIL) Note that the pointer L still points to the record that contains v1. If you want anything else, you would have to shift the entries inside the records so that in the end you would get (*) L --> (v2, p1) p1 --> (v3, p2) p2 --> (v1, NIL) That would be really "in-place", but it's not the way that list operations are currently implemented in FriCAS. The problem with this is that it might have quite a lot of side effects. Suppose you do l := [1,2,3] r := rest l rotate! l -- where rotate! would be programmed like (*) then you would have l = [2,3,1] and r = [3,1]. And of course the side effects may occur in very distant places. The exclamation mark in FriCAS should remind you that you shouldn't use that function unless you make sure that the side effects this functions has are not too bad for other parts of your code. For example, using sort!(x) on a list x that you have just generated is usually safe since this list isn't reference elsewhere. Ralf -- You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/fricas-devel?hl=en.
