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 X-Google-Thread: 103376,ea5071f634c2ea8b X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,CP1252 Received: by 10.68.35.68 with SMTP id f4mr6619284pbj.5.1322106515853; Wed, 23 Nov 2011 19:48:35 -0800 (PST) Path: lh20ni11358pbb.0!nntp.google.com!news2.google.com!postnews.google.com!b19g2000yqj.googlegroups.com!not-for-mail From: Shark8 Newsgroups: comp.lang.ada Subject: Re: Generic-Package Elaboration Question / Possible GNAT Bug. Date: Wed, 23 Nov 2011 19:47:07 -0800 (PST) Organization: http://groups.google.com Message-ID: <4a7d66be-ba5c-45b1-81f7-2b3b36c726ec@b19g2000yqj.googlegroups.com> References: <7bf9bc32-850a-40c6-9ae2-5254fe220533@f29g2000yqa.googlegroups.com> NNTP-Posting-Host: 24.230.151.194 Mime-Version: 1.0 X-Trace: posting.google.com 1322106515 15446 127.0.0.1 (24 Nov 2011 03:48:35 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 24 Nov 2011 03:48:35 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: b19g2000yqj.googlegroups.com; posting-host=24.230.151.194; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: HUALESNKRC X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0,gzip(gfe) Xref: news2.google.com comp.lang.ada:14587 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Date: 2011-11-23T19:47:07-08:00 List-Id: On Nov 22, 9:13=A0pm, Yannick Duch=EAne (Hibou57) wrote: > A guess attempt: does not depend on Generic_Delete implementation, but > rather on a Generic_Delete instantiation parameters. If you could post th= e > instantiation snippet too=85 (with declarations it depends on). > > Le Sat, 19 Nov 2011 22:14:44 +0100, Shark8 a > =E9crit: > > > > > > > > > > > I was working on some simple little array manipulation functions when > > I encountered an interesting behavior in the compiler; it said that > > trying to instantiate a function of the form: > > =A0 =A0Generic > > =A0 =A0 =A0 Type Element is Private; > > =A0 =A0 =A0 Type Index_Type is (<>); > > =A0 =A0 =A0 Type Array_Type is Array (Index_Type Range <>) of Element; > > =A0 =A0Function Generic_Delete( Index : In Index_Type; Data : In > > Array_Type ) Return Array_Type; > > > When given the following body, the compiler complained about the > > Index_Range'First/Last not being static: > > > =A0 =A0Function Generic_Delete( Index : In Index_Type; Data : In > > Array_Type ) Return Array_Type is > > =A0 =A0begin > > =A0 =A0 =A0 if Index not in Data'Range then > > =A0 =A0 =A0 =A0 =A0Raise Constraint_Error; > > =A0 =A0 =A0 else > > =A0 =A0 =A0 =A0 =A0 =A0case Index is > > =A0 =A0 =A0 =A0 =A0 =A0when Index_Type'First =3D> Return > > Data( Index_Type'Succ(Index)..Data'Last ); > > =A0 =A0 =A0 =A0 =A0 =A0when Index_Type'Last =3D> Return > > Data( Data'First..Index_Type'Pred(Index) ); > > =A0 =A0 =A0 =A0 =A0 =A0when others =3D> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Return Data( Data'First..Index_Type= 'Pred(Index) ) > > =A0 =A0 =A0 =A0 =A0 =A0 & Data( Index_Type'Succ(Index)..Data'Last ); > > =A0 =A0 =A0 =A0 =A0 =A0end case; > > =A0 =A0 =A0 end if; > > =A0 =A0end Generic_Delete; > > > Now, I know that the following works as a fix: > > > =A0 =A0 =A0Function Generic_Delete( Index : In Index_Type; Data : In > > Array_Type ) Return Array_Type is > > =A0 =A0 =A0begin > > =A0 =A0 =A0 =A0 if Index not in Data'Range then > > =A0 =A0 =A0 =A0 =A0 =A0Raise Constraint_Error; > > =A0 =A0 =A0 =A0 else > > =A0 =A0 =A0 =A0 =A0 =A0if Index =3D Data'First then > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 Return Data( Index_Type'Succ(Index)..Data'L= ast ); > > =A0 =A0 =A0 =A0 =A0 =A0elsif Index =3D Data'Last then > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 Return Data( Data'First..Index_Type'Pred(In= dex) ); > > =A0 =A0 =A0 =A0 =A0 =A0else > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 Return Data( Data'First..Index_Type'Pred(In= dex) ) > > =A0 =A0 =A0 =A0 =A0 =A0 & Data( Index_Type'Succ(Index)..Data'Last ); > > =A0 =A0 =A0 =A0 =A0 =A0end if; > > =A0 =A0 =A0 =A0 end if; > > =A0 =A0 =A0end Generic_Delete; > > > But the question that came to my mind after reading the ARM section on > > the error (sorry, I forgot to write it down) is, why is it not static? > > Is it because though the elaboration-parameters *may* be known [and > > static] at compile-time that some instantiation might NOT be > > [guaranteed] to be known at compile-time? (i.e. because the compiler > > cannot guarantee that you won't throw 1..N where N is something pulled > > from the user-input?) > > -- > =93Syntactic sugar causes cancer of the semi-colons.=94 =A0[Epigrams on > Programming =97 Alan J. =97 P. Yale University] > =93Structured Programming supports the law of the excluded muddle.=94 [Id= em] The type I was using were something like: SubType Board_Index is Positive Range 1..9; Type Column is Array( Board_Index Range <> ) of Board_Index; So the instantiation was something like: Function Delete is New Generic_Delete( Board_Index, Board_Index, Column );