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 17.2.2) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp")))))
4 12687dd9 2023-08-04 jrmu (define-struct phone-record (name number))
5 12687dd9 2023-08-04 jrmu
6 12687dd9 2023-08-04 jrmu ;A phone-record is a structure
7 12687dd9 2023-08-04 jrmu ;(make-phone-record s n)
8 12687dd9 2023-08-04 jrmu ;where s is a symbol and n is a number.
9 12687dd9 2023-08-04 jrmu ;
10 12687dd9 2023-08-04 jrmu ;A list-of-symbols is either
11 12687dd9 2023-08-04 jrmu ;1. empty or
12 12687dd9 2023-08-04 jrmu ;2. (cons s los)
13 12687dd9 2023-08-04 jrmu ;where s is a symbol and los is a list-of-symbols.
14 12687dd9 2023-08-04 jrmu ;
15 12687dd9 2023-08-04 jrmu ;A list-of-numbers is either
16 12687dd9 2023-08-04 jrmu ;1. empty or
17 12687dd9 2023-08-04 jrmu ;2. (cons n lon)
18 12687dd9 2023-08-04 jrmu ;where n is a number and lon is a list-of-numbers.
19 12687dd9 2023-08-04 jrmu ;
20 12687dd9 2023-08-04 jrmu ;A list-of-phone-records is either
21 12687dd9 2023-08-04 jrmu ;1. empty or
22 12687dd9 2023-08-04 jrmu ;2. (cons pr lopr)
23 12687dd9 2023-08-04 jrmu ;where pr is a phone-record and lopr is a list-of-phone-records.
24 12687dd9 2023-08-04 jrmu ;
25 12687dd9 2023-08-04 jrmu ;zip : list-of-symbols list-of-numbers -> list-of-phone-records
26 12687dd9 2023-08-04 jrmu ;Given los (list-of-symbols representing a list of names) and lon (list-of-numbers representing a list of phone numbers), produces a list-of-phone-records.
27 12687dd9 2023-08-04 jrmu ;ASSUMPTION: Both lists are assumed to be of the same length.
28 12687dd9 2023-08-04 jrmu
29 12687dd9 2023-08-04 jrmu (define (zip los lon)
30 12687dd9 2023-08-04 jrmu (cond
31 12687dd9 2023-08-04 jrmu [(empty? los) empty]
32 12687dd9 2023-08-04 jrmu [(cons? los) (cons (make-phone-record (first los) (first lon))
33 12687dd9 2023-08-04 jrmu (zip (rest los) (rest lon)))]))
34 12687dd9 2023-08-04 jrmu
35 12687dd9 2023-08-04 jrmu (define list-names '(Joe Sam Bill Hank Frank Ronald))
36 12687dd9 2023-08-04 jrmu (define list-numbers '(595 393 232 521 423 094))
37 12687dd9 2023-08-04 jrmu (zip list-names list-numbers)