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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,2078ce7aac45af5b X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.66.80.4 with SMTP id n4mr7310436pax.7.1352763879708; Mon, 12 Nov 2012 15:44:39 -0800 (PST) Received: by 10.68.240.103 with SMTP id vz7mr5835095pbc.10.1352763879691; Mon, 12 Nov 2012 15:44:39 -0800 (PST) Path: s9ni5145pbb.0!nntp.google.com!kt20no6799444pbb.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 12 Nov 2012 15:44:39 -0800 (PST) In-Reply-To: <0114d327-9f9f-4ad2-9281-56331d11a90c@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ NNTP-Posting-Host: 66.126.103.122 References: <0114d327-9f9f-4ad2-9281-56331d11a90c@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <2bb9e5fa-04a2-4073-bca1-1739ce0580f1@googlegroups.com> Subject: Re: Ada202X : Adding functors From: Adam Beneschan Injection-Date: Mon, 12 Nov 2012 23:44:39 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2012-11-12T15:44:39-08:00 List-Id: On Monday, November 12, 2012 2:09:15 PM UTC-8, Martin wrote: > I'm increasingly using functors in my C++ life and they are very cool. I'= d like to be able to use them in my Ada life too but the language doesn't s= upport it - or can someone tell me I'm wrong? >=20 > I think it could be done by 'simply' allowing something like this: >=20 > package P is=20 > type T is tagged ...; >=20 > function Create return T; > procedure "()" (This : T; I : Integer); -- The functor call > function "()" (This : T) return Integer; -- Alternative functor that's= a function >=20 > private >=20 > ... >=20 > end P; >=20 > with P; > procedure Demo is > My_T : P.T :=3D P.Create > begin > My_T (42); -- call to procedure version > if My_T () > 100 then ... end if; -- call to function version > end Demo; >=20 >=20 >=20 > I guess one of the trickier bits of adding this would be the possible nee= d to step away from the current Ada convention of not requiring empty paren= thesis...but new language revisions always change the 'current' good style.= .. >=20 > Any thoughts? package P is=20 type T is tagged ...;=20 function Create return T;=20 procedure Call (This : T; I : Integer); -- The functor call=20 function Call (This : T) return Integer; -- Alternative functor that's = =20 -- function private=20 ...=20 end P;=20 with P;=20 procedure Demo is=20 My_T : P.T :=3D P.Create ; begin=20 My_T.Call (42); -- call to procedure version=20 if My_T.Call > 100 then ... end if; -- call to function version=20 end Demo;=20 This already works in Ada, and doesn't require any major language changes t= hat would give the ARG headaches about empty parentheses, possible syntax c= onflicts with user-defined references and indexing, the interpretation of c= onstructs involving function calls that return P.T followed by parentheses,= etc., etc., etc. I'll concede that doing it this way may be considered le= ss "cool" than being able to avoid typing that extra identifier ("Call"). = Being able to say "This is a variable, but OH LOOK I can use it like a func= tion" certainly does seem cool, in a way. I don't see any other advantage,= though. -- Adam