comp.lang.ada
 help / color / mirror / Atom feed
From: "Norman H. Cohen" <ncohen@watson.ibm.com>
Subject: Re: Modest proposal, 2 of 3
Date: 1996/11/25
Date: 1996-11-25T00:00:00+00:00	[thread overview]
Message-ID: <3299FA03.5A1D@watson.ibm.com> (raw)
In-Reply-To: 575ag6$rt6@netline-fddi.jpl.nasa.gov


Van Snyder wrote:

> PROPOSAL for next standardization of Ada
> 
> Allow objects to be declared in the public part of a package
> specification with mode "out".  The meaning is that clients of the
> package can reference the variable, but can't store into it.

Somewhat confusing since generic formal parameters of mode IN indicate
that the generic parameter is to be bound to some constant value, and a
subprogram parameter of mode IN is constant within the subprogram body. 
So perhaps instead of

   X: out Integer;

the notation should be

   X: Integer constant when not private;   -- ;-)

> Thus, a variable that a package publishes with "out" mode has the same
> properties as a private variable with a public parameterless function to
> access it, and no procedure to update it directly.  But it's more
> efficient, and there's less code to write initially, and therefore less
> to read and understand when you're the poor schmo assigned to make the
> next minor change.

The effect of an object modifiable as a variable from within a package,
but only readable as a constant from outside the package, can already be
achieved in Ada 95 as follows:

   package P is
      type Access_Constant is access constant Integer;
      Constant_View_Of_Variable: constant Access_Constant;
   private
      Variable: aliased Integer;
      Constant_View_Of_Variable:
         constant Access_Constant := Variable'Access;
   end P;

Of course this doesn't quite achieve the referential transparency Van
Snyder is after, because it requires you to say
Constant_View_Of_Variable.all instead of Constant_View_Of_Variable.

-- 
Norman H. Cohen
mailto:ncohen@watson.ibm.com
http://www.research.ibm.com/people/n/ncohen




  parent reply	other threads:[~1996-11-25  0:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-11-22  0:00 Modest proposal, 2 of 3 Van Snyder
1996-11-23  0:00 ` Robert Dewar
1996-11-25  0:00 ` Norman H. Cohen [this message]
1996-11-26  0:00   ` Ken Garlington
1996-11-28  0:00   ` Richard A. O'Keefe
1996-11-26  0:00 ` Tucker Taft
replies disabled

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