Question: Use the map and reduce functions we learned in class to implement function minAbsoluteVal that determines the minimal absolute value of a list of integer

Use the map and reduce functions we learned in class to implement function minAbsoluteVal that determines the minimal absolute value of a list of integer numbers.

Example (define minAbsoluteVal (lambda (l) ... )) ...

(minAbsoluteVal (-5 -3 -7 -10 12 8 7)) --> 3

Here are the map and reduce functions that need to be used:

(define map (lambda (f l) (if (null? l) '( ) ( cons ( f (car l) ) (map f (cdr l) ) ) ) ) )

map takes two arguments: a function and a list

map builds a new list by applying the function to every element of the (old) list

(define reduce (lambda ( op l id) ( if (null? l) id (op (car l) (reduce op (cdr l) id)) ) ) )

Reduce: Higher order function that takes a binary, associative operation and uses it to roll up a list

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!