Question
2. Arithmetic of Functions We can define a higher order function, i.e. functional form, that accepts two functions as parameters and returns their sum, As
2. Arithmetic of Functions We can define a higher order function, i.e. functional form, that accepts two functions as parameters and returns their sum, As a running example, well consider two functions: f(x) = x + 2 g(x) = 3x + 4 These are modeled by the following Scheme functions, respectively: (define (f x) (+ x 2)) (define (g x) (+ (* 3 x ) 4)) The higher order function: (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 f g) 10) ; returns 46. Or (define (plus func1 func2 x) (+ (func1 x) (func2 x)) ) (plus f g 10) ; returns 46. Define a function (form) that compute the difference of two functions.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started