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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,75ce2ead897158b2 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit X-Received: by 10.181.13.179 with SMTP id ez19mr5285221wid.5.1365063593946; Thu, 04 Apr 2013 01:19:53 -0700 (PDT) Path: p18ni36544wiv.0!nntp.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!ecngs!feeder2.ecngs.de!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx05.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: My bug or else regarding Visibility Rules Date: Thu, 04 Apr 2013 09:19:54 +0100 Organization: A noiseless patient Spider Message-ID: References: <0c77e832-e12b-446d-af24-78d77c358f1e@googlegroups.com> <25ee066d-3270-4efd-829f-ed40b04c0655@googlegroups.com> <89292c53-1d4e-48a7-b2ae-a10983ef4168@googlegroups.com> <55c932fa-73a4-4999-a913-71d0d8ff4782@googlegroups.com> Mime-Version: 1.0 Injection-Info: mx05.eternal-september.org; posting-host="72a7bb6120f61bc7749e29c9c2e535af"; logging-data="27868"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+GueBo1bT9HwfhPMRbZNpLGC8lVH7SLWo=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (darwin) Cancel-Lock: sha1:Za7ubGjJVrJzDWjHp98IMqFm9ks= sha1:Dc2ssTat1xwuQAWWdJIjDp+yIO0= Content-Type: text/plain Date: 2013-04-04T09:19:54+01:00 List-Id: Anh Vo writes: > On Tuesday, April 2, 2013 1:16:34 PM UTC-7, Simon Wright wrote: >> 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. This is a bug in GNAT, fixed in GCC 4.8.0 (I had tested with GNAT GPL 2012, which allows it). >> 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. Not simpler, just the only way I can see to retain privacy and contracts. >> 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? Because after the index has wrapped round Buffer'Old(1) will not be the same as Buffer(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. No. You wrote (Index mod Length) + 1 but it should be (Index + 1) mod Length