• This forum is the machine-generated translation of www.cad3d.it/forum1 - the Italian design community. Several terms are not translated correctly.

acad _ strlsort vs vl- sort (per ordinary le liste)

  • Thread starter Thread starter x11start
  • Start date Start date

x11start

Guest
to order lists there are 2 commands:

- the most "old" (which only orders string lists) is called acad_strlsort

- while the most recent (because introduced with all other vl-xxx commands from version 2000 or so...), it is called vl-sort.
the latter has the advantage of allowing the reordering also of the whole and real numbers and selecting the order from the minor to the major or vice versa; what with acad-strlsort, you can do it only by doing (reverse (acad-strlsort nomelista).

it seems therefore that vl-sort is definitely better than the predecessor ... however, having made a lisp in autocad and then having launched it on gstarcad.... I had a (just pleasant!) surprise:

e.g. (setq list '("3" "0" "2" "1" "0" "2"))

on autocad doing:
(acad-strlsort list)
I get:
'("0" "0" "1" "2" "2" "2" "3")

the same result I get by doing the command:
(vl-sort list <)

.... but if I use vl-sort in gstarcad the result becomes:
"("0" "1" "2" "3")

practically the command "deletes the doubles"... and the thing can create serious operating problems at the lisp!
Unfortunately, as I mentioned before, the acad-strlsort command, does not allow to reorder the numbers but only the strings, so today I will try to change my "module" lisp for the ordinations, to make sure that the n. Reals are transformed into strings, before the order... paying attention to putting them "0" in front; this because otherwise the list...

("10" "1" "8") would become ("1" "10" "8")

instead with opportuni "0" in front.. .

("10" "01" "08") becomes ("01" "08" "10")... that retransformed in whole is the right sequence.. .

last note:
There is also a command called vl-sort-i, which serves to order a list "taking" the order in which another list should be ordered.. .
Well: this command works very well on gstarcad.... in the sense that in this case you do not "eat" indexes, in case the reference list to be processed, have double values!
 
to not "lose" duplicates do so:
Code:
(setq lista '(12 3 8 5 3 3))

(mapcar)
lambda (x) (nth x lista)
(vl-sort-i lista '<)
)

(3 3 5 8 12)
_$
also works in gstarcad;)
 
thanks gp.... as soon as I can try it!

among other things I read that acad-strlsorts has the limit of 200 items in the list: it is not a big problem for most cases... But he's still keeping an eye on him.
 
actually works properly on gstarcad... thanks to the fact that it is used vl-sort-i also where before it used vl-sort.
Thank you very much!

I attach the "module" for sorting lists, revised and correct.
 

Attachments

Forum statistics

Threads
44,997
Messages
339,767
Members
4
Latest member
ibt

Members online

No members online now.
Back
Top