Jump to content
dilan

Convert list

Recommended Posts

dilan

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 this post


Link to post
Share on other sites
kpblc

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

  • Like 1

Share this post


Link to post
Share on other sites
dilan
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 this post


Link to post
Share on other sites
Grrr
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 this post


Link to post
Share on other sites
dilan

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) 
;----------------------------------- 


 

Share this post


Link to post
Share on other sites
Lee Mac

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)

 

  • Like 1

Share this post


Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...