Need Help Understanding Bindings in Schema Code

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 :)

+3
source share
1

w, . x - , x ( f1).

, f1 , x, 3. f1, , x 14.

- lambda , ; , , , x.

+4

Source: https://habr.com/ru/post/1778776/


All Articles