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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,de7dd126d6737f3a X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!feedme.ziplink.net!news.swapon.de!newsfeed.straub-nv.de!noris.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Callback in Ada Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <8lc2d0Fb6jU1@mid.individual.net> <4cf0ec67$0$6882$9b4e6d93@newsspool2.arcor-online.net> <393221c0-ac56-436f-b3f8-280c40d5a53a@j1g2000vbl.googlegroups.com> Date: Mon, 29 Nov 2010 12:04:42 +0100 Message-ID: <10p6vzd761rdz$.1gtmc0fk6t9rb.dlg@40tude.net> NNTP-Posting-Date: 29 Nov 2010 12:04:42 CET NNTP-Posting-Host: 9cc8d6fe.newsspool1.arcor-online.net X-Trace: DXC=WY@Q^WDPA6_YQ5E:l On Mon, 29 Nov 2010 02:12:33 -0800 (PST), Maciej Sobczak wrote: > On Nov 29, 9:41�am, "Dmitry A. Kazakov" > wrote: > >>> And now an equivalent example with functions, please. :-) >> >> �� �procedure Foo (Closure : function return Integer); >> �� �function Bar return Integer; >> �� �... >> �� �Foo (Bar); >> >> There is no difference. > > There is. > >> * Ada is not bottom up as C++, it can resolve using the type of the result. > > But here there is no type of the result. Of course there is. The result type is an anonymous procedural type: type is function return Integer; > Bar is not even called, so > there is no result on which you could disambiguate this construct. Yes, it is an object. BTW, the following is legal Ada: package P is type X is (V); end P; package Q is function V return Float; end Q; package body Q is function V return Float is begin return 3.14; end V; end Q; use P, Q; X : Float := V; -- Resolved between P.V and Q.V > In order to make your reasoning complete you would have to introduce > additional way of using function names: > > 1. This way: > > Bar > > would mean that the function is called. The type of result can be used > to disambiguate the overloaded calls. For the brave: watch out > enumerations. > > 2. This way: > > Bar > > would mean that the function is *not* called, but is denoted as a > first-class entity. Yes and both ways already exist in Ada, how otherwise would you be able to take an access to the subprogram: Bar'Access reads #2: use the object Bar and apply 'Access to it. It does not read #1: call Bar and apply 'Access to the result. Once you introduce subprograms as first-class entities in any form (even through pointers), you get the ambiguity. The same happens with referential types, e.g. Ptr as self vs. Ptr as target. There is nothing to do about it. Whatever magic words you would put around Ptr it would never be clear if these apply to Ptr or to Ptr.all, without further premises. The right answer is resolution according to the type. In a typed system the context tells the meaning of the operation. No problem. P.S. In fact Ada had this kind of stuff from the day one. In Ada 83 there were no pointers to subprograms, but it had tasks. We customary used tasks where a program needed as a parameter. Nobody died. P.P.S. As Ada strives to introduce procedural-literals, e.g. conditional expressions, fancy quantified expressions and other awful stuff, it will inevitably require subprogram types, because you cannot get pointer of a literal. What is all this mess worth of if it cannot be given as a parameter? -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de