-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathex-173.rkt
58 lines (44 loc) · 1.35 KB
/
ex-173.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#lang htdp/bsl
; ### Constants
(define ARTICLES (cons "a" (cons "an" (cons "the" '()))))
(define line0 (cons "I" (cons "am" (cons "a" (cons "horse" '())))))
(define line0-no-art (cons "I" (cons "am" (cons "horse" '()))))
(define line1 (cons "the" (cons "wise" (cons "man" '()))))
(define line1-no-art (cons "wise" (cons "man" '())))
; ### Data Definitions
; LLS (List-of-list-of-strings) is one of:
; - '()
; - (cons List-of-strings LLS)
; ### Functions
; LLS -> LLS
; Removes all articles from all lines
(check-expect (remove-articles '()) '())
(check-expect
(remove-articles (cons line0 (cons line1 '())))
(cons line0-no-art (cons line1-no-art '()))
)
(define (remove-articles lls)
(cond
[(empty? lls) '()]
[else
(cons
(remove-line-articles (first lls))
(remove-articles (rest lls))
)]))
; List-of-string -> List-of-string
; Removes all articles from line
(check-expect (remove-line-articles '()) '())
(check-expect (remove-line-articles line0) line0-no-art)
(define (remove-line-articles los)
(cond
[(empty? los) '()]
[(article? (first los)) (remove-line-articles (rest los))]
[else (cons (first los) (remove-line-articles (rest los)))]
))
; String -> Boolean
; Checks whether a given string is an article
(define (article? s)
(member? s ARTICLES)
)
(require test-engine/racket-tests)
(test)