comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Ada202X : Adding functors
Date: Mon, 12 Nov 2012 15:44:39 -0800 (PST)
Date: 2012-11-12T15:44:39-08:00	[thread overview]
Message-ID: <2bb9e5fa-04a2-4073-bca1-1739ce0580f1@googlegroups.com> (raw)
In-Reply-To: <0114d327-9f9f-4ad2-9281-56331d11a90c@googlegroups.com>

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 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;
> 
> 
> 
> I guess one of the trickier bits of adding this would be the possible need to step away from the current Ada convention of not requiring empty parenthesis...but new language revisions always change the 'current' good style...
> 
> Any thoughts?

package P is 
   type T is tagged ...; 
   function Create return T; 
   procedure Call (This : T; I : Integer);  -- The functor call 
   function Call (This : T) return Integer; -- Alternative functor that's   
                                            -- function
private 
... 
end P; 

with P; 
procedure Demo is 
   My_T : P.T := P.Create ;
begin 
   My_T.Call (42);  -- call to procedure version 
   if My_T.Call > 100 then ... end if;  -- call to function version 
end Demo; 


This already works in Ada, and doesn't require any major language changes that would give the ARG headaches about empty parentheses, possible syntax conflicts with user-defined references and indexing, the interpretation of constructs involving function calls that return P.T followed by parentheses, etc., etc., etc.  I'll concede that doing it this way may be considered less "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 function" certainly does seem cool, in a way.  I don't see any other advantage, though.

                         -- Adam



  parent reply	other threads:[~2012-11-12 23:44 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-12 22:09 Ada202X : Adding functors Martin
2012-11-12 23:14 ` Jeffrey Carter
2012-11-12 23:19   ` Martin
2012-11-13 10:45     ` Georg Bauhaus
2012-11-13 12:08       ` Yannick Duchêne (Hibou57)
2012-11-13 12:35       ` Martin
2012-11-12 23:44 ` Adam Beneschan [this message]
2012-11-13  2:11   ` Jeffrey Carter
2012-11-13 11:11   ` Martin
2012-11-14  0:51     ` Adam Beneschan
2012-11-14  8:39       ` Martin
2012-11-14 16:54         ` Adam Beneschan
2012-11-14 18:54           ` Martin
2012-11-14 20:37           ` Dmitry A. Kazakov
2012-11-14 20:57             ` Shark8
2012-11-14 21:31             ` Martin
2012-11-14 22:42               ` Adam Beneschan
2012-11-15  9:27               ` Dmitry A. Kazakov
2012-11-14 21:45             ` Simon Wright
2012-11-14 22:22               ` Martin
2012-11-14 22:27               ` Martin
2012-11-13  4:22 ` Shark8
2012-11-15  0:20 ` sbelmont700
2012-11-15  7:12   ` Martin
2012-11-15 12:21     ` Georg Bauhaus
2012-11-15 12:31     ` Georg Bauhaus
2012-11-15 12:46       ` Martin
2012-11-16  6:15       ` Randy Brukardt
2012-11-15 10:11   ` Dmitry A. Kazakov
2012-11-15 15:52     ` Peter C. Chapin
2012-11-15 17:04       ` Dmitry A. Kazakov
2012-11-15 19:57         ` Georg Bauhaus
2012-11-15 20:39           ` Dmitry A. Kazakov
2012-11-16  0:15             ` Peter C. Chapin
2012-11-16 10:12               ` Georg Bauhaus
2012-11-16  0:01         ` Peter C. Chapin
2012-11-16  6:09           ` Randy Brukardt
2012-11-16 12:35             ` Peter C. Chapin
2012-11-16 18:10               ` Martin
2012-11-16  8:59           ` Dmitry A. Kazakov
2012-11-16 12:20             ` Peter C. Chapin
2012-11-16 17:44               ` Dmitry A. Kazakov
2012-11-18 15:58                 ` Peter C. Chapin
2012-11-15 21:34     ` sbelmont700
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox