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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,583fc1ff93937468,start X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit X-Received: by 10.224.185.201 with SMTP id cp9mr797223qab.6.1364517148533; Thu, 28 Mar 2013 17:32:28 -0700 (PDT) X-Received: by 10.50.33.175 with SMTP id s15mr2335091igi.8.1364517148491; Thu, 28 Mar 2013 17:32:28 -0700 (PDT) Path: v17ni9qad.0!nntp.google.com!ca1no15382344qab.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Thu, 28 Mar 2013 17:32:28 -0700 (PDT) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=69.20.190.126; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC NNTP-Posting-Host: 69.20.190.126 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Pure vs. Pure; aspect vs. pragma. From: Shark8 Injection-Date: Fri, 29 Mar 2013 00:32:28 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2013-03-28T17:32:28-07:00 List-Id: In the Ada 2012 rationale it says: > A number of existing pragmas are paralleled by aspect specifications but= the pragmas are not made obsolete. Examples are the pragmas relating to pa= ckages such as Pure, Preelaborate, Elaborate_Body and so on. > > Thus we can write either of > > package P is > pragma Pure(P); > end P; > > or > > package P > with Pure is > end P; So they should be equivalent; this, however, is not so in GNAT-2012. Example: ----------------------------------------------- -- Test.adb Pragma Ada_2012; Pragma Assertion_Policy( Check ); With some_function, subtype_definitions, subtype_definitions2, Ada.Text_IO; Procedure Test is Function F( Parameter : Integer ) Return Integer renames some_function; Begin Ada.Text_IO.Put_Line("Starting Test:"); declare Generic Type S is (<>); With Function Image( Item: S ) Return String is S'Image; Package Metric is First : Constant S :=3D S'First; Last : Constant S :=3D S'Last; =20 Function Range_String(Name : String) Return String is (Name & " is Range" & First'Img & " .." & Last'Img); End Metric; =09 =09 =09 -- Swap out these definitione to see the differences. Package S is new subtype_definitions; -- Package S is new subtype_definitions2(f(1), f(2), f(11)); =09 Package M1 is new Metric( S.S1 ); Package M2 is new Metric( S.S2 ); Package M3 is new Metric( S.S3 ); =09 Use Ada.Text_IO; begin Put_Line( M1.Range_String( "S1" ) ); Put_Line( M2.Range_String( "S2" ) ); Put_Line( M3.Range_String( "S3" ) ); end; Ada.Text_IO.Put_Line("Testing complete."); End Test; ----------------------------------------------- -- some_function.adb With Ada.Numerics.Discrete_Random; Function Some_Function( Parameter : Integer ) Return Integer is Subtype K is Positive Range 64..1024; Package RNG_Pkg is new Ada.Numerics.Discrete_Random(Result_Subtype =3D>= K); RNG : RNG_Pkg.Generator; begin =20 -- There is actually another function here importing glGetIntegerv, -- executing it, and returning the result in 'Result'. Return Result : Integer do for Index in 1..Parameter loop Result:=3D RNG_Pkg.Random(RNG); end loop; end return; end Some_Function; ----------------------------------------------- -- subtype_definitions.ads With some_Function; generic package subtype_definitions with Pure is -- Cannot uncomment. -- Pragma Pure; =20 subtype S1 is Integer Range 0 .. some_function(1); subtype S2 is Integer Range 0 .. some_function(2); subtype S3 is Integer Range 0 .. some_function(11); end subtype_definitions; ----------------------------------------------- -- subtype_definitions2.adb generic L1 : Integer; L2 : Integer; L3 : Integer; package subtype_definitions2 with Pure is Pragma Pure; =20 subtype S1 is Integer Range 0 .. L1; =20 subtype S2 is Integer Range 0 .. L2; =20 subtype S3 is Integer Range 0 .. L3; end subtype_definitions2; --------------------------------------------------- I ran into this when restructuring my open-gl library; the idea being that = I can have the object-enumerations (lights, buffers, etc) definitions dynam= ically defined at instantiation on the target computer -- these enumeration= s have certain mandatory minimums [on the upper bound] and those, it seems,= are what the open-gl bindings I've looked at [mostly C/C++] seem to embrac= e... but it seems a bit limiting to do that in Ada when we have subtypes [w= hich can be dynamically set]. {Of course subprograms taking those enumerations should have parameters of = those subtypes; leading me to think generic-packages would be the best way = to address this.}