 Convert list

Recommended Posts 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.

Share on other sites 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

Share on other sites 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

Share on other sites Posted (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 by Grrr

Share on other sites 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")
(end_list)
;-----------------------------------

Share on other sites 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

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. Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.