comp.lang.ada
 help / color / mirror / Atom feed
From: madmats@elcgl.epfl.ch
Subject: Re: procedural variables
Date: 16 Feb 91 13:12:32 GMT	[thread overview]
Message-ID: <1991Feb16.141232.1@elcgl.epfl.ch> (raw)
In-Reply-To: 2834@cod.NOSC.MIL


In my opinion, procedure variables were not included in Ada because of the
restrictions that must be placed upon them, making the feature non-ortho-
gonal. Most languages that have procedure variables allow only top-level
(i.e. declared as library units or immediately within library packages)
procedures as their values. This is the case of Modula-2 for instance.
The reason for this restriction is obvious: otherwiswe, a local procedure
might be called in a situation where its context is not present, as in the
following example written in PV-Ada (Ada with proc. variables):

   ...                       

   type Proc is procedure;  -- parameterless

   X : Proc;

   procedure P is

      A : Integer;

      procedure Q is
      begin
         A := A + 1;
      end;
   
   begin
      X := Q;
   end P;

   ...

   P;
   X;  -- this should be a call to P.Q, which makes no sense.

Now one might argue that it is easy to check (at runtime) if X's context 
is present at the moment X is called, but this is not so true because a 
simple check that P is currently being called is not sufficient as
different invocations of P may create different contexts for Q, for 
instance by declaring subtypes with non-static bounds.
This issue of 'dangling subprograms' is treated in more detail in the
context of an object-oriented extension to Ada in Norman Cohen's
report "Ada subtypes as subclasses", which I recommend.

For Ada-9X, I would much prefer an object-oriented extension than support
for procedure variables, because this would greatly extend the expressive
power of the language and would simultaneoulsy provide support for
procedure variables for those who really want them: a procedure value 
would be an object with no data and only one method. To me, a procedure
value not tied to an object does not make much sense.

After all, the 'need' for procedure variables has only
become serious since people have been trying to interface x-toolkits
with Ada (callbacks), but does that mean that callbacks are the right
way of doing it ?

Mats Weber

  reply	other threads:[~1991-02-16 13:12 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1991-02-11 18:04 procedural variables J o s e D u a r t e ! ! !
1991-02-11 21:45 ` Howard Turner
1991-02-12 12:32   ` Matthias Ulrich Neeracher
1991-02-15 18:32     ` Charles H. Sampson
1991-02-16 13:12       ` madmats [this message]
1991-02-19 20:33         ` stephen edwards
1991-02-20 21:02           ` Jim Showalter
1991-02-18  0:28       ` Jim Showalter
1991-02-12 23:04   ` (George C. Harrison) Norfolk State University
  -- strict thread matches above, loose matches on Subject: below --
1991-02-14 19:08 stt
1991-02-24 21:18 Erland Sommarskog
replies disabled

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