-
Notifications
You must be signed in to change notification settings - Fork 0
/
115.rkt~
executable file
·28 lines (24 loc) · 1.14 KB
/
115.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
;; The first three lines of this file were inserted by DrRacket. They record metadata
;; about the language level of this file in a form that our tools can easily process.
#reader(lib "htdp-beginner-reader.ss" "lang")((modname |115|) (read-case-sensitive #t) (teachpacks ((lib "image.rkt" "teachpack" "2htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "image.rkt" "teachpack" "2htdp")) #f)))
; Any -> Boolean
; is the given value an element of TrafficLight
(define (light? x)
(cond
[(string? x) (or (string=? "red" x)
(string=? "green" x)
(string=? "yellow" x))]
[else #false]))
(define MESSAGE
"traffic light expected, given some other value")
; Any Any -> Boolean
; are the two values elements of TrafficLight and,
; if so, are they equal
(check-expect (light=? "red" "red") #true)
(check-expect (light=? "red" "green") #false)
(check-expect (light=? "green" "green") #true)
(check-expect (light=? "yellow" "yellow") #true)
(define (light=? a-value another-value)
(if (and (light? a-value) (light? another-value))
(string=? a-value another-value)
(error MESSAGE)))