Article View: comp.lang.misc
Article #311multi-dimensional switch statements
From: Mike (I'll think of something ye...
Date: Sat, 22 Jul 1989 05:17
Date: Sat, 22 Jul 1989 05:17
51 lines
2697 bytes
2697 bytes
Last night, I ran into the need for a construct that I've not seen in
any language. I've seen this same need more than once, so thought I'd
ask if any existing language has such a construct.
There's a second half to this question: I don't know what the
construct should look like. I know what features I want it to have; I
just don't know how to get it to fit into a language.
The basic idea is to be able to code a state table as is, so that the
table is obvious. A two-dimensional switch statement is the analogy
that comes to mind. A typical example might look like:
switch (row:bumpx, col: bumpy) {
case 0: case 3: case 5: case 7:
case 2: z = x++ + y; z = 2 * x + y; z = 3 * x++ + y; z = x;
case 4: z = x + y; z = x + y++; z = 3 * x + y++; z = y;
case 7: z = x++ + y++; z = x + 2 * y; z = 8 * x++ + y++; z = x * y;
}
I have no idea how to make a compiler swallow something like the
above. I don't know that that's the right form for the thing.
Features that must be there: the labels on each axis should have to be
mentioned only once, and should definitely be computed only once. It
should be able to handle large blocks of code in each element. The
compilers should be free to create the most efficient code for this
case: jump tables, spares matrixes, search trees, or else-if chains
(i.e. - the features doesn't force an implemenation technic on the
compiler writers). Most importantly, the table should have to be
mentioned only once.
I'd like to hear any thoughts from people who've actually done some
language design & implementation work, on how they'd try and get such
a feature into a language, and what they'd make it look like.
I also look forward from hearing from those who think current language
design is wrong. After all, their "everything to all people" language
would allow me to do this. If it won't let me express my ideas in a
form I find comfortable, what good is it?
Thanx,
<mike
--
Cats will be cats and cats will be cool Mike Meyer
Cats can be callous and cats can be cruel mwm@berkeley.edu
Cats will be cats, remember this words! ucbvax!mwm
Cats will be cats and cats eat birds. mwm@ucbjade.BITNET
Technical Details
Message-ID:
<26584@agate.BERKELEY.EDU>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!agate!mica.berkeley.edu!mwmShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!agate!mica.berkeley.edu!mwm From: mwm@mica.berkeley.edu (Mike (I'll think of something yet) Meyer) Newsgroups: comp.lang.misc Subject: multi-dimensional switch statements Message-ID: <26584@agate.BERKELEY.EDU> Date: 22 Jul 89 05:17:41 GMT Sender: usenet@agate.BERKELEY.EDU Reply-To: mwm@mica.berkeley.edu (Mike (I'll think of something yet) Meyer) Organization: Missionaria Phonibalonica Lines: 51