3.)Function composition We can define a higher order function, i.e. functional form, that accepts two functions as parameters and returns their sum, As an example, consider two functions below: f1(x) = x + 2 g1(x) = 3x + 4 These are modeled by the following Scheme functions, respectively: (define (f1 x) (+ x 2)) (define (g1 x) (+ (* 3 x ) 4)) The higher order function plus = f1 + g1: (define (plus func1 func2) (lambda (x) (+ (func1 x) (func2 x)))) Note the use of the lambda in order to return a nameless function. In essence, we are accepting two functions, func1 and func2, and returning a function that takes one parameter x and represents their sum. We can apply this functional form as follows: ((plus f1 g1) 10) ; returns 46. Or (define (plus func1 func2 x) (+ (func1 x) (func2 x)) ) (plus f1 g1 10) ; returns 46. Define a function (form) that compute the product of two functions and test your functions.
3.)Function composition We can define a higher order function, i.e. functional form, that accepts two functions as parameters and returns their sum, As an example, consider two functions below: f1(x) = x + 2 g1(x) = 3x + 4 These are modeled by the following Scheme functions, respectively: (define (f1 x) (+ x 2)) (define (g1 x) (+ (* 3 x ) 4)) The higher order function plus = f1 + g1: (define (plus func1 func2) (lambda (x) (+ (func1 x) (func2 x)))) Note the use of the lambda in order to return a nameless function. In essence, we are accepting two functions, func1 and func2, and returning a function that takes one parameter x and represents their sum. We can apply this functional form as follows: ((plus f1 g1) 10) ; returns 46. Or (define (plus func1 func2 x) (+ (func1 x) (func2 x)) ) (plus f1 g1 10) ; returns 46. Define a function (form) that compute the product of two functions and test your functions.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images