Question: use SCHEME program, use R5RS Function composition f g is an operation that takes two functions f and g and returns a function h such
use SCHEME program, use R5RS
- Function composition f g is an operation that takes two functions f and g and returns a function h such that h(x) = f(g(x)). [2 marks] Define a function (compose f g) that returns a composed function f g, such that the following usage works as shown. (define square (lambda(x)(* x x)))
(define double (lambda(x)(+ x x))) ((compose square double) 3) -> 6^2 = 36
- [1 mark] Define a function (divisibleBy x) that takes an integer argument and returns a predicate function. The returned predicate should accept an integer y and return true if y is evenly divisible by x, false otherwise. E.g.:
(define mod3 (divisibleBy 3)) (mod3 7) -> #f (mod3 9) -> #t
- [3 marks] Define a function called (newmap f) that takes a function f as argument and returns a function. The returned function should take a list as argument and map the function f over each element of the list. You should not use the built-in map function in your solution. E.g.
(define double-mapper (newmap (lambda(x)(* x 2)))) (double-mapper '(1 2 3 4)) --> (2 4 6 8) (double-mapper '(10 20 30)) --> (20 40 60)
- [3 marks] Define a function called (newfilter f) that takes a function f as argument and returns a function. That returned function should take a list as argument and filter the list using f. You should not use the built-in filter function in your solution. E.g.
(define evens-filter (newfilter (divisibleBy 2)))
- [2 marks] Using the functions you created above (and given the range function from lecture), fill in the blank (??>) on the statement below so that the definition of the function myfunc produces the expected results as shown.
(define myfunc ??>) (myfunc (range 1 20)) (16 64 144 256 400)
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
