...I have never understood the concept of mapcar, lambda and apply clearly. ...Me too, but don't say it to others ...
Is there any situation where the logic cannot be achieved by foreach, repeat. while etc but can be achieved by mapcar, apply etc.
So what is the benefit of lambda ?
(setq pt1 '(1.0 1.0 0.0))
(setq pt2 '(2.0 2.0 0.0))
(defun addelev ( pt / x y z newz newpt)
(setq x (car pt))
(setq y (cadr pt))
(setq z (caddr pt))
(if pt
(setq newz (+ 12.0 z))
(princ "\nNot a point coordinate")
);if
(setq newpt (list x y newz))
(princ newpt)
)
(setq pt1 '(1.0 2.0 0.0))
(setq pt2 '(2.0 3.5 0.0))
(setq pt3 '(5.0 10.0 0.0))
(setq pt4 '(6.0 7.5 0.0))
(setq lst (list pt1 pt2 pt3 pt4))
(mapcar
'(lambda ( pt )
(list (car pt) (cadr pt) (+ (caddr pt) 12.))
)
lst
)
(mapcar '(lambda (pt)(mapcar '+ pt (list 0 0 12))) lst)
(setq pt1 '(1.0 2.0 0.0))
(1.0 2.0 0.0)
Command: (setq pt2 '(2.0 3.5 0.0))
(2.0 3.5 0.0)
Command: (setq pt3 '(5.0 10.0 0.0))
(5.0 10.0 0.0)
Command: (setq pt4 '(6.0 7.5 0.0))
(6.0 7.5 0.0)
Command: (setq lst (list pt1 pt2 pt3 pt4))
((1.0 2.0 0.0) (2.0 3.5 0.0) (5.0 10.0 0.0) (6.0 7.5 0.0))
Command: (mapcar '(lambda (pt)(mapcar '+ pt (list 0 0 12))) lst)
((1.0 2.0 12.0) (2.0 3.5 12.0) (5.0 10.0 12.0) (6.0 7.5 12.0))
Command: (setq pt1 '(1.0 2.0 0.0))
(1.0 2.0 0.0)
Command: (setq pt2 '(2.0 3.5 0.0))
(2.0 3.5 0.0)
Command: (setq pt3 '(5.0 10.0 0.0))
(5.0 10.0 0.0)
Command: (setq pt4 '(6.0 7.5 0.0))
(6.0 7.5 0.0)
Command: (setq lst (list pt1 pt2 pt3 pt4))
((1.0 2.0 0.0) (2.0 3.5 0.0) (5.0 10.0 0.0) (6.0 7.5 0.0))
Command: (mapcar
(_> '(lambda ( pt )
('(_> (list (car pt) (cadr pt) (+ (caddr pt) 12.))
('(_> )
(_> lst
(_> )
((1.0 2.0 12.0) (2.0 3.5 12.0) (5.0 10.0 12.0) (6.0 7.5 12.0))
Not sure I understand the difference.
I can't follow the logic in yours..nevertheless; it appears to work as well.
(mapcar '(lambda (pt)(mapcar '+ pt (list 0 0 12))) lst)
and
(mapcar
'(lambda ( pt )
(list (car pt) (cadr pt) (+ (caddr pt) 12.))
)
lst
)
(mapcar
(_> '(lambda ( pt )
('(_> (list (car pt) (cadr pt) (+ (caddr pt) 12.))
('(_> )
(_> lst
(_> )
((1.0 2.0 12.0) (2.0 3.5 12.0) (5.0 10.0 12.0) (6.0 7.5 12.0))
I'll be looking into this more, surely there's a reason for knowing this other way
(defun c:dff ()
(setq lst nil)
(setq a (list 100.4 340.24 452.24))
(repeat 10000 (setq lst (append lst (list a))))
(setq Start (getvar "Millisecs"))
(setq b (mapcar '(lambda (pt) (mapcar '+ pt (list 0.0 0.0 12.0))) lst))
(setq End (getvar "Millisecs"))
(setq yu (- End Start))
(princ "\nTime Taken to Run Method 1 (two mapcar) : ")
(princ yu)
(princ " milliseconds \n")
(setq Start (getvar "Millisecs"))
(setq c
(mapcar '(lambda (pt) (list (car pt) (cadr pt) (+ (caddr pt) 12.0)))
lst
)
)
(setq End (getvar "Millisecs"))
(setq yu (- End Start))
(princ "\nTime Taken to Run Method 2 (single mapcar) : ")
(princ yu)
(princ " milliseconds \n")
(princ)
)
(setq a (list 100.4 340.24 452.24))
(repeat 20000 (setq lst (append lst (list a))))
(defun test1 ()
(mapcar'(lambda (pt)(reverse (cons (+ (last pt) 12)(cdr (reverse pt)))))lst)
)
(defun test2 ()
(mapcar '(lambda (pt)(mapcar '+ pt (list 0 0 12))) lst)
)
(defun MavBull ()
(mapcar '(lambda (pt) (list (car pt) (cadr pt) (+ (caddr pt) 12.0)))lst)
)
Excuse me if I'm wrong- just trying to gain understanding here... and I'm not, definitely not, thinking my methodology is the best here but at the moment the second example, "fixos example" seems a bit redundant with the multiple calls to mapcar and the single list. I suppose with the points being a list themselves, is this what's causing the second mapcar?
(setq nameslist (list "Brandon" "carrie" "john" "frank" "tod" "bill"
"Shannon"))
("Brandon" "carrie" "john" "frank" "tod" "bill" "Shannon")
Command: (mapcar
(_> 'strcase
(_> nameslist
(_> )
("BRANDON" "CARRIE" "JOHN" "FRANK" "TOD" "BILL" "SHANNON")
Fixo
Your first post was an inspiration.
It's nice to be able to speak with like minded individuals, with no pretenses other than the code itself that we all wrap around us