Let your program break down from top to bottom:
(* z 4)
Multiply z by 4
(lambda (y) (* z 4))
Return Function z*4
(* (lambda (y) (* z 4)) 2)
The product of this function and 2. You cannot multiply the function by 2. This probably causes your error; perhaps you want to do the following:
(define (zlamb) (lambda (z) ((lambda (y) (* 2 (yz))) ; Note the two parenthesis before lambda - this is a function application (lambda (z2) (* z2 4)))))
First, note that both z same, since z2 tied to the value of z on line 3. They can be referred to as z , but I named them differently to prevent confusion.
It then appears that your main problem is confusing the name of the function with its arguments:
(lambda (name) ...)
creates an anonymous function with argument name . The reason we can refer to the anonymous function in line 4 as y in line 3 is to make a construct
((lambda (y) ...) (lambda ...))
which passes the second function as an argument to the first, thereby calling it y .
source share