comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: anonymous access type
Date: Wed, 04 Mar 2009 18:54:52 -0500
Date: 2009-03-04T18:54:52-05:00	[thread overview]
Message-ID: <wcck574x2r7.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: d1fb109a-13d6-4884-9e71-304a58c46e62@w9g2000yqa.googlegroups.com

Maciej Sobczak <see.my.homepage@gmail.com> 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



  parent reply	other threads:[~2009-03-04 23:54 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-03 12:25 anonymous access type Maciej Sobczak
2009-03-03 12:40 ` christoph.grein
2009-03-03 12:44   ` christoph.grein
2009-03-03 13:15     ` Maciej Sobczak
2009-03-03 13:43 ` Jean-Pierre Rosen
2009-03-05  0:00   ` Robert A Duff
2009-03-03 21:03 ` sjw
2009-03-03 22:35   ` Adam Beneschan
2009-03-04  5:47     ` christoph.grein
2009-03-04 16:01       ` Robert A Duff
2009-03-05  1:44         ` Randy Brukardt
2009-03-05  8:52           ` christoph.grein
2009-03-05 11:08             ` Hibou57 (Yannick Duchêne)
2009-03-04  8:30   ` Maciej Sobczak
2009-03-04 23:54 ` Robert A Duff [this message]
2009-03-05  8:14   ` Ludovic Brenta
2009-03-05 16:27     ` Rob Norris
2009-03-05 17:51       ` Hibou57 (Yannick Duchêne)
2009-03-09 11:40         ` Rob Norris
2009-03-05 20:25       ` sjw
2009-03-06 12:49         ` Stephen Leake
2009-03-05  8:38   ` Hibou57 (Yannick Duchêne)
2009-03-05 15:05     ` Robert A Duff
2009-03-05 15:18       ` Dmitry A. Kazakov
2009-03-05 17:50       ` Hibou57 (Yannick Duchêne)
2009-03-05 18:35         ` Adam Beneschan
2009-03-06  0:52           ` Hibou57 (Yannick Duchêne)
2009-03-06 16:25             ` Adam Beneschan
replies disabled

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