Author Topic: adding point to a list  (Read 3565 times)

0 Members and 1 Guest are viewing this topic.

DEVITG

  • Bull Frog
  • Posts: 479
adding point to a list
« on: May 15, 2004, 04:19:30 PM »
I'm LISP "lost in ...."

in a WHILE stament  I get diferent points each loop .
I want to join all them in a list , it shall be as point

guess
(Setq  q1  '(26.7685 18.8831 0.0))
(setq q2   '(39.8771 3.60675 0))

I want to have a list such
q3= ((26.7685 18.8831 0.0) (39.8771 3.60675 0)))

If I use
(setq q3 (append q1 q2))

I got (26.7685 18.8831 0.0 39.8771 3.60675 0)

But I want ((26.7685 18.8831 0.0)( 39.8771 3.60675 0))

 :oops:

I SOLVE IT

While doing :Try and error
 it is cons not append , do not why but it is so.
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

David Bethel

  • Swamp Rat
  • Posts: 656
adding point to a list
« Reply #1 on: May 15, 2004, 06:38:24 PM »
Try:

(setq q3 (append q1 (list q2)))


(cons) is much faster though.  If the order of the points is important.  (cons) everything together and then (reverse) the final list.

-David
R12 Dos - A2K

DEVITG

  • Bull Frog
  • Posts: 479
adding point to a list
« Reply #2 on: May 15, 2004, 07:05:58 PM »
But q2 is a list yet , how does it work
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
adding point to a list
« Reply #3 on: May 15, 2004, 07:49:34 PM »
Devitg, Dont be confused by what the list actualy is and what the intripriter displays. The intripriter will display anything that it thinks as a list wraped in Paren's.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

David Bethel

  • Swamp Rat
  • Posts: 656
adding point to a list
« Reply #4 on: May 16, 2004, 08:11:46 AM »
Yes,q2 is a list, but in your case, you want the list q2 to become an atom in another list q3.  q3 has 2 atoms q1 and q2, both of which happen to be lists.

(append existing_list ( list_of_new_atoms ))

-David
R12 Dos - A2K

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
adding point to a list
« Reply #5 on: May 16, 2004, 08:30:16 AM »
DEVITG

In this case you want to use LIST.

Code: [Select]
(setq q3 (list q1 q2))

Now if you want to add to the list q3

Code: [Select]
(setq q0 '(0.0 0.0 0.0))
(setq q3 (cons q0 q3))
((0.0 0.0 0.0) (26.7685 18.8831 0.0) (39.8771 3.60675 0))

; but not
(setq q3 (cons q3 q0))
(((26.7685 18.8831 0.0) (39.8771 3.60675 0)) 0.0 0.0 0.0)


You could do this
Code: [Select]
(setq q3 '())
nil
_$ (setq q3 (cons q1 q3))
((26.7685 18.8831 0.0))
_$ (setq q3 (cons q2 q3))
((39.8771 3.60675 0) (26.7685 18.8831 0.0))
_$ (setq q3 (cons q0 q3))
((0.0 0.0 0.0) (39.8771 3.60675 0) (26.7685 18.8831 0.0))
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

DEVITG

  • Bull Frog
  • Posts: 479
adding point to a list
« Reply #6 on: May 16, 2004, 11:01:38 AM »
Hi all , thanks for your help.  following is how I solve it , with your help , of course :D  :?


Code: [Select]
(setq invpt ())
(WHILE (< IR (+ RE 0.005))

;process to get the new x y z points
 
(setq q2 (list IRX IRY ZPT))

(setq invpt (cons q2 invpt));

  (setq x (+ x st))
);_end while  
Location @ Córdoba Argentina Using ACAD 2019  at Window 10