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