From: "Mike Silva" <mjsilva@jps.net>
Subject: Re: Modular type. What is it and why?
Date: 1999/04/06
Date: 1999-04-06T00:00:00+00:00 [thread overview]
Message-ID: <7edk6p$1j7$1@its.hooked.net> (raw)
In-Reply-To: 370A4B3A.5EDB3B37@pwfl.com
Marin David Condic wrote in message <370A4B3A.5EDB3B37@pwfl.com>...
>Mike Silva wrote:
>> 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!
>>
>
>My C is pretty rusty - not having done anything serious in it in at
>least 10 years - but wasn't there some kind of type/operation that
>allowed for wraparound semantics?...
Well, if you're going up you can do:
index = ( index + 1 ) % NUM_ELEMENTS; /* where % is the MOD operator */
but you can't do:
index = ( index - 1 ) % NUM_ELEMENTS; /* won't handle 0 ->
NUM_ELEMENTS - 1 correctly */
As Ole-Hjalmar Kristensen commented, the nice Ada solution doesn't work if
NUM_ELEMENTS varies at runtime (at least, it appears that a modular type
can't be defined dynamically -- correct?), but that's not the usual case I
run across.
Mike
next prev parent reply other threads:[~1999-04-06 0:00 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-04-05 0:00 Modular type. What is it and why? Staffan Dittmer
1999-04-05 0:00 ` David C. Hoos, Sr.
1999-04-06 0:00 ` Mike Silva
1999-04-06 0:00 ` Marin David Condic
1999-04-06 0:00 ` Mike Silva [this message]
1999-04-06 0:00 ` bglbv
1999-04-07 0:00 ` Ole-Hjalmar Kristensen
1999-04-07 0:00 ` Mike Silva
1999-04-07 0:00 ` Stephen Leake
1999-04-08 0:00 ` Ole-Hjalmar Kristensen
1999-04-06 0:00 ` Ole-Hjalmar Kristensen
1999-04-06 0:00 ` Mike Silva
1999-04-07 0:00 ` Robert Dewar
1999-04-07 0:00 ` Bret
1999-04-11 0:00 ` Florian Weimer
1999-04-05 0:00 ` Marin David Condic
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox