comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: My bug or else regarding Visibility Rules
Date: Thu, 04 Apr 2013 09:19:54 +0100
Date: 2013-04-04T09:19:54+01:00	[thread overview]
Message-ID: <lyfvz6hfmd.fsf@pushface.org> (raw)
In-Reply-To: 55c932fa-73a4-4999-a913-71d0d8ff4782@googlegroups.com

Anh Vo <anhvofrcaus@gmail.com> 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



  reply	other threads:[~2013-04-04  8:19 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-28 19:54 My bug or else regarding Visibility Rules Anh Vo
2013-03-28 20:58 ` Adam Beneschan
2013-03-28 22:03   ` Randy Brukardt
2013-03-30  6:05     ` Anh Vo
2013-04-02  0:56       ` Randy Brukardt
2013-04-02  1:52         ` Anh Vo
2013-04-02  8:26           ` Simon Wright
2013-04-02 18:17             ` Anh Vo
2013-04-02 20:16               ` Simon Wright
2013-04-03 23:21                 ` Anh Vo
2013-04-04  8:19                   ` Simon Wright [this message]
2013-04-04 19:21                     ` Anh Vo
2013-04-04 19:47                       ` Simon Wright
2013-04-02 22:04           ` Randy Brukardt
2013-03-28 22:06   ` Anh Vo
replies disabled

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