dilan Posted July 10, 2019 Posted July 10, 2019 Hello. I have a list: (("n1" 74678.6 53741.6 0.0) ("n2" 74683.8 53741.6 0.0) ("n3" 74683.8 53747.6 0.0) ("n4" 74677.6 53747.6 0.0)) I can not convert it to this kind: (n1 74678.6 53741.6 0.0) (n2 74683.8 53741.6 0.0) (n3 74683.8 53747.6 0.0) (n4 74677.6 53747.6 0.0) Please tell me how it can be done. Thank. Quote
kpblc Posted July 10, 2019 Posted July 10, 2019 Start list is one variable. Final list is 4 variables. I think it's impossible to convert quite right you want. (setq lst '(("n1" 74678.6 53741.6 0.0) ("n2" 74683.8 53741.6 0.0) ("n3" 74683.8 53747.6 0.0) ("n4" 74677.6 53747.6 0.0))) (mapcar (function (lambda(x)(cons (read (car x)) (cdr x)))) lst)) ;; returns : '((N1 74678.6 53741.6 0.0) (N2 74683.8 53741.6 0.0) (N3 74683.8 53747.6 0.0) (N4 74677.6 53747.6 0.0)) ;; using nth, foreach, mapcar etc you can get access to any element of list 1 Quote
dilan Posted July 10, 2019 Author Posted July 10, 2019 48 minutes ago, kpblc said: Start list is one variable. Final list is 4 variables. I think it's impossible to convert quite right you want. (setq lst '(("n1" 74678.6 53741.6 0.0) ("n2" 74683.8 53741.6 0.0) ("n3" 74683.8 53747.6 0.0) ("n4" 74677.6 53747.6 0.0))) (mapcar (function (lambda(x)(cons (read (car x)) (cdr x)))) lst)) ;; returns : '((N1 74678.6 53741.6 0.0) (N2 74683.8 53741.6 0.0) (N3 74683.8 53747.6 0.0) (N4 74677.6 53747.6 0.0)) ;; using nth, foreach, mapcar etc you can get access to any element of list Thank you very match....That's what I need Quote
Grrr Posted July 10, 2019 Posted July 10, 2019 (edited) Assuming that the list is consistent - (setq L '(("n1" 74678.6 53741.6 0.0) ("n2" 74683.8 53741.6 0.0) ("n3" 74683.8 53747.6 0.0) ("n4" 74677.6 53747.6 0.0))) ( '((L) (apply 'mapcar (cons 'list (cons (mapcar 'read (car L)) (cdr L) ) ) ) ) (apply 'mapcar (cons 'list L)) ) Edited July 10, 2019 by Grrr Quote
dilan Posted July 10, 2019 Author Posted July 10, 2019 I wanted to put this list in list_box DCL, I did it like this ... ;+++++++++++++ (defun List_for_Box ( list_ / qwer ) (foreach item list_ (setq qwer (strcat "\n" " " (car item) " " (rtos (nth 1 item)) " " (rtos (nth 2 item)) " " (rtos (nth 3 item)) ) ptlist_DCL (cons qwer ptlist_DCL) ) ); end of foreach ptlist_DCL ); end of defun ;+++++++++++++ (setq ptlist_DCL (List_for_Box (("n1" 74678.6 53741.6 0.0) ("n2" 74683.8 53741.6 0.0) ("n3" 74683.8 53747.6 0.0) ("n4" 74677.6 53747.6 0.0))) show_coord (reverse ptlist_DCL) ) ;----------------------------------- (start_list "Coord") (mapcar 'add_list show_coord) (end_list) ;----------------------------------- Quote
Lee Mac Posted July 10, 2019 Posted July 10, 2019 For what it's worth, you needn't iterate over the list repeatedly - you can construct the string whilst adding items to the list box, e.g.: (setq lst '(("n1" 74678.6 53741.6 0.0) ("n2" 74683.8 53741.6 0.0) ("n3" 74683.8 53747.6 0.0) ("n4" 74677.6 53747.6 0.0))) (start_list "Coord") (foreach itm lst (add_list (apply 'strcat (cons (car lst) (mapcar '(lambda ( x ) (strcat " " (rtos x))) (cdr lst))))) ) (end_list) 1 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.