[plt-scheme] 12.4.2 word definition; is this OK?
2009/5/10 Grant Rettke <grettke at acm.org>:
> Is this definition of word OK?
>
> ;; A word is a list of 0 or more symbols ('a, 'b, ..., 'z).
>
> (check-expect empty (list))
>
> ;; word? : word -> boolean
> ;; to determine whether the argument is a word
> (define (word? arg)
> (cond ((empty? arg) true)
> ((symbol? (first arg)) (word? (rest arg)))
> (else false)))
>
> ; word? unit tests
>
> (check-expect true
> (word? (list)))
> (check-expect true
> (word? (list 'a)))
> (check-expect true
> (word? (list 'a 'b)))
> (check-expect true
> (word? (list 'a 'b 'c)))
> (check-expect false
> (word? (list 'a 'b (list))))
> (check-expect false
> (word? (list (list) 'b 'c)))
(check-expect (word? (list 'not 'a 'word)) false)
Henk