Blame


1 12687dd9 2023-08-04 jrmu ;; The first three lines of this file were inserted by DrScheme. They record metadata
2 12687dd9 2023-08-04 jrmu ;; about the language level of this file in a form that our tools can easily process.
3 12687dd9 2023-08-04 jrmu #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 12687dd9 2023-08-04 jrmu #|
5 12687dd9 2023-08-04 jrmu
6 12687dd9 2023-08-04 jrmu 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.
7 12687dd9 2023-08-04 jrmu
8 12687dd9 2023-08-04 jrmu |#
9 12687dd9 2023-08-04 jrmu
10 12687dd9 2023-08-04 jrmu ;filter1 : (X Y -> boolean) (listof X) Y -> (listof X)
11 12687dd9 2023-08-04 jrmu
12 12687dd9 2023-08-04 jrmu (define (filter1 rel-op alox y)
13 12687dd9 2023-08-04 jrmu (cond
14 12687dd9 2023-08-04 jrmu [(empty? alox) empty]
15 12687dd9 2023-08-04 jrmu [(rel-op (first alox) y)
16 12687dd9 2023-08-04 jrmu (cons (first alox)
17 12687dd9 2023-08-04 jrmu (filter1 rel-op (rest alox) y))]
18 12687dd9 2023-08-04 jrmu [else
19 12687dd9 2023-08-04 jrmu (filter1 rel-op (rest alox) y)]))
20 12687dd9 2023-08-04 jrmu
21 12687dd9 2023-08-04 jrmu ;not=? : Y Y -> boolean
22 12687dd9 2023-08-04 jrmu ;Given item1 and item2, return true if the two are not equal, false if they are.
23 12687dd9 2023-08-04 jrmu
24 12687dd9 2023-08-04 jrmu (define (not=? item1 item2)
25 12687dd9 2023-08-04 jrmu (not (equal? item1 item2)))
26 12687dd9 2023-08-04 jrmu
27 12687dd9 2023-08-04 jrmu (define list1 '(automobile
28 12687dd9 2023-08-04 jrmu vehicle
29 12687dd9 2023-08-04 jrmu motorcycle
30 12687dd9 2023-08-04 jrmu van
31 12687dd9 2023-08-04 jrmu truck
32 12687dd9 2023-08-04 jrmu car
33 12687dd9 2023-08-04 jrmu sedan
34 12687dd9 2023-08-04 jrmu car
35 12687dd9 2023-08-04 jrmu pick-up
36 12687dd9 2023-08-04 jrmu train))
37 12687dd9 2023-08-04 jrmu
38 12687dd9 2023-08-04 jrmu (filter1 not=? list1 'car)
39 12687dd9 2023-08-04 jrmu (filter1 not=? list1 'automobile)
40 12687dd9 2023-08-04 jrmu