"Jason Piercey" wrote in message news:403614ce_2@newsprd01...
> 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"
Newsgroups: autodesk.autocad.customization
References: <3E78800E.C7972757@bbsae.com>
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 '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.
"Mike Hutchinson" wrote in message news:3E78800E.C7972757@bbsae.com...
> some pointers to get me started please
> how can I sort a list of points?
>
---------------------------------------------------------------
--
AcadXTabs: MDI Document Tabs for AutoCAD
http://www.acadxtabs.com
AcadX for AutoCAD 2004 Beta 1
http://mysite.verizon.net/~vze2vjds/acadx/AcadX16.zip
>
> Quick example:
>
> (vl-sort '(1 3 2 1) '<)
>
> (1 2 3)
>
> Notice on the removal of duplicates.
>
> --
>
> -Jason
> Member of the Autodesk Discussion Forum Moderator Program
>
>
> "liftedaxis" wrote in message
> news:20139699.1077237141303.JavaMail.jive@jiveforum1.autodesk.com...
> > okay, yes, that was a brain fade.
> > i'm sorry, the example for vl-sort is perfect.
> > sorry for wasting your time in reading this. :)
> >
> > --Jeremiah
>
>