shorting list..

caduser

Usenet Archive
Joined
Jan 1, 2000
Messages
51
Reaction score
0
'("A3" "A11" "A5" "A1") can shorting? and how the lisp look like
 
(acad_strlsort '("A3" "A11" "A5" "A1"))

("A1" "A11" "A3" "A5")

Also hit the VLIDE help file and search for "list manipulation functions" and vl-sort

HTH
Kevin
 
is it always only A's (only one prefix letter)???
never ("A1" "A2" "A3" "B1" "B2" "B3")???
if it is always A, then it's simple, but if not, it's more involved (defun alphaNumsort (strlist) (print strlist) (mapcar (function (lambda(st st2) (strcat (substr st 1 1)(itoa st2)) ) );f strlist (vl-sort (mapcar (function (lambda(s) (atoi (substr s 2)) ) ) strlist) '< )

);m
);d
(defun test
(setq testlst(list "A2" "A3" "A45" "A1" "A5" "A7" "A100" "A6" "A1000")) (alphaNumsort testlst)
)

_$ (test)

("A2" "A3" "A45" "A1" "A5" "A7" "A100" "A6" "A1000")
("A1" "A2" "A3" "A5" "A6" "A7" "A45" "A100" "A1000")

but that *won't* work if you have
;(setq testlst(list "A3" "B4" "A5" "B1" "A1"))
 
Pad with leading zeros ???
"A03" "A11" "A05" "A01"
"A003" "A011" "A005" "A001"
 
in testlsp i add same more "B34" "B2" "B12" "C12" "C4" "C2" and so on.... but the adds element is not display
 
That's why I told you it wouldn't work with those cases, you'll have to write differently if you don't only have a's. your example only had a's. Like I said, if you have more than one prefix letter this will not work, but you might be able to figure out how to get it to work with the other letters by seeing how this works hint vl-sort is the culprit cause it *sometimes* discards duplicate values so you have to sort yours a's and b's and c's separately, get it?
 

Latest threads

Back
Top