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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no 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.81.200 with SMTP id c8mr8512960pay.1.1352780578559; Mon, 12 Nov 2012 20:22:58 -0800 (PST) Received: by 10.68.135.67 with SMTP id pq3mr5950215pbb.19.1352780578542; Mon, 12 Nov 2012 20:22:58 -0800 (PST) Path: s9ni5145pbb.0!nntp.google.com!kt20no7416168pbb.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 12 Nov 2012 20:22:58 -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=69.20.190.126; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC NNTP-Posting-Host: 69.20.190.126 References: <0114d327-9f9f-4ad2-9281-56331d11a90c@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <3b23fc65-f5d0-422a-89e8-94e3c374f7ca@googlegroups.com> Subject: Re: Ada202X : Adding functors From: Shark8 Injection-Date: Tue, 13 Nov 2012 04:22:58 +0000 Content-Type: text/plain; charset=ISO-8859-1 Date: 2012-11-12T20:22:58-08:00 List-Id: On Monday, November 12, 2012 3:09:15 PM UTC-7, 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 support it - or can someone tell me I'm wrong? > > I think it could be done by 'simply' allowing something like this: > > package P is > type T is tagged ...; > function Create return T; > procedure "()" (This : T; I : Integer); -- The functor call > function "()" (This : T) return Integer; -- Alternative functor that's a function > private > ... > end P; > > with P; > procedure Demo is > My_T : P.T := P.Create > begin > My_T (42); -- call to procedure version > if My_T () > 100 then ... end if; -- call to function version > end Demo; Er, why? Couldn't you use operator overloading, generic packages, etc to do it? Type NR is null record; Generic Type T; With Function "+"( Left: in out T; Right: Integer ) Return NR; With Function "+"( Item: T ) Return Integer; Package K is End K; Then use K as a signature package for your actual usages. Also, you could eliminate NR and use a procedure instead, calling it 'Add' or something.