Blob


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 "htdp-intermediate-reader.ss" "lang")((modname 20.2.3) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
4 #|
6 Exercise 20.2.3. Use filter1 to develop a function that consumes a list of symbols and extracts all those that are not equal to 'car. Give filter1's corresponding contract.
8 |#
10 ;filter1 : (X Y -> boolean) (listof X) Y -> (listof X)
12 (define (filter1 rel-op alox y)
13 (cond
14 [(empty? alox) empty]
15 [(rel-op (first alox) y)
16 (cons (first alox)
17 (filter1 rel-op (rest alox) y))]
18 [else
19 (filter1 rel-op (rest alox) y)]))
21 ;not=? : Y Y -> boolean
22 ;Given item1 and item2, return true if the two are not equal, false if they are.
24 (define (not=? item1 item2)
25 (not (equal? item1 item2)))
27 (define list1 '(automobile
28 vehicle
29 motorcycle
30 van
31 truck
32 car
33 sedan
34 car
35 pick-up
36 train))
38 (filter1 not=? list1 'car)
39 (filter1 not=? list1 'automobile)