Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

  1. 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 
  2. [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. [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) 
  4. [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))) 
  5. [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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

=+3. What resources will these tactics require?

Answered: 1 week ago

Question

a valuing of personal and psychological privacy;

Answered: 1 week ago