Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Scheme > lambda and defi...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 5 Topic 4609 of 4788
Post > Topic >>

lambda and define

by rk <rakeshks@[EMAIL PROTECTED] > Jul 15, 2008 at 04:31 PM

Hello schemers,

My understanding, after going through initial chapters of SICP, of
define was that it is lambda in disguise. However, this code piece
(trying the solution to ex. 3.7 ed.1) does not work as expected and I
had to replace the define with lambda.

(define (estimate-integral x1 x2 y1 y2 trials)
   (define experiment
      (p (real-random x1 x2) (real-random y1 y2)))
   (* (rect-area x1 x2 y1 y2) (monte-carlo trials experiment)))

The trace of the procedure showed that the experiment was getting
evaluated before calling the monte-carlo. When I replaced the
experiment with this code, it worked as it passed the procedure
instead of the value of the procedure

(define (estimate-integral x1 x2 y1 y2 trials)
   (let ((experiment
             (lambda()
                (p (real-random x1 x2) (real-random y1 y2)))))
     (* (rect-area x1 x2 y1 y2) (monte-carlo trials experiment))))

If lambda and define are one and the same then how come the evaluation
points are different? Any explanation is really appreciated.
 




 5 Posts in Topic:
lambda and define
rk <rakeshks@[EMAIL PR  2008-07-15 16:31:18 
Re: lambda and define
pjb@[EMAIL PROTECTED] (P  2008-07-16 08:20:27 
Re: lambda and define
Jens Axel Soegaard <fi  2008-07-16 14:11:19 
Re: lambda and define
Vend <vend82@[EMAIL PR  2008-07-21 02:55:04 
Re: lambda and define
Vend <vend82@[EMAIL PR  2008-07-21 03:00:53 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Oct 12 22:19:32 CDT 2008.