Jump to content

Mapcar + lambda Description


Sweety

Recommended Posts

Hello GUYS.:)

 

I just wanted to show you something, which means a big step to me with Defun + Lambda functions in this example. :lol:

 

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

Link to comment
Share on other sites

  • Replies 22
  • Created
  • Last Reply

Top Posters In This Topic

  • Sweety

    10

  • Lee Mac

    8

  • BlackBox

    4

  • muthu123

    1

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. :lol:

 

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

Link to comment
Share on other sites

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