-
Notifications
You must be signed in to change notification settings - Fork 0
/
115.rkt
executable file
·26 lines (23 loc) · 1.16 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
;; 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]))
; 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)
(cond
[(not (light? a-value)) (error "a-value is not a traffic light")]
[(not (light? another-value)) (error "another-value is not a traffic light")]
[else (string=? a-value another-value)]))