Lately, when I've been using cond, I make use of a trick for cond:
Quote
(cond
((= a b) foo)
(default bar))
This works, because "default" is a builtin function with an address, so it always evaluates to true. I was actually shocked that there is a builtin function named "default". Had to look it up to see what it did.
So, I thought, I will try this trick also for a case statement!
Quote
(case a
(b foo)
(default bar))
This doesn't work. But (true bar) instead of (default bar) does work. Lutz, if "true" is a default value for case statement, can we have "default" work as well?
This works (from the manual):
(define (translate n)
(case n
(1 "one")
(2 "two")
(3 "three")
(4 "four")
(true "Can't translate this")))
or this (good to use for error messages, if an unexpected condition occurs):
(define (translate n)
(cond
((= n 1) "one")
((= n 2) "two")
((= n 3) "three")
((= n 4) "four")
("default" "Can't translate this")))