comp.lang.ada
 help / color / mirror / Atom feed
From: Ole-Hjalmar Kristensen <ohk@maestro.clustra.com>
Subject: Re: Modular type. What is it and why?
Date: 1999/04/07
Date: 1999-04-07T00:00:00+00:00	[thread overview]
Message-ID: <umqg16cpn3y.fsf@maestro.clustra.com> (raw)
In-Reply-To: 7edk6p$1j7$1@its.hooked.net

"Mike Silva" <mjsilva@jps.net> writes:

> 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 */
> 

Actually, if index is unsigned, then it *will* 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.

Agreed, I just thought I would mention it.
> 
> Mike
> 
> 
> 

-- 
E pluribus Unix




  parent reply	other threads:[~1999-04-07  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 ` Marin David Condic
1999-04-05  0:00 ` David C. Hoos, Sr.
1999-04-06  0:00   ` Mike Silva
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-06  0:00     ` Marin David Condic
1999-04-06  0:00       ` Mike Silva
1999-04-06  0:00         ` bglbv
1999-04-07  0:00         ` Ole-Hjalmar Kristensen [this message]
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
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox