Question

(define test
     (lambda()
       (let* ((x 1)
              (y 3)
              (z 5)
              (foo (lambda (n)
                     (let* ((x 3)
                            (y (+ x n))
                            (g (lambda(w) (+ (* x w) y))))
                       g))))
        ((foo 10) x))))

What does this evaluate to?

Attempt:

Call (foo 10) -> (lambda(w) (+ x w) y), where x = 3, y = 13

Call ((lambda(w) (+ (* x w) y) x) -> (where local x is 1) ->

Was it helpful?

Solution

(foo 10) => (lambda (w) (+ (* x w) y) ; where x = 3 and y = 13
         => (lambda (w) (+ (* 3 w) 13)

((foo 10) x) => (+ (* 3 w) 13) ; where w is 1
             => (+ (* 3 1) 13)
             => 16

See here

Don't know where you got 52 from.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top