put them in another list
(setq allx (mapcar 'car (list p1 p2 p3))) >>>> all values of x
(setq ally (mapcar 'cadr (list p1 p2 p3))) >>>> all values of y
then play in just 2 lists (allx and ally)
Registered forum members do not see this ad.
Hello, it's me again.
Here is the question
(defun c:sve ()
(setq p1 (list 0 21))
(setq p2 (list 1082 39))
(setq p3 (list 2298 60))
;
;
(setq p1_x (car p1))
(setq p1_y (cadr p1))
;
(setq p2_x (car p2))
(setq p2_y (cadr p2))
;
(setq p3_x (car p3))
(setq p3_y (cadr p3))
;and so on...
)
Now, is it possible for lisp to set p1_x to the value
of (car p1) automaticly (?!) so I don't have to write
all the text manually?
Thank you for reading my question,
greetings!
put them in another list
(setq allx (mapcar 'car (list p1 p2 p3))) >>>> all values of x
(setq ally (mapcar 'cadr (list p1 p2 p3))) >>>> all values of y
then play in just 2 lists (allx and ally)
You can use something like this. It ceates as many variables as needed.
But there is seldom a need for the code I posted. I would do it like wizman did.Code:(defun c:sve () (setq pointlist '( (0 21) (1082 39) (2298 60) ) ) (setq idx 1) (foreach pt pointList (set (read (strcat "p" (itoa idx) "_x")) (car pt)) (set (read (strcat "p" (itoa idx) "_y")) (cadr pt)) (setq idx (1+ idx)) ) (princ) )
Registered forum members do not see this ad.
Thank you
And now I have two more commands
to learn, mapcar&foreach.
I dont have my
own internet connection and i cant
come here very often. That sucks,
this is a very nice place to be.
Greetings to everyone!
Bookmarks