@@ -1168,11 +1168,13 @@ also write modules without saving them in a file. For example:
11681168
11691169@ex[
11701170(module bt racket
1171- (provide bt-height)
1171+ (provide (all-defined-out ))
1172+ (struct leaf () #:prefab )
1173+ (struct node (v l r) #:prefab )
11721174 (define (bt-height bt)
11731175 (match bt
1174- [` leaf 0 ]
1175- [` (node , _ , left , right)
1176+ [( leaf) 0 ]
1177+ [(node _ left right)
11761178 (+ 1 (max (bt-height left)
11771179 (bt-height right)))])))
11781180]
@@ -1185,7 +1187,7 @@ provided values:
11851187
11861188@ex[
11871189(require 'bt )
1188- (bt-height ' leaf )
1190+ (bt-height ( leaf) )
11891191]
11901192
11911193We could have also used the @tt{#lang racket} shorthand for
@@ -1214,29 +1216,32 @@ provide everything:
12141216 (module+ test
12151217 (require rackunit))
12161218
1219+ (struct leaf () #:prefab )
1220+ (struct node (v l r) #:prefab )
1221+
12171222 (define (bt-empty? bt)
12181223 (match bt
1219- [' leaf #t ]
1220- [(cons 'node _ ) #f ]))
1224+ [( leaf) #t ]
1225+ [_ #f ]))
12211226
12221227 (module+ test
1223- (check-equal? (bt-empty? ' leaf ) #t )
1224- (check-equal? (bt-empty? ' (node 3
1225- (node 7 leaf leaf)
1226- (node 9 leaf leaf)))
1228+ (check-equal? (bt-empty? ( leaf) ) #t )
1229+ (check-equal? (bt-empty? (node 3
1230+ (node 7 ( leaf) ( leaf) )
1231+ (node 9 ( leaf) ( leaf) )))
12271232 #f ))
12281233
12291234 (define (bt-height bt)
12301235 (match bt
1231- [` leaf 0 ]
1232- [` (node , _ , left , right)
1236+ [( leaf) 0 ]
1237+ [(node _ left right)
12331238 (+ 1 (max (bt-height left)
12341239 (bt-height right)))]))
12351240
12361241 (module+ test
1237- (check-equal? (bt-height ' leaf ) 0 )
1242+ (check-equal? (bt-height ( leaf) ) 0 )
12381243 (code:comment "intentionally wrong test: " )
1239- (check-equal? (bt-height ' (node 3 leaf leaf)) 2 )))
1244+ (check-equal? (bt-height (node 3 ( leaf) ( leaf) )) 2 )))
12401245]
12411246
12421247Requiring this module with make @racket[bt-height], but @emph{it will not run the tests}:
0 commit comments