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,4ce0ea7d497db907 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nntp.club.cc.cmu.edu!usenet01.sei.cmu.edu!elk.ncren.net!newsswitch.lcs.mit.edu!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: anonymous access type Date: Wed, 04 Mar 2009 18:54:52 -0500 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1236210893 32548 192.74.137.71 (4 Mar 2009 23:54:53 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Wed, 4 Mar 2009 23:54:53 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:tr40PMq/TpaF1Onpeuzm7Pyaq2g= Xref: g2news1.google.com comp.lang.ada:3953 Date: 2009-03-04T18:54:52-05:00 List-Id: Maciej Sobczak writes: > Consider a simple callback protocol: > > procedure Call (Process : not null access procedure); > > This is widely used for example in the containers library (Iterate > operation). Yes, but I don't call that a callback. To me, a "callback" is when you pass a global subprogram, and it's saved in a global data structure, to be "called back" later. For example, when you say "Please call so-and-so procedure when in the future somebody clicks the mouse on the "OK" button". For this, you need a named access type. I call your example a "downward closure", where Call calls Process some number of times, and then Call exits, and then Process is never heard from again. For this, you need an anonymous access type. > Now, being a good citizen, I would like to explicitly stress that the > parameter is passed 'in' instead of relying on implicit mode, so let's > add the 'in' keyword where it belongs: > > procedure Call (Process : in not null access procedure); I disagree that "being a good citizen" means "making things explicit". You should make dangerous or unusual things explicit (like "out" params). "in" params are usual and safe, so should be implicit. It's really a (minor) language design flaw that "in" is allowed but not required. It should be either required or forbidden. (I would prefer forbidden.) As it is, the Ada language has split into three dialects: always say 'in', never say 'in', and say 'in' only for procedures. That's unfortunate. > GNAT says: "anonymous access type definition not allowed here". GNAT is obeying the syntax rules, here. > I cannot find anything in the standard that would explain this. Any > references are welcome. It's in the syntax rules in RM-6.1: 15/2 {AI95-00231-01} parameter_specification ::= defining_identifier_list : mode [null_exclusion] subtype_mark [:= default_expression] | defining_identifier_list : access_definition [:= default_expression] 16 mode ::= [in] | in out | out The "access_definition" case doesn't allow a mode (because it's always 'in'). I'd actually like to change that, by the way, but it's not easy. - Bob