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 17.3.0) (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 ;A list-of-symbols is either
7 ;where s is a symbol and los is a list-of-symbols.
9 ;A natural-number [>=1] (N[>=1]) is either
11 ;2. (add1 n) where n is [N(>=1)]
13 ;list-pick : list-of-symbols N[>=1] -> symbol
14 ;Given a-los and n, find the nth symbol in a-los. The first symbol in a-los has an index of 1.
16 (define (list-pick a-los n)
19 (empty? a-los)) (error 'list-pick "list too short")]
21 (cons? a-los)) (first a-los)]
23 (empty? a-los)) (error 'list-pick "list too short")]
25 (cons? a-los)) (list-pick (rest a-los) (sub1 n))]))
27 (define los '(Fred Ted Bill Bob Joe))
29 ;A natural-number [>=0] (N[>=0]) is either
31 ;2. (add1 n) where n is [N(>=0)].
33 ;list-pick : list-of-symbols N[>=1] -> symbol
34 ;Given a-los and n, find the nth symbol in a-los. The first symbol in a-los has an index of 0.
35 ;(define (list-pick0 a-los n)
38 ; (empty? a-los)) (error 'list-pick0 "list too short")]
40 ; (cons? a-los)) (first a-los)]
42 ; (empty? a-los)) (error 'list-pick0 "list too short")]
44 ; (cons? a-los)) (list-pick0 (rest a-los) (sub1 n))]))
45 (define (list-pick0 a-los n)
47 [(empty? a-los) (error 'list-pick0 "list too short")]
48 [(= n 0) (first a-los)]
49 [(> n 0) (list-pick0 (rest a-los) (sub1 n))]))
54 ;A list-of-data is either
57 ;where d is a Scheme datum and lod is a list-of-data.
59 ;replace-eol-with : list-of-data list-of-data -> list-of-data
60 ;(define (replace-eol-with lod1 lod2)
64 ; [(empty? lod2) empty]
65 ; [(cons? lod2) lod2])]
68 ; [(empty? lod2) lod1]
69 ; [(cons? lod2) (append (list (first lod1))
70 ; (replace-eol-with (rest lod1) lod2))])]))
72 (define (replace-eol-with lod1 lod2)
79 [(cons? lod2) (append (list (first lod1))
80 (replace-eol-with (rest lod1) lod2))]))