For the code below, I am unable to comprehend how the bindings (x, y, z) occur. Please check out the code, I'll explain my problem in greater 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 values for x.
This means initially, x=3, y=4, z=2. In the 2nd call, i.e. (f1 2 1), x=14, y=2,z=1.
My doubts:
How does the binding occur at first, why is x=3, y=4, and z=2? If it has got to do with lambda expression in the function, please elaborate on how it works..I have a feeling this is where my understanding breaks down..
Next, why is the initial answer of x=14 retained in the second call, i.e. (f1 2 1)?
Thank you for looking into this :)