Sweety Posted September 11, 2010 Author Share Posted September 11, 2010 Hello GUYS. I just wanted to show you something, which means a big step to me with Defun + Lambda functions in this example. As it is mentioned in the uploaded book by Renderman as follows . [size=3](setq pt1 '(-3.24 2.82 0.0))[/size] [size=3](setq pt2 '(2.5 8.76))[/size] [size=3](mapcar '(lambda (c1 c2)[/size] [size=3] (/ (+ c1 c2) 2.0)[/size] [size=3] )[/size] [size=3] pt1[/size] [size=3] pt2[/size] [size=3])[/size] [size=3]that wouls return the mid point between both of them.[/size] BUT, in my example also would return the same result with use of Defun . Check this out PLEASE. .... (defun mids (sweet1 sweet2) (list (setq one (/ (+ (car sweet1)(car sweet2)) 2.0)) (setq two (/ (+ (cadr sweet1)(cadr sweet2)) 2.0)) (setq three (/ (+ (caddr sweet1)(caddr sweet2)) 2.0)) ) ) (setq p1 '(1.0 2.0 3.0)) (setq p2 '(4.0 5.0 6.0)) (mids p1 p2) Hope you give me your opinion about them. Thanks for all Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 11, 2010 Share Posted September 11, 2010 So you can see the benefit in terms of concision and elegance by using a mapcar expression Check out my earlier post also, it has quite a few examples of averages of points. Quote Link to comment Share on other sites More sharing options...
Sweety Posted September 11, 2010 Author Share Posted September 11, 2010 Thank you Lee. I am so happy with it today, cause I have been forcing my self between Mapcar + Lambda for so long for now, and finally got it with Defun function. So Mapcar and Lambda are really doing a very great work togather, Specially when we want lots of devides and distributions for vaiables. Hope you do not mind if I discovered something else to share opinions with it. Thanks a lot Quote Link to comment Share on other sites More sharing options...
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.