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,8077d2e20cde67b1 X-Google-Attributes: gid103376,public From: niewiap@widzew.net (Pawe� Niewiadomski) Subject: Re: Modular types inside records Date: 2000/10/21 Message-ID: <8FD4BD4F4Pablo@213.25.200.9>#1/1 X-Deja-AN: 684163458 References: <8FD47616EPablo@213.25.200.9> <8ss7fb$5c7$1@nnrp1.deja.com> X-Complaints-To: usenet@tpi.pl X-Trace: news.tpi.pl 972141849 16219 195.117.215.73 (21 Oct 2000 15:24:09 GMT) Organization: tp.internet - http://www.tpi.pl User-Agent: Xnews/03.04.11 NNTP-Posting-Date: 21 Oct 2000 15:24:09 GMT Newsgroups: comp.lang.ada Date: 2000-10-21T15:24:09+00:00 List-Id: > > 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