On 16 Lug, 08:20, p...@[EMAIL PROTECTED]
(Pascal J. Bourguignon)
wrote:
> rk <rakes...@[EMAIL PROTECTED]
> writes:
> > 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.
>
> (define var expression) <--> (let ((var expression)) ...)
> (define (fun args...) expression) <--> (let ((fun (lambda (args...)
expression))) ...
<nitpicking>
It's letrec not let.
</nitpicking>


|