From: Dale Worley
Subject: Case statements in sane languages
Date: 
Message-ID: <9003191549.AA01608@sn1987a.compass.com>
    From: ·······@sanders.austin.ibm.com (Tony Sanders)

    How do you do this in ADA?

	switch(n) {
	  case 0:
	    count++;
	  case 1:
	    ocount++;
	  case 2:
	    printf("%d %d\n",count,ocount);
	    break;
	  default:
	    printf("unknown n\n");
	    break;
	}

    See how I left out the breaks on purpose.

    In ADA you wouldn't be able to do this without duplicating either the
    case-expression (they aren't always simple numbers) or the statements.

In this case, duplicating the statements wouldn't be hard enough to
worry about.  If the bodies of the cases were large enough to make it
hard, you can write a local procedure, and just call it from several
cases.  (Since Ada has nested procedures, you can write a procedure
that has access to local variables.)

    The 11th commandment: "Thou shalt use lint"

In Ada (or any sane language), "Lint" is called "the compiler".

Dale Worley		Compass, Inc.			······@compass.com
--
Why are you RUNNING?  Cerebus just wants to KILL you a little...

From: Mario O. Bourgoin
Subject: Re: Case statements in sane languages
Date: 
Message-ID: <1925@mit-amt.MEDIA.MIT.EDU>
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
From: Mario O. Bourgoin
Subject: Case statements: Error in my reply.
Date: 
Message-ID: <1936@mit-amt.MEDIA.MIT.EDU>
I apologize for having made an error in my reply's example.  I left
out the expression that evaluates to the selection key.  Here is the
correct code:

        (case-every n
		    (0
		     (1+ count))
		    ((0 1)
		     (1+ ocount))
		    ((0 1 2)
		     (writeln count ocount))
		    (else
		     (writeln "unknown n")))

--Mario