[plt-scheme] 12.4.2 word definition; is this OK?
On May 10, 2009, at 10:25 AM, Carl Eastlund wrote:
> ... you must use the contract Any -> Boolean.
> Otherwise you can't sensibly ask this question any time you might not
> already know the answer.
>
> ... if the contract is Word -> Boolean, this simplifies even
> further to a trivial function. But if the contract is Any -> Boolean
> as with most predicates, your last version will most definitely crash
> on inputs such as 5, "hello", and (make-posn 100 200). The use of
> cons? before applying first and rest is critical.
Oops: you're right. That should have been
(define (word? arg)
(or (empty? arg)
(and (cons? arg) (symbol? (first arg)) (word? (rest arg)))))
relying on the short-circuit behavior of both "or" and "and".
Stephen Bloch
sbloch at adelphi.edu