Jump to content

Recommended Posts

Posted

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)))

Posted
(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.

Posted

Lee , That was Fantastic Thank You So much :D

 

and i have another Question with same lambda function

 

How to sort Lowest Co-ordinate Point from a List

Posted
How to sort Lowest Co-ordinate Point from a List

 

Lowest X, Y or Z coordinate?

Posted (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 by gS7
Posted

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))
)

Posted

Pbe Thank You So Much for Clarifying

 

but also need some time for Understand :lol:

Posted

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

Posted
I want to find lowest Corner Point of Rectangular

 

(apply 'mapcar (cons 'min corner_Points))

Posted

@ Pbe, Thank You Again

 

Sub Function is Better way i Think

Posted

@ Lee Your are the Masterpiece Thank You so Much

Posted

(cons 'min corner_Points). Should've thought that. Good one LM :)

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...