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: a07f3367d7,26a21b9e317dc639 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.66.86.102 with SMTP id o6mr3769911paz.41.1354016299391; Tue, 27 Nov 2012 03:38:19 -0800 (PST) MIME-Version: 1.0 Path: s9ni14346pbb.0!nntp.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!novia!news-hub.siol.net!news.mi.ras.ru!goblin3!goblin1!goblin2!goblin.stu.neva.ru!aioe.org!news.ecp.fr!news.jacob-sparre.dk!munin.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Access type to member procedure of instance (Object Oriented programming in Ada) Date: Mon, 19 Nov 2012 17:59:06 -0600 Organization: Jacob Sparre Andersen Research & Innovation Message-ID: References: <9b0bcb37-8ae3-440f-af4f-a796702e4250@googlegroups.com> NNTP-Posting-Host: static-69-95-181-76.mad.choiceone.net X-Trace: munin.nbi.dk 1353369552 12168 69.95.181.76 (19 Nov 2012 23:59:12 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Mon, 19 Nov 2012 23:59:12 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 X-RFC2646: Format=Flowed; Original Date: 2012-11-19T17:59:06-06:00 List-Id: wrote in message news:9b0bcb37-8ae3-440f-af4f-a796702e4250@googlegroups.com... >Not sure if this has already been discussed but: Is it possible to define a >pointer to > a member procedure of an instance? > >This problem has it's origin in the implementation of the MVC pattern for a >GtkAda application. >Consider the following: > >package Some_Package is > > type Message_Type is tagged null record; > > procedure Print(Message : Message_Type); > >end Some_Package; > >package body Some_Package is > > procedure Print (Message : Message_Type) is > begin > null; > end Print; > >end Some_Package; > >Then it is possible to create the following Main application that compiles >just fine: > >with Some_Package; >procedure Main is > Message : Some_Package.Message_Type; >begin > Message.Print; >end Main; > >Is it possible to create a parameterless access type to the Message.Print >procedure? >The following application refuses to compile: > >with Some_Package; >procedure Main is > Message : Some_Package.Message_Type; > > Method_Ref : access procedure := Message.Print'Access; >begin > Method_Ref; >end Main; > >The error message is: no selector "Print" for type "Message_Type" defined >at some_package.ads:3 I think this should work; if it doesn't, the error has something to do with conventions. So there is probably a compiler bug here. The "name" (Ada synax terminology) "Message.Print" represents a parameterless procedure, and can be used in the same way as other parameterless procedures. In particular, it can be renamed as a parameterless procedure: procedure P renames Message.Print; I'm not certain what the convention of this procedure is (it might be defined to be "intrinsic" somewhere, in which case you couldn't take 'Access to it, I can't find such a rule on a quick check of the RM). But it surely exists and should not report that "selector "Print" doesn't exist. In any case, our intent is that one could use this just like any other procedure with the same profile. You can rename it, pass it as a formal subprogram, call it of course, etc. So I would expect 'Access to work as well, unless the RM explicitly says it does not. Randy. P.S. I don't know what everyone else is talking about here; it's *obvious* ;-) that this should work in Ada and all other programming languages with similar constructs. (Please make careful note of the smiley here.)