Exercises in this lecture        next -- Keyboard shortcut: 'n'  Go to the slide, where this exercise belongs -- Keyboard shortcut: 'u'  

Exercise 2.18
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:

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)))
                 number?
                 char?))
 > (h 1 3 #\a 4 7 #\b 8 #\c #t 5 #t #t #\d)
   (28 "abcd")

You may want to play with your function for other purposes, with other predicates, etc.


Solution