Author Topic: Which is better way?  (Read 1897 times)

0 Members and 1 Guest are viewing this topic.

HasanCAD

  • Swamp Rat
  • Posts: 1421
Which is better way?
« on: May 09, 2011, 10:25:43 AM »
This method
Code: [Select]
(list
  (+ (nth 0 (cadr pt1)) (nth 0 (cdr (cadr pt2))))
  (+ (nth 1 (cadr pt1)) (nth 1 (cdr (cadr pt2))))
  (+ (nth 2 (cadr pt1)) (nth 2 (cdr (cadr pt2))))
  )
Or
Code: [Select]
(setq x1 (nth 0 (cadr pt1)))
(setq y1 (nth 1 (cadr pt1)))
(setq z1 (nth 2 (cadr pt1)))

(setq x2 (nth 0 (cadr pt2)))
(setq y2 (nth 1 (cadr pt2)))
(setq z2 (nth 2 (cadr pt2)))

(list
  (+ x1 x2)
  (+ y1 y2)
  (+ z3 z3)
  )

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Which is better way?
« Reply #1 on: May 09, 2011, 10:32:05 AM »
Code: [Select]
(mapcar '+ pt1 pt2)
As far as your two go, if it's not needed to defined a variable, then I wouldn't, but it doesn't really hurt anything...as long as you ARE localizing your variables.  :wink:
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Which is better way?
« Reply #2 on: May 09, 2011, 10:58:45 AM »
What are the forms of pt1 and pt2?  Your two examples seem to contradict each other.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Which is better way?
« Reply #3 on: May 09, 2011, 11:27:01 AM »
Yes, please give an example with numbers and not variables so we can see what you are trying to do. :-)
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.

HasanCAD

  • Swamp Rat
  • Posts: 1421
Re: Which is better way?
« Reply #4 on: May 09, 2011, 12:10:36 PM »

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Which is better way?
« Reply #5 on: May 09, 2011, 12:33:18 PM »
As Alanjt said:

Code: [Select]
(cons 10 (mapcar '+ pt (cdr (assoc 10 ent))))
Speaking English as a French Frog