I'm studying lambda for my midterm and I understand the concept. **the lambda function is just a way of defining a function without giving it a name. **the lambda format has to be ((lambda (x y z) (formula) parameter) **please fix me if I'm wrong. I don't understand the codes below. Can someone explain to me why the answer is like that? I know it's a lot, you don't have to explain all the examples. Thanks!
((lambda (x y z)(x(/ y 2)(* 3 z)6))+ 4 2) ;14
((lambda (x)((lambda (x)(/ x 4))(+ x 2)))6) ;2
((lambda (x y)(+ (x * y)(x + y)))(lambda (x y)(x y y ))3) ;15
(((lambda (a)(lambda (b) '(lambda (c) '(a b c)))) 1) 2)
(((lambda(x)(lambda(y)(+ x y))) 12) ((lambda(z)(* 3 z)) 3))
(define (x y z)((lambda (y z)(- y z)) z y)) (x 3 5)
((lambda (x y) (+ 3 x (* 2 y))) (+ 3 3)(* 2 2))
((lambda(x)(lambda(y)(+ x y)))12)
You can easily rewrite a lambda
to a let
. Eg.
((lambda (x y z)
(x (/ y 2)
(* 3 z)
6))
+
4
2)
As let:
(let ((x +) (y 4) (z 2))
(x (/ y 2)
(* 3 z)
6))
It is the exact same code but perhaps slightly more readable. Every lambda
for that gets called immediately can get that treatment also after substitution steps.
Now you can use the substitution rules. Replace x
with +
, y
with 4
and z
with 2
and replace the call/let
with the same expression with the values replaced:
(+ (/ 4 2)
(* 3 2)
6))
Substitute simple expressions with their result:
(+ 2
6
6))
; ==> 14
And there you go. Easy peasy.