gS7 Posted April 6, 2013 Posted April 6, 2013 Hey Guys , I am Trying to Understand lambda function and i need your Help to Understand Properly Example : i created a List (list (0 0 0) (1 1 1) (2 2 2)) and i am Trying to add 0.5 value to x & y value of Coordinate point from list Tell me How add those Values using lambda function Mylist (setq mylist (list '(0 0 0) '(1 1 1) '(2 2 2) '(3 3 3))) Quote
Lee Mac Posted April 6, 2013 Posted April 6, 2013 (mapcar '(lambda ( x ) (mapcar '+ x '(0.5 0.5 0))) mylist) Or (mapcar '(lambda ( x ) (list (+ (car x) 0.5) (+ (cadr x) 0.5) (caddr x))) mylist) My Mapcar & Lambda tutorial may help you grasp the concept. Quote
gS7 Posted April 6, 2013 Author Posted April 6, 2013 Lee , That was Fantastic Thank You So much and i have another Question with same lambda function How to sort Lowest Co-ordinate Point from a List Quote
Lee Mac Posted April 6, 2013 Posted April 6, 2013 How to sort Lowest Co-ordinate Point from a List Lowest X, Y or Z coordinate? Quote
gS7 Posted April 8, 2013 Author Posted April 8, 2013 (edited) Lee, I want to find lowest Corner Point of Rectangular Example Codes: (setq corner_Points (list '(10.0 10.0 0.0) '(20.0 10.0 0.0) '(20.0 20.0 0.0) '(10.0 20.0 0.0))) (setq x (mapcar 'car corner_points)) (setq y (mapcar 'cadr corner_points)) (setq lower (list (apply 'min x) (apply 'min y))) (setq upper (list (apply 'max x) (apply 'max y))) For This I Have to Create So Many Variables Edited April 8, 2013 by gS7 Quote
pBe Posted April 8, 2013 Posted April 8, 2013 Lambda and no variables besides the points [corner_points] ((lambda (x y z) (list (list (y (car x)) (y (cadr x))) (list (z (car x)) (z (cadr x))) ) ) (list (mapcar 'car corner_points) (mapcar 'cadr corner_points) ) (lambda (i) (apply 'min i)) (lambda (i) (apply 'max i)) ) Quote
gS7 Posted April 8, 2013 Author Posted April 8, 2013 Pbe Thank You So Much for Clarifying but also need some time for Understand Quote
pBe Posted April 8, 2013 Posted April 8, 2013 I personally don't have anything against creating variables, your code could be written this way: (defun _HiLow (pts) (list (list (apply 'min (setq x (mapcar 'car pts))) (apply 'min (setq y (mapcar 'cadr pts))) ) (list (apply 'max x) (apply 'max y)) ) ) ( _HiLow corner_Points ) will give you the same result when use as a helper routine. [that is if you need to extract the low and high points for more two or more point list at one time] HTH Quote
Lee Mac Posted April 8, 2013 Posted April 8, 2013 I want to find lowest Corner Point of Rectangular (apply 'mapcar (cons 'min corner_Points)) Quote
gS7 Posted April 8, 2013 Author Posted April 8, 2013 @ Pbe, Thank You Again Sub Function is Better way i Think Quote
gS7 Posted April 8, 2013 Author Posted April 8, 2013 @ Lee Your are the Masterpiece Thank You so Much Quote
pBe Posted April 8, 2013 Posted April 8, 2013 (cons 'min corner_Points). Should've thought that. Good one LM Quote
Recommended Posts
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.