[plt-scheme] 12.4.2 word definition; is this OK?

From: Henk Boom (henk at henk.ca)
Date: Sun May 10 10:47:44 EDT 2009

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


Posted on the users mailing list.