Scheme::R5RS。我正在研究 lambda,但我不明白这些代码
Scheme::R5RS. I'm studying lambda and I don't understand these codes
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)
您可以轻松地将 lambda
重写为 let
。例如
((lambda (x y z)
(x (/ y 2)
(* 3 z)
6))
+
4
2)
让:
(let ((x +) (y 4) (z 2))
(x (/ y 2)
(* 3 z)
6))
这是完全相同的代码,但可读性可能稍好一些。立即调用的每个 lambda
也可以在替换步骤后得到该处理。
现在您可以使用替换规则。将 x
替换为 +
,将 y
替换为 4
,将 z
替换为 2
,并将 call/let
替换为相同的表达式替换值:
(+ (/ 4 2)
(* 3 2)
6))
用结果替换简单表达式:
(+ 2
6
6))
; ==> 14
好了。简单易行。
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)
您可以轻松地将 lambda
重写为 let
。例如
((lambda (x y z)
(x (/ y 2)
(* 3 z)
6))
+
4
2)
让:
(let ((x +) (y 4) (z 2))
(x (/ y 2)
(* 3 z)
6))
这是完全相同的代码,但可读性可能稍好一些。立即调用的每个 lambda
也可以在替换步骤后得到该处理。
现在您可以使用替换规则。将 x
替换为 +
,将 y
替换为 4
,将 z
替换为 2
,并将 call/let
替换为相同的表达式替换值:
(+ (/ 4 2)
(* 3 2)
6))
用结果替换简单表达式:
(+ 2
6
6))
; ==> 14
好了。简单易行。