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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,fcf8ea94b94d6941 X-Google-Attributes: gid103376,public From: "Mike Silva" Subject: Re: Modular type. What is it and why? Date: 1999/04/06 Message-ID: <7ede2p$pd1$1@its.hooked.net>#1/1 X-Deja-AN: 463299446 References: <7ean3c$79m$1@eol.dd.chalmers.se> <7eb2iq$jc3@hobbes.crc.com> X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 Organization: Whole Earth Networks News Newsgroups: comp.lang.ada Date: 1999-04-06T00:00:00+00:00 List-Id: David C. Hoos, Sr. wrote in message <7eb2iq$jc3@hobbes.crc.com>... <....> >There are many uses for such a type -- e.g., the index of a circular array, or a representation of the days of the week... One of the little "goodies" I discovered in coming from C to Ada are modular types. I often had to write code like: switch ( key ) { case ARROW_DOWN: if ( index < ( NUM_ELEMENTS - 1 ) ) index++; else index = 0; break; case ARROW_UP: if ( index > 0 ) index = NUM_ELEMENTS - 1; else index--; break; } Now with Ada I'll be able to write (assuming 'index' is the appropriate modular type): case ( key ) is when ARROW_DOWN => index := index + 1; when ARROW_UP => index := index - 1; end case; Now -that's- what I call progress! Mike