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,MAILING_LIST_MULTI, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d534ed04fa87be8b X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-12-25 06:20:04 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!arclight.uoregon.edu!wn14feed!worldnet.att.net!206.252.192.28!news.stealth.net!news.stealth.net!fr.usenet-edu.net!usenet-edu.net!enst.fr!not-for-mail From: Michal Nowak Newsgroups: comp.lang.ada Subject: Re: Discriminant name must be alone Date: Wed, 25 Dec 2002 15:29:27 +0100 Organization: ENST, France Sender: comp.lang.ada-admin@ada.eu.org Message-ID: References: Reply-To: comp.lang.ada@ada.eu.org NNTP-Posting-Host: marvin.enst.fr Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7BIT X-Trace: avanie.enst.fr 1040826003 97135 137.194.161.2 (25 Dec 2002 14:20:03 GMT) X-Complaints-To: usenet@enst.fr NNTP-Posting-Date: Wed, 25 Dec 2002 14:20:03 +0000 (UTC) Return-Path: In-reply-to: X-Mailer: Calypso Version 3.30.00.00 (3) Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org X-Mailman-Version: 2.0.13 Precedence: bulk X-Reply-To: vinnie@inetia.pl List-Unsubscribe: , List-Id: comp.lang.ada mail<->news gateway List-Post: List-Help: List-Subscribe: , Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org Xref: archiver1.google.com comp.lang.ada:32303 Date: 2002-12-25T15:29:27+01:00 On 2002-12-21 at 23:08 Robert A Duff wrote: >Michal Nowak writes: > >> Hello all, >> >> Digging around (teaching myself and experimenting with Ada) >> I wandered to RM 3.8 (12): > >I suggest using a textbook (perhaps Barnes) to learn Ada, rather than >the RM. Unless you're very comfortable reading all the legalese in the >RM (and AARM)... That's OK, I got Cohen's superior "Ada as a Second Language". The rule I was referring to is described in point 9.2.4 (Allowable use of discriminants), but there was no explanation of internal matters and why it is like that. > >The implementation issue is not just "potential". >It really does simplify implementation to know that the bound >can be computed by a simple fetch of the discriminant. > [snip some of my questions] > >Most uses have no problem with the current rule. The usual thing is >that the discriminant is the upper bound of an array. Not 10 less than >the upper bound, or some other convolution. > >However, I have run into a few cases where I would like to do what >you're suggesting here. For example, I wrote a "storage pool" type, >where the private part defined the storage as an array of machine words. >The allocated types were known to be always word aligned, and always a >multiple of word size. The array of words makes alignment easy, and the >Allocate procedure can simply return 'Address of one of the array >components. But I wanted the client to specify the size in >Storage_Elements. So the array would have to be: > > Storage: Word_Array(0..(Size_In_Bytes-1)/4); -- Illegal! > >where Size_In_Bytes is the discriminant. Or something like that. I forget to mention, that I had immutable records in mind, this issue is more complicated with mutable records. I think one time I wanted an array, which was a component of record, to start at specified index, but the discriminant was Size. It was impossible to compute ending bound. >I think the main problem with allowing that (besides what the AARM >mentions) is that if you allow arbitrary expressions referring to >discriminants, you have to worry about when that expression is >evaluated. Suppose that expression is "F(Size_In_Bytes)", where F is >some function that might have side effects. If it has side effects, it >might return a different answer each time it's called. > >I suppose one answer is to say that the expression is evaluated whenever >a value of the record type is created. The value of that expression >must be saved as "dope" -- a hidden record component created by the >compiler. If it has side effects, that's the programmer's problem. >This would be the first case where a compiler is required to store >dope. Some compilers store dope, but it's never required. Now I get the point. Thank you for answer and explanations, Merry Christmas, - Michal -- ----------------------------------------------------------------- -- * ___ * _' ' * ` * ` * ' . -- / _ \ ' * | | * * * ~*~ -- | |_| | ___| | * _____ ` * ` * * ` i/:\i -- | _ *| | __ | | __' | * i/`:'\i -- |_| |_| |____*|_ |_____|_ Christmas with Ada: ` i/`':`'\i -- * ' http://www.autopen.com/OTANBAUM.shtml '^^^I^^^' -- -----------------------------------------------------------------