jan_ek Posted July 16, 2012 Posted July 16, 2012 Hello. As with AutoLISP obtained in this way, a sorted list.(see Annex). Quote
Lee Mac Posted July 16, 2012 Posted July 16, 2012 See this thread: http://www.theswamp.org/index.php?topic=41463 Quote
jan_ek Posted July 16, 2012 Author Posted July 16, 2012 ; ----- Error around expression ----- (VL-STRING-ELT A I) ; ; error : bad argument type ; expected at [VL-STRING-ELT] For list (attach) Function eea-str_int_sort2 ??? lista.txt Quote
irneb Posted July 17, 2012 Posted July 17, 2012 That list seems to contain symbol names instead of strings. Also you've not included the rest of the code. From that error it looks as if the I variable doesn't contain an integer. See the help on vl-string-elt. Did you use any particular defun from that other thread? Or did you change something in one? Quote
jan_ek Posted February 18, 2013 Author Posted February 18, 2013 Hello. I have the same problem (defun c:trewq ( / ) (eea-str_int_sort2 (list "DN1""DN10""DN11""DN12""DN13""DN14""DN15""DN16""DN17""DN2""DN3""DN4""DN5""DN6""DN7""DN8""DN9)t) ) (VL-STRING-ELT A I) ;bad argument type <3> ; expected <INTEGER> at [VL-STRING-ELT] but if the list looks like this: (eea-str_int_sort2 (list "DN1x""DN10""DN11""DN12""DN13""DN14""DN15""DN16""DN17""DN2""DN3""DN4""DN5""DN6""DN7""DN8""DN9")t ) it's ok. Am I doing something wrong?. Do you work in.Please Help. Quote
irneb Posted February 18, 2013 Posted February 18, 2013 Firstly your list is incorrect, it doesn't end: ..."DN9)... should be ..."DN9")... Secondly, I think you've found a problem with Evgeniy's code. If I run it on his code: Command: (eea-str_int_sort (list "DN1""DN10""DN11""DN12""DN13""DN14""DN15""DN16""DN17""DN2""DN3""DN4""DN5""DN6""DN7""DN8""DN9") t) ; error: bad argument value: string position out of range 3 But using Lee's _Filesort2 seems to work: Command: (_filesort2 (list "DN1""DN10""DN11""DN12""DN13""DN14""DN15""DN16""DN17""DN2""DN3""DN4""DN5""DN6""DN7""DN8""DN9") t) ("DN1" "DN2" "DN3" "DN4" "DN5" "DN6" "DN7" "DN8" "DN9" "DN10" "DN11" "DN12" "DN13" "DN14" "DN15" "DN16" "DN17") Quote
jan_ek Posted February 18, 2013 Author Posted February 18, 2013 First - my mistake. Second - thanks for the quick response. Quote
Lee Mac Posted February 19, 2013 Posted February 19, 2013 Here is my modified version of Evgeniy's function, it should perform successfully with your examples: ([color=BLUE]defun[/color] eea-lm-str_int_sort ( l f ) ([color=BLUE]mapcar[/color] ([color=BLUE]function[/color] ([color=BLUE]lambda[/color] ( a ) ([color=BLUE]nth[/color] a l))) ([color=BLUE]vl-sort-i[/color] ([color=BLUE]if[/color] f ([color=BLUE]mapcar[/color] '[color=BLUE]strcase[/color] l) l) ([color=BLUE]function[/color] ([color=BLUE]lambda[/color] ( a b [color=BLUE]/[/color] i ) ([color=BLUE]setq[/color] i ([color=BLUE]vl-string-mismatch[/color] a b)) ([color=BLUE]cond[/color] ( ([color=BLUE]zerop[/color] i) ([color=BLUE]if[/color] ([color=BLUE]and[/color] ([color=BLUE]<[/color] 47 ([color=BLUE]ascii[/color] a) 58) ([color=BLUE]<[/color] 47 ([color=BLUE]ascii[/color] b) 58)) ([color=BLUE]<[/color] ([color=BLUE]atoi[/color] a) ([color=BLUE]atoi[/color] b)) ([color=BLUE]<[/color] a b) ) ) ( ([color=BLUE]=[/color] i ([color=BLUE]strlen[/color] a))) ( ([color=BLUE]=[/color] i ([color=BLUE]strlen[/color] b)) [color=BLUE]nil[/color]) ( ([color=BLUE]and[/color] ([color=BLUE]<[/color] 47 ([color=BLUE]vl-string-elt[/color] a i) 58) ([color=BLUE]<[/color] 47 ([color=BLUE]vl-string-elt[/color] b i) 58) ) ([color=BLUE]<[/color] ([color=BLUE]atoi[/color] ([color=BLUE]substr[/color] a ([color=BLUE]1+[/color] i))) ([color=BLUE]atoi[/color] ([color=BLUE]substr[/color] b ([color=BLUE]1+[/color] i)))) ) ( ([color=BLUE]<[/color] 47 ([color=BLUE]vl-string-elt[/color] a ([color=BLUE]1-[/color] i)) 58) ([color=BLUE]<[/color] ([color=BLUE]atoi[/color] ([color=BLUE]substr[/color] a i)) ([color=BLUE]atoi[/color] ([color=BLUE]substr[/color] b i))) ) ( ([color=BLUE]<[/color] a b)) ) ) ) ) ) ) _$ (eea-lm-str_int_sort '("DN1" "DN10" "DN11" "DN12" "DN13" "DN14" "DN15" "DN16" "DN17" "DN2" "DN3" "DN4" "DN5" "DN6" "DN7" "DN8" "DN9") t) ("DN1" "DN2" "DN3" "DN4" "DN5" "DN6" "DN7" "DN8" "DN9" "DN10" "DN11" "DN12" "DN13" "DN14" "DN15" "DN16" "DN17") Quote
jan_ek Posted April 9, 2013 Author Posted April 9, 2013 Hi, thanks for the revised version. It works great. I have one small question.Is is difficult to adapt to the list sorting function (list ("A" "AC") ("D" "1C") ("2" "#C") ("11" "AsS")) I would like to sort the position 2 list Quote
fixo Posted April 9, 2013 Posted April 9, 2013 Something like this: (setq master (list '("A" "AC") '("D" "1C") '("2" "#C") '("11" "AsS"))) (setq match_list (mapcar '(lambda(x)(cons (cadr x)(car x))) master)) (setq unsorted (mapcar 'cadr master)) (setq sorted (eea-lm-str_int_sort unsorted nil)) (setq result nil) (foreach item sorted (setq result (cons (cons (cdr (assoc item match_list)) item) result))) (setq result (reverse result)) Quote
Lee Mac Posted April 9, 2013 Posted April 9, 2013 I have one small question.Is is difficult to adapt to the list sorting function (list ("A" "AC") ("D" "1C") ("2" "#C") ("11" "AsS")) I would like to sort the position 2 list Change: (if f (mapcar 'strcase l) l) to: (if f (mapcar 'strcase (mapcar 'cadr l)) (mapcar 'cadr l)) Quote
jan_ek Posted April 10, 2013 Author Posted April 10, 2013 (setq master (list '("A" "AC") '("D" "1C") '("2" "#C") '("11" "AsS"))) (setq match_list (mapcar '(lambda(x)(cons (cadr x)(car x))) master)) (setq unsorted (mapcar 'cadr master)) (setq sorted (eea-lm-str_int_sort unsorted nil)) (setq result nil) (foreach item sorted (setq result (cons (cons (cdr (assoc item match_list)) item) result))) (setq result (reverse result)) And if we have a list of any number of characters. And if we want to have a universal function, sorted by the selected argument (np. 3 or 6). Quote
irneb Posted April 10, 2013 Posted April 10, 2013 You'll need in extra input to specify which item to sort on, then you'll use nth instead of cadr to get the relevant item. Edit: Something like this (defun eea-lm-str_int_sort ( l f n / test) (defun test (item) (nth n item)) (mapcar (function (lambda ( a ) (nth a l))) (vl-sort-i (if f (mapcar 'strcase (mapcar 'test l)) (mapcar 'test l)) Quote
jan_ek Posted April 10, 2013 Author Posted April 10, 2013 Thanks for the help, but could you explain to me how this line" (defun test (item) (nth n item)) How retrieves item? Quote
BlackBox Posted April 10, 2013 Posted April 10, 2013 More on NTH, and DEFUN functions... Be sure to note the 'Return values'. Quote
irneb Posted April 10, 2013 Posted April 10, 2013 It is called through the mapcar's. I made it into a true defun since I use it twice, else it could have been a lambda instead - but in this case I'd have made 2 lambda's exactly the same, so one defun is less coding (and probably slightly more efficient). The mapcar takes the list(s) and sends each item in the list in turn to the test function, that is where it's input argument comes from. In this case I called it item, it's arbirary what you call it - lisp doesn't care, you could've called it this-strange-thing-which-is-passed-to-here-which-I-need-to-do-something-to, or anything your heart desires. I just used item, since it's rather close to what it truly is. Perhaps I could've called it subList instead, might have been more descriptive. Quote
jan_ek Posted June 9, 2014 Author Posted June 9, 2014 Hello I have another problem. In attachment Test lisp. The problem arises when the above position 11. What am I doing wrong? stest.lsp Quote
Bhull1985 Posted June 9, 2014 Posted June 9, 2014 Thanks for this great sorting routine, it's working well for me! Quote
jan_ek Posted June 9, 2014 Author Posted June 9, 2014 Right. At autcad works.Unfortunately, in Bricscad gives the result as an attachment.I have no idea what is wrong Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.