Generation of functions with a very flexible signature ***
Write a function grouping-abstraction-by-predicates
(define (grouping-abstraction-by-predicates collector pred1 pred2) ....)
with the following characteristics:
- It takes 3 parameters.
- collector is another function of three parameters: (1) The list of those that satisfy pred1, (2) the list of those that satisfy pred2, and (3) the list of all others.
- pred1 is a predicate
- pred2 is another predicate
- grouping-abstraction-by-predicates returns a function that accept an arbitrary number of parameters.
The returned function traverses the (list of) parameters passed to it.
The elements that satisfy pred1 are collected in one list; The elements that satisfy pred2 are collected in another list;
The remaining elements are collected in a third list.
The three lists of collected elements are passed to collector. grouping-abstraction-by-predicates returns the result the call to collector.
Use grouping-abstraction-by-predicates to generate a function that accepts an arbitrary number of parameter. The functions should add all numbers in the parameter list,
form a string of all characters in the parameter list, and throw away all others away. Thus, the generated function should return a list of one number and one string. Here is an example:
> (define h (grouping-abstraction-by-predicates
(lambda (l1 l2 l3) (list (sum l1) (apply string l2)))
> (h 1 3 #\a 4 7 #\b 8 #\c #t 5 #t #t #\d)
You may want to play with your function for other purposes, with other predicates, etc.