> I haven't looked at the documentation of sort!, but the general rule > is, if you call a function that has an exclamation mark at the end, > it does something destructive to (at least one) of its arguments.
Sure. But the general rule as far as I would *expect* is that the function has to do its well-defined job. Modifying the argument just for what needs to be done in order to fulfill the algorithm, f.e. sort inplace. But not do "other things" on the argument. And for sure not leave the argument in some inconsistent state. Hence I would call this a bug. > In this case, after the first call, you shouldn't use l anymore after > the first call. The right way to call would be > > l := sort! l Hmm, why should I need to reassign here? Maybe I should not think in terms of "call by reference"? > That, of course, you can repeat as often as you like. Ok. Thanks for the hint. > Ralf already answered that, but let me add that 'sort!' is > not considered "in place" but "destructive". See: > So, after call to 'sort!' the 'l' variable contains trash, while > the correct result is given by return value. Some operations > (typically ones working on vectors and matrices) really are > "in place". Other destroy their argument. However, normally > return value contains the result and should be used. 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 ... -- 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.
