Jason Piercey said:
Becareful with vl-sort. There have been many
discussions here in this group on how dangerous
this function can be.
Here's one:
---------------------------------------------------------------------
From: "Tony Tanzillo" <tony.tanzillo at caddzone dot com>
Newsgroups: autodesk.autocad.customization
References: <
[email protected]>
Subject: Re: How can I sort a list of 3d points?
Date: Wed, 19 Mar 2003 10:37:20 -0500
Lines: 48
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
You can use vl-sort, with a comparison function that
weights the ordinates in whatever way you want.
Here's an example that gives the greatest weight
to the X ordinate, and the least weight to the Z
ordinate:
(setq fuzz 1.0e-6) ;; comparison precision
;; sort on three keys (x, y, and z)
(defun compare-points (a b)
(if (equal (car a) (car b) fuzz)
(if (equal (cadr a) (cadr b) fuzz)
(> (caddr a) (caddr b))
(> (cadr a) (cadr b))
)
(> (car a) (car b))
)
)
(vl-sort <list-of-points> 'compare-points)
If you search this newsgroup, you'll find a much
more powerful sorting function along with a good
discussion on why (vl-sort) can be very dangerous.
For that reason, I suggest you replace the built-in
vl-sort with this:
(defun vl-sort (lst func)
(mapcar
'(lambda (x) (nth x lst))
(vl-sort-i lst func)
)
)
This will ensure that (vl-sort) does not remove
elements that it sees as equal.