1 ;; The first three lines of this file were inserted by DrScheme. They record metadata
2 ;; about the language level of this file in a form that our tools can easily process.
3 #reader(lib "" "lang")((modname 20.2.4) (read-case-sensitive #t) (teachpacks ((lib "" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "" "teachpack" "htdp")))))
4 Exercise 20.2.4. Formulate general contracts for the following functions:
6 sort, which consumes a list of items and a function that consumes two items (from the list) and produces a boolean; it produces a list of items.
8 map, which consumes a function from list items to Xs and a list; it produces a list of Xs.
10 project, which consumes a list of lists and a function from lists to Xs; it produces a list of Xs.
12 Compare with exercise 20.2.2. Solution
14 ;sort : (listof X) (X X -> boolean) -> (listof X)
15 ;
16 ;map : ((listof X) -> X) (listof Y) -> (listof X)
17 ;
18 ;project : (listof (listof X)) ((listof X) -> X) -> (listof X)
20 ;sort : (listof numbers) (number number -> boolean) -> (listof numbers)
22 ;map : (number -> number) (listof numbers) -> (listof numbers)
24 ;project : (listof (listof symbols)) ((listof symbols) -> symbols) -> symbols