In the code below, I cannot understand how the bindings (x, y, z) occur. Please read the code, I will explain my problem in more detail below:
(define (w x)
(lambda (y z)
(begin
(set! x (+ (* y x) z)) x)))
(define f1 (w 3))
(f1 4 2)
(f1 2 1)
The output is 14, 29. These are the values for x.
This means that first x = 3, y = 4, z = 2. In the second call, that is (f1 2 1), x = 14, y = 2, z = 1.
My doubts:
How is binding first, why x = 3, y = 4 and z = 2? If this is related to the expression of a lambda in a function, please clarify how this works. I have a feeling when my understanding breaks down.
Further, why is the original answer x = 14 stored in the second call, i.e. (f1 2 1)?
Thanks for looking at this :)
source
share