From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: ** X-Spam-Status: No, score=2.1 required=5.0 tests=BAYES_05,INVALID_DATE, MSGID_SHORT,REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Xref: utzoo comp.software-eng:3239 comp.lang.ada:3498 comp.lang.c:27047 comp.lang.fortran:2995 comp.lang.lisp:2949 comp.lang.misc:4519 comp.lang.modula2:2204 comp.lang.pascal:3248 comp.lang.scheme:1184 Path: utzoo!attcan!uunet!ogicse!mintaka!mit-eddie!mit-amt!mob From: mob@mit-amt.MEDIA.MIT.EDU (Mario O. Bourgoin) Newsgroups: comp.software-eng,comp.lang.ada,comp.lang.c,comp.lang.fortran,comp.lang.lisp,comp.lang.misc,comp.lang.modula2,comp.lang.pascal,comp.lang.scheme Subject: Re: Case statements in sane languages Message-ID: <1925@mit-amt.MEDIA.MIT.EDU> Date: 19 Mar 90 19:38:50 GMT References: <9003191549.AA01608@sn1987a.compass.com> Reply-To: mob@media-lab.media.mit.edu (Mario O. Bourgoin) Organization: MIT Media Lab, Cambridge MA List-Id: 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