chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] destructive sort! really destructive


From: Loïc Faure-Lacroix
Subject: [Chicken-users] destructive sort! really destructive
Date: Sat, 24 May 2014 02:03:04 +0400

I’m not sure if it’s how it is supposed to work. I have a list that looks like this:

'((23 14 19) (28 9 19) (10 10 19) (16 14 18)
 (14 8 18) (25 13 18) (13 13 17) (10 7 17) 
 (27 12 17) (21 12 16) (10 6 16) (5 11 16) 
 (25 11 15) (6 5 15) (0 10 15) (3 4 14)
 (5 3 13) (23 2 12) (16 1 11) (29 0 10) 
 (15 8 9) (9 5 9) (4 7 8) (17 6 7) 
 (17 5 6) (28 3 4) (10 0 4) (7 2 3)
 (20 1 2) (11 0 1))

When calling this function on this list let say (define a …)

(sort! a (lambda (x y) (< (car x) (car y))))
Returns the sorted list and then
a is equal to:

((23 14 19) (23 2 12) (25 13 18) (25 11 15) (27 12 17) (28 9 19) (28 3 4) (29 0 10))

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… 

-- 
Loïc Faure-Lacroix
Sent with Airmail

reply via email to

[Prev in Thread] Current Thread [Next in Thread]