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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!goblin1!goblin3!goblin.stu.neva.ru!news.ripco.com!news.glorb.com!peer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!fx09.iad.POSTED!not-for-mail From: Shark8 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:31.0) Gecko/20100101 Thunderbird/31.0a1 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Type Transcriptions References: <53554D3F.8050009@shaw.ca> <87ha5m1kyc.fsf@ludovic-brenta.org> In-Reply-To: <87ha5m1kyc.fsf@ludovic-brenta.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Message-ID: <9aq5v.115278$Fj3.61184@fx09.iad> X-Complaints-To: abuse@teranews.com NNTP-Posting-Date: Tue, 22 Apr 2014 08:57:41 UTC Organization: TeraNews.com Date: Tue, 22 Apr 2014 02:57:41 -0600 X-Received-Bytes: 3843 X-Received-Body-CRC: 3293918534 Xref: news.eternal-september.org comp.lang.ada:19489 Date: 2014-04-22T02:57:41-06:00 List-Id: On 21-Apr-14 14:33, Ludovic Brenta wrote: > Shark8 writes: >> On 21-Apr-14 12:11, Yannick Duchêne (Hibou57) wrote: >>> Le Mon, 21 Apr 2014 18:54:23 +0200, Brad Moore a >>> écrit: >>> >>>> I'd suggest trying to make GenericAEADCipher a discriminated record >>>> type, with the two length values as the discriminants, and then the >>>> arrays are sized using the discriminants. No Generics needed. >>>> >>>> Brad >>>> >>> >>> I guess Shark8 would already have figured it if this could be as simple. >>> He says this, which is important: “certain class of record-type is >>> dependent on the values in another record, yet distinctly separate”. >>> With two separated things, a discriminant is not applicable. Or may be >>> I've not understood. >> >> You have the right of it. >> Using discriminants is the natural way to do it, but doing so would >> (in actuality) break sticking to the spec as the record-type would >> have fields which don't exist in the spec. >> >> I suppose the better way to phrase it is: >> "Is it better to strictly stick to the spec, letting generic >> instantiation take care of these 'extra-typal' parameters, *OR* doing >> things the natural Ada way, and worrying about 'fixing-up' things in, >> say, 'Input and 'Output operations." > > Ada 2012 has a very nice new feature: unchecked unions (clause B.3.3); > it is a discriminated record with an aspect says that the discriminants > are *not* in the record, but stored elsewhere instead. I have used them > in my tiny Ada binding to the X C binding (XCB), like so: > > type Detail_T (Response_Type : Response_Type_T := Reply) is record > case Response_Type is > when Key_Press | Key_Release => > Keycode : Interfaces.Unsigned_8; > when Button_Press | Button_Release | Motion_Notify => > Detail : Button_T; > when others => > Padding : Interfaces.Unsigned_8; > end case; > end record > with Unchecked_Union; > > type Response_T (Sent : Boolean; Response_Type : Response_Type_T) is > record > Detail : Detail_T (Response_Type); > [other components omitted] > end record; > for Response_T use record > Sent at 0 range 7 .. 7; > Response_Type at 0 range 0 .. 6; > end record; > > > This says that the Response_T has two discriminants, stored as the first > two components, and that the second discriminant, Response_Type, also > constrains the component Detail, but Detail does not contain a copy of > this discriminant. > > This sounds awfully similar to the spec you're trying to implement :) > > In this case, Ada 2012 saves the day! > Thanks for the info. Unfortunately it is of no help: the [non-]discriminant cannot be used to set the length of the internal 'vector' (the array).