Case statements in sane languages
Mario O. Bourgoin
mob at mit-amt.MEDIA.MIT.EDU
Tue Mar 20 05:38:50 AEST 1990
I feel I must interject a some Scheme code in this otherwise C-based
discussion cross-posted to comp.lang.scheme. In Scheme, there's a
control construct called CASE which is much like C's SWITCH except
that doesn't allow the clauses to be cascaded but it does allow
multiple constants per clause. It's easy to imagine a CASE-EVERY (in
the spirit of ZETALISP's COND-EVERY) very similar to CASE but that
evaluates every clause whose constant part includes the key. The
resulting structure passes control more explicitly than its C
equivalent, and yet remains simple enough to encourage programmers to
use it. For example:
(case-every (0
(1+ count))
((0 1)
(1+ ocount))
((0 1 2)
(writeln count ocount))
(else
(writeln "unknown n")))
--Mario
More information about the Comp.lang.c
mailing list