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=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.182.112.231 with SMTP id it7mr29202119obb.9.1413998709941; Wed, 22 Oct 2014 10:25:09 -0700 (PDT) X-Received: by 10.50.72.105 with SMTP id c9mr432142igv.3.1413998709853; Wed, 22 Oct 2014 10:25:09 -0700 (PDT) Path: border2.nntp.dca1.giganews.com!nntp.giganews.com!uq10no15707053igb.0!news-out.google.com!ks2ni543igb.0!nntp.google.com!h18no8830966igc.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 22 Oct 2014 10:25:09 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=66.126.103.122; posting-account=KSa2aQoAAACOxnC0usBJYX8NE3x3a1Xq NNTP-Posting-Host: 66.126.103.122 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <5c9aa35f-c12e-4212-b8b9-4d4c6340302a@googlegroups.com> Subject: Re: passing parametars as determinants From: Adam Beneschan Injection-Date: Wed, 22 Oct 2014 17:25:09 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: number.nntp.giganews.com comp.lang.ada:189975 Date: 2014-10-22T10:25:09-07:00 List-Id: On Tuesday, October 21, 2014 11:11:58 PM UTC-7, mockturtle wrote: > As far as I know, not directly. You have two alternatives: > 1. Pass c as an access to string.=20 > 2. Give to the task an entry point Init (or something similar) and use= it to pass c. Something like > task body myTaskType is > local_copy : myOtherType; > begin > accept Init(c: myOtherType) do > local_copy :=3D c; > end Init; > -- Back to serious work > end myTaskType; > Why are not we allowed to use generic types as discriminants? Honestly, = I do not know, I have always been curious...=20 Do you really mean "generic", or do you mean "general"? Generic formal typ= es can be used as discriminants, as long as they're known to be discrete: generic type T is (<>); package Pack1 is task type Task_Type (Discr : T) is ... -- legal As for why discriminant types are limited to discrete and access types: In = Ada 83, discriminants were allowed only on record types (not tasks), and th= ere were no access discriminants. The main use of discriminants on a recor= d type were to provide a bound for an array component: subtype String_Length is Integer range 0 .. 1000; type Varying_String (Length : String_Length :=3D 0) is record Data : String (1 .. Length); end record; or to use in a variant part: type Variant_Record (D : Data_Type) is record case D is when Integer_Type =3D> Int_Data : Integer; when Float_Type =3D> Float_Data : Float; when Boolean_Type =3D> Boolean_Data : Boolean; end case; end record; For both of these purposes, only discrete types make sense as discriminants= . For task discriminants, which were added in Ada 95, a String discriminant (= parameter) would pose a problem if you used a local variable as a parameter= : type Task_Type (Data : String) is ... end Task_Type; type Task_Type_Acc is access all Task_Type; procedure Proc is Task_Data : constant String :=3D Some_Function_Call; New_Task : Task_Type_Acc :=3D new Task_Type (Task_Data); begin ... end Proc; The task could outlive Task_Data, causing a problem. Discrete discriminant= s don't have that problem because they're copy-in, and access discriminants= don't have that problem because the accessibility rules prevent the discri= minant from being the 'Access of something that won't live as long as the t= ask. (Of course you could defeat it with 'Unchecked_Access, or by passing = an access to an allocated object and then using Unchecked_Deallocation on t= he object.) I guess you could legitimately ask why they didn't allow fixed= -point or floating-point types, which are copy-in, to be used as discrimina= nts. -- Adam