(define (foo x)(+ x 2))
(define (bar y) (y 3))
;substitution model
;(bar foo)
;(foo 3)
;(+ 3 2)
;5
(define (func x)
(if (>= x 0) + -))
(define (pi-sum a b)
(define (pi-term a) (/ 1.0 (* a (+ a 2))))
(define (pi-next a) (+ a 4))
(if (> a b)
0
(+ (pi-term a)
(pi-sum (pi-next a) b))))
(define (sum a b term next)
(if (> a b)
0
(+ (term a)
(sum (next a) b term next))))
(define (sum-int a b)
(define (identity x) x)
(define (inc x)(+ x 1))
(sum 1 100 identity inc)) ;integer sum
(define (sum-cubes a b)
(define (cube x)(* x x x))
(define (inc x)(+ x 1))
(sum 1 100 cube inc)) ;cube sum
(define (pi-sum2 a b)
(define (pi-term a)(/ 1.0 (* a (+ a 2))))
(define (pi-next a)(+ a 4))
(sum 1 1000 pi-term pi-next)) ;pi ssum
(* 8 (pi-sum2 1 100))
;lambda examples
(lambda() (+ 3 4))
((lambda()(+ 3 4)))
(lambda(x) (+ x 3))
((lambda(x)(+ x 3)) (+ 1 2 3 (* 4 5 6)))
((lambda(x y z)(+ (* x y) z)) 2 3 4) ;=> ?
(sum 1 100 (lambda(x)x) (lambda(x)(+ x 1)))
;equivalent…
(define (cube x)(* x x x))
(define cube (lambda(x)(* x x x)))
(define f
(lambda (x y)
(* (+ x y) 2)))
(f 5 4)
((lambda(i j k)(+ (* 3 i)(- j k))) 3 2 1) ;=> 10
(let ((i 3)(j 2)(k 1)) (+ (* 3 i)(- j k))) ;=> 10
((lambda(arg)(arg 2 3)) (lambda(x y)(+ (* 2 x) y))) ;=> 7
;((lambda(arg)(arg 2 3)) (lambda(x y)(+ (* 2 x) y)))
;((lambda(x y)(+ (* 2 x) y)) 2 3)
(define (fun x)
((lambda(y) (if (< x y) x y)) 2))
(fun 3)
(define (myfunction x)
(lambda(y)(+ x y)))
(myFunction 3) ;=> #procedure
((myFunction 3) 2) ;=> 5
;((myFunction 3) 2)
;((lambda(y)(+ x y)) 2)
;(+ x 2) ; ?