comp.lang.ada
 help / color / mirror / Atom feed
* Overloading of assignment
@ 1988-11-25 12:09 Mats Weber
  1988-11-26 19:59 ` William Thomas Wolfe,2847,
  0 siblings, 1 reply; 4+ messages in thread
From: Mats Weber @ 1988-11-25 12:09 UTC (permalink / raw)



The question of what an overloaed assignment procedure should look like still
remains:

  variant A:

  procedure ":=" (OBJECT : out SOME_LIMITED_TYPE;
                  VALUE  : in  SOME_LIMITED_TYPE);

  variant B:

  procedure ":=" (OBJECT : in out SOME_LIMITED_TYPE;
                  VALUE  : in     SOME_LIMITED_TYPE);

The problem with variant A is that if SOME_LIMITED_TYPE has subcomponents that
are of an access type, then no garbage collection can be performed on OBJECT
before assigning it its new value, because OBJECT cannot be read inside ":=".

The problem with variant B is that it cannot be used for the initialization
of an object (unless SOME_LIMITED_TYPE is an array or record type) because the
actual parameter for OBJECT must have a defined value before the use of ":="
(otherwise the program is erroneous). Consider the following example:

   package ADT is

      type T is limited private;

      procedure ":=" (OBJECT : in out T; VALUE : in T);

      function TO_T (N : INTEGER) return T;

   private

      type T is range 0..1000;

   end ADT;

   with ADT;
   procedure P is

      X : ADT.T;

      use ADT;

   begin
      X := TO_T(7);    -- this call of ":=" is erroneous because X
   end P;              -- is undefined.


Variant A is better if SOME_LIMITED_TYPE is a scalar type,
variant B is better if SOME_LIMITED_TYPE is an array or record type,
both variants work with access types as these always have the initial value
null.

Personally, I think the rules on assignment in Ada cannot be changed if
upward compatibility is to be acheived.

Mats Weber
DI-LITh-EPFL
Swiss Federal Institute of Technology
1015 Lausanne
Switzerland

e-mail : madmats@elma.epfl.ch

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1988-11-29 16:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1988-11-25 12:09 Overloading of assignment Mats Weber
1988-11-26 19:59 ` William Thomas Wolfe,2847,
1988-11-26 20:10   ` William Thomas Wolfe,2847,
1988-11-29 16:01   ` Stephe Leake

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