From: niewiap@widzew.net (Pawe� Niewiadomski)
Subject: Re: Modular types inside records
Date: 2000/10/21
Date: 2000-10-21T15:24:09+00:00 [thread overview]
Message-ID: <8FD4BD4F4Pablo@213.25.200.9> (raw)
In-Reply-To: 8ss7fb$5c7$1@nnrp1.deja.com
>
> X := X + 1;
> if X = max then X := 0; end if;
>
>will work just fine
>
>And no, there is clearly no way to use a modular type in
>this case. To understand why, consider that the model of
>generics is always organized to allow shared generics, and
>we can't have base types whose range is dynamic at runtime!
>
How about this one?
generic
type item_type is private;
type mod_n_max is mod <>;
package queues is
type queue is tagged private;
function empty (q: queue) return boolean;
function full (q: queue) return boolean;
procedure add (q: queue; item: in item_type);
procedure remove (q: queue; item: out item_type);
private
type arr is array (natural range <>) of item_type;
procedure move_to_0 (var: out natural);
procedure move_to_last (var: out natural; values: in arr);
type queue is tagged record
values: arr (0..mod_n_max'modulus-1);
tail: mod_n_max:=0;
head: mod_n_max:=1;
end record;
end queues;
Pretty neat, huh? Not as flexible as my previous (erroneous) idea (you
need to instantiate the generic every time you want to change the size of
your queue), but still gets rid of constraint verification problem. It is
just a rough, untested idea, but I think it will work.
Thanks for your answer,
Pawel
next prev parent reply other threads:[~2000-10-21 0:00 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-10-21 0:00 Modular types inside records Pawe� Niewiadomski
2000-10-21 0:00 ` Robert Dewar
2000-10-21 0:00 ` Pawe� Niewiadomski [this message]
2000-10-21 0:00 ` Jeff Carter
2000-10-21 0:00 ` Pawe� Niewiadomski
2000-10-23 0:00 ` Robert A Duff
2000-10-23 0:00 ` Pawe� Niewiadomski
2000-10-24 0:00 ` Robert A Duff
2000-10-25 1:50 ` Nick Roberts
2000-10-25 0:00 ` Pawe� Niewiadomski
2000-10-27 22:05 ` Robert Dewar
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox