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 2002:a24:c5c1:: with SMTP id f184-v6mr3512038itg.22.1522808335610; Tue, 03 Apr 2018 19:18:55 -0700 (PDT) X-Received: by 2002:a9d:730a:: with SMTP id e10-v6mr928996otk.8.1522808335501; Tue, 03 Apr 2018 19:18:55 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!paganini.bofh.team!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!u184-v6no5764475ita.0!news-out.google.com!15-v6ni530itg.0!nntp.google.com!u184-v6no5764472ita.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Tue, 3 Apr 2018 19:18:55 -0700 (PDT) In-Reply-To: <3a9d9cbf-87aa-41a4-89b5-b4a02ebcb748@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=173.71.218.250; posting-account=QF6XPQoAAABce2NyPxxDAaKdAkN6RgAf NNTP-Posting-Host: 173.71.218.250 References: <3a9d9cbf-87aa-41a4-89b5-b4a02ebcb748@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: limited agregate and limited components default initialization From: Jere Injection-Date: Wed, 04 Apr 2018 02:18:55 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader02.eternal-september.org comp.lang.ada:51329 Date: 2018-04-03T19:18:55-07:00 List-Id: On Tuesday, April 3, 2018 at 2:18:18 PM UTC-4, Jean-Claude Rostaing wrote: > Talking about limited aggregates, how to make the exemple below with prot= ected types work ? It should be pretty much the same as what I already did,= yet... > package P is > type Essai (<>) is limited private; > function Constructor (v: Natural) return ESSAI; > procedure CHANGE (Obj: Essai; V: Natural); > private > protected type ESSAI (D1: Natural) is=20 > procedure CHANGE (V: Natural); > private > Private_var: Natural :=3D D1;=20 > end Essai; > end P; >=20 > package BODY P is > -- procedure change(Obj: Essai; V: natural) renames ESSAI.CHANGE; > procedure CHANGE (Obj: ESSAI; V: NATURAL) is > begin > OBJ.CHANGE(V); -- 5 > end CHANGE; > function CONSTRUCTOR ( V : NATURAL) return ESSAI is > (Essai(D1 =3D> V)); -- 9 >=20 > protected body Essai is > procedure CHANGE (V: natural) is > begin > PRIVATE_VAR :=3D V; > end change; > end Essai; > end P; >=20 > I get > p.adb:5:10: prefix of protected procedure or entry call must be variable > p.adb:9:14: invalid prefix in call >=20 > Actually, I wanted CHANGE to be a renaming of Change, but since Essai her= e behave more like a package, the protected operation doesn't its protected= object as an argument, so the profile wouldn't be the same, so a renaming = can only point to a specific task/protect object's entry. >=20 > I want to force people to use a constructor on any object of ESSAI type t= hrough setting its discriminants. Discriminants who would serve to set the = default value with the constructor, so they must be hidden from the user. >=20 > I must confess I never used anything protected types before... I thought = the use would be more intuitive ? As an alternative. If you end up needing to handle protected types without discriminants, you can use a private implementation type and composition: package P is type Essai (<>) is limited private; function Constructor (v: Natural) return ESSAI; procedure CHANGE (Obj: in out Essai; V: Natural) with Inline; private =20 -- Internal implementation type protected type ESSAI_Impl is procedure CHANGE (V: Natural); private Private_var: Natural :=3D 0; end Essai_Impl; =20 -- new wrapper type type Essai is limited record Impl : Essai_Impl; end record; end P; =20 package BODY P is =20 procedure CHANGE (Obj: in out ESSAI; V: NATURAL) is begin OBJ.Impl.CHANGE(V); -- 5 end CHANGE; =20 function CONSTRUCTOR ( V : NATURAL) return ESSAI is begin -- Can use aggregate to create the wrapper type return Result : Essai :=3D (others =3D> <>) do Result.Impl.CHANGE(V); --now initialize the value end return; end CONSTRUCTOR; =20 protected body Essai_Impl is =20 procedure CHANGE (V: natural) is begin PRIVATE_VAR :=3D V; end change; =20 end Essai_Impl; =20 end P;=20