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 |21.2|) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ())))
4 12687dd9 2023-08-04 jrmu ;selection : (listof symbol) (listof symbol) -> (listof symbol)
5 12687dd9 2023-08-04 jrmu ;selection, which consumes two lists of names and selects all those from the second one that are also on the first.
6 12687dd9 2023-08-04 jrmu
7 12687dd9 2023-08-04 jrmu (define (selection list1 list2)
8 12687dd9 2023-08-04 jrmu (cond
9 12687dd9 2023-08-04 jrmu [(empty? list2) empty]
10 12687dd9 2023-08-04 jrmu [(in-other-list? (first list2) list1) (cons (first list2)
11 12687dd9 2023-08-04 jrmu (selection list1 (rest list2)))]
12 12687dd9 2023-08-04 jrmu [else (selection list1 (rest list2))]))
13 12687dd9 2023-08-04 jrmu
14 12687dd9 2023-08-04 jrmu (define (in-other-list? an-item a-list)
15 12687dd9 2023-08-04 jrmu (cond
16 12687dd9 2023-08-04 jrmu [(empty? a-list) false]
17 12687dd9 2023-08-04 jrmu [(equal? (first a-list) an-item) true]
18 12687dd9 2023-08-04 jrmu [else (in-other-list? an-item (rest a-list))]))
19 12687dd9 2023-08-04 jrmu
20 12687dd9 2023-08-04 jrmu (define (selection list1 list2)
21 12687dd9 2023-08-04 jrmu (cond
22 12687dd9 2023-08-04 jrmu [(empty? list1) empty]
23 12687dd9 2023-08-04 jrmu [else (local ((define (equal-to-first-of-list1 a-symbol)
24 12687dd9 2023-08-04 jrmu (equal? (first list1) a-symbol)))
25 12687dd9 2023-08-04 jrmu (cons (filter equal-to-first-of-list1? list2) (selection list2 (rest list1))))]))
26 12687dd9 2023-08-04 jrmu
27 12687dd9 2023-08-04 jrmu
28 12687dd9 2023-08-04 jrmu equal-to-first-of-list1 : symbol -> boolean