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: a07f3367d7,344faf475a6f812a,start X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit X-Received: by 10.224.217.195 with SMTP id hn3mr20571321qab.5.1366655230009; Mon, 22 Apr 2013 11:27:10 -0700 (PDT) X-Received: by 10.182.129.105 with SMTP id nv9mr286915obb.22.1366655229972; Mon, 22 Apr 2013 11:27:09 -0700 (PDT) Path: ef9ni9516qab.0!nntp.google.com!gp5no4825967qab.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 22 Apr 2013 11:27:09 -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: <97967083-d21d-4de2-aeb8-76d0d5818993@googlegroups.com> Subject: Interresting difference in Normal-Returns/Expression-Functions and Extended-Returns. From: Shark8 Injection-Date: Mon, 22 Apr 2013 18:27:10 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2013-04-22T11:27:09-07:00 List-Id: I recently ran into unexpected behavior in the differences between a normal= return and an extended return [in GNAT]: namely an extended return used to= generate items in an array of tasks will *ALWAYS* execute in a sequential = manner whereas the array generated with an expression-function or normal re= turn is executed simultaneously. Is there some subtle difference in the extended return that I'm unaware of?= (Is this a bug?) -------------------- -- Experiment.adb -- -------------------- Pragma Ada_2012; With Ada.Text_IO, Ada.Numerics.Float_Random ; Procedure Experiment is ----------------------------------------------------- -- RNG; This sets up random numbers for durations. -- ----------------------------------------------------- Package RNG is Function Random Return Duration; Private Use Ada.Numerics.Float_Random; G : Generator; Function Random Return Duration is ( Duration( Random(G) ) ); End RNG; =20 Package Body RNG is Begin Ada.Numerics.Float_Random.Reset( G ); End RNG; =20 -------------------------------------------------- -- Resource; Protected object handling Text-IO. -- -------------------------------------------------- protected Resource is procedure Write( Input : In String ); procedure New_Line; private end Resource; =20 protected body Resource is procedure Write( Input : In String ) is begin Ada.Text_IO.Put_Line( Input ); end Write; Procedure New_Line is begin Write(""); end New_Line; end Resource; =20 --------------------------------------------------------- -- Testing; This is the task-type we are playing with. -- --------------------------------------------------------- Task Type Testing( Text : Not Null Access Constant String ) is end Testing; Task Body Testing is D : Duration :=3D RNG.Random; -- Get a random duration. Begin delay D; -- Delay for that duration. -- Then print the Text for the task as well as the Delay. Resource.Write( Text.ALL & ASCII.HT & Duration'Image(D) ); End Testing; =20 -- Make; these functions make an access-to-tasks for arrays. -- Note: these should all be equivelant. Function Make_EF(Input : in String) Return Not Null Access Testing is ( New Testing( Text =3D> New String'(Input) ) ); Function Make_ER(Input : in String) Return Not Null Access Testing is begin Return Result : Not Null Access Testing:=3D New Testing(New String'(I= nput)); End Make_ER; Function Make_NR(Input : in String) Return Not Null Access Testing is begin Return New Testing(New String'(Input)); End Make_NR; =20 Begin Resource.Write("TEST_1:"& ASCII.HT &"Expression Function"); TEST_1: declare Function Make(Input : in String) Return Not Null Access Testing Renames Make_EF; P : Constant Array (Positive Range <>) of Not Null Access Constant Testing:=3D ( Make("Bob"), Make("Steve"), Make("Dave"), Make("Joey") ); begin null; end TEST_1; Resource.New_Line; Resource.Write("TEST_2:"& ASCII.HT &"Normal Return Function"); TEST_2: declare Function Make(Input : in String) Return Not Null Access Testing Renames Make_NR; P : Constant Array (Positive Range <>) of Not Null Access Constant Testing:=3D ( Make("Bob"), Make("Steve"), Make("Dave"), Make("Joey") ); begin null; end TEST_2; Resource.New_Line; Resource.Write("TEST_3:"& ASCII.HT &"Extended Return Function"); TEST_3: declare Function Make(Input : in String) Return Not Null Access Testing Renames Make_ER; P : Constant Array (Positive Range <>) of Not Null Access Constant Testing:=3D ( Make("Bob"), Make("Steve"), Make("Dave"), Make("Joey") ); begin null; end TEST_3; Resource.New_Line; =20 Resource.Write( "Terminating." ); End Experiment;