On Sat, May 24, 2014 at 02:03:04AM +0400, Loïc Faure-Lacroix wrote: > I guess that I understand why I get such result. Since the list is sorted > destructively, the elements within the list are changed. Except the variable > “a” is still pointing to the cons of (23 14 19) . rest. For that reason, I’m > missing some elements in my list as I’m not referencing a to the new head. I > guess it should be pointed out in the documentation that the behaviour of > “sort!” might be quite different from what someone might be expecting…
Hi there, I'm afraid this sort of indeterminate behaviour is the case for _all_ destructively updating procedures. The actual results will depend on the input list, the procedure's current implementation and other factors. The best thing to do in your case is to use the nondestructive variant, or use (set! a (sort! a ...)). Destructive variants are provided for those who need the performance, and it is generally assumed that you understand the consequences of these kinds of procedures: the idea is that they're used as if they were "functional" like their nondestructive counterparts, except you shouldn't be using old references to (shared) (sub)structures, and shouldn't rely on them actually destroying anything, either. Consider that (define sort! sort) is a perfectly acceptable implementation; destructive procedures are not _required_ to make use of any mutations at all. Adding a note to sort! isn't going to help much, because there are so many other destructively updating procedures. This is simply an aspect of the language (or culture) that you'll have to learn and live with. Cheers, Peter -- http://www.more-magic.net _______________________________________________ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users