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.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,75ce2ead897158b2 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit X-Received: by 10.224.110.68 with SMTP id m4mr2056722qap.2.1365031308079; Wed, 03 Apr 2013 16:21:48 -0700 (PDT) X-Received: by 10.49.6.66 with SMTP id y2mr421638qey.18.1365031308064; Wed, 03 Apr 2013 16:21:48 -0700 (PDT) Path: ef9ni1264qab.0!nntp.google.com!ca1no28280211qab.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 3 Apr 2013 16:21:47 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=149.32.224.34; posting-account=Qh2kiQoAAADpCLlhT_KTYoGO8dU3n4I6 NNTP-Posting-Host: 149.32.224.34 References: <0c77e832-e12b-446d-af24-78d77c358f1e@googlegroups.com> <25ee066d-3270-4efd-829f-ed40b04c0655@googlegroups.com> <89292c53-1d4e-48a7-b2ae-a10983ef4168@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <55c932fa-73a4-4999-a913-71d0d8ff4782@googlegroups.com> Subject: Re: My bug or else regarding Visibility Rules From: Anh Vo Injection-Date: Wed, 03 Apr 2013 23:21:48 +0000 Content-Type: text/plain; charset=ISO-8859-1 Date: 2013-04-03T16:21:47-07:00 List-Id: On Tuesday, April 2, 2013 1:16:34 PM UTC-7, Simon Wright wrote: > Anh Vo writes: > On Tuesday, April 2, 2013 1:26:12 AM UTC-7, Simon Wright wrote: > Other recipients: > Anh Vo writes: >> It is dangerous make internal data visible in this case. after careful >> consideration, I decided to take away part of the post-conditions >> rather than exposing them. Following the philosophy of Ada, I would >> not leave any possibilities for the clients to accidently mess it up >> (not allowing clients to shoot themselve in the foot) > I think that part of your difficulty is that your Queue is implemented > using(effectively) global objects (Buffer, In_Index etc). Actually, it is my intention to design this way. I believe it is called singleton form. I could have designed Queue type as well, as you suggested. > then you could say something like > > procedure Put (Q : in out Queue; Item : Element) > with Pre => not Queue_Full (Q'Old), > Post => Item_Added (Q'Old, Q, Item); I believe that attribute 'Old is allowed in post-conditions only. > with public > > function Item_Added (Old, Current : Queue; Item : Element) return Boolean; > >and private > > function Item_Added > (Old, Current : Queue; Item : Element) return Boolean is > ((Current.In_Index = (Old.In_Index + 1) mod Length) and > (Current.Buffer (Old.In_Index) = Item) and > -- (for all I in 1 .. Queue_Length'Old => > -- Buffer(I) = Buffer'Old (I)) and > (not Queue_Empty (Current))); This way does not look simpler. I rather go with simple way even I decide to use Queue type instead of Singleton Queue. > I commented out the comparison, because this is a *circular* buffer, so > the first valid element isn't at Buffer(1). I do not understand this. Why isn't Buffer(1) valid if my index starts at 1? > I think it will all work better if you say > subtype Index is Natural range 0 .. Length - 1; > so that mod works as you require. > > You need to add 1 to the current index and then do mod length! This is another array index option. A. Vo