🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.ada
Article #1013

Re: parameter passing

#1013
From: Geoff Mendal
Date: Fri, 10 Oct 1986 16:46
68 lines
2747 bytes
The answer to this question can be found in Ichbiah's
"Ada Rationale" draft, which by the way, will be coming
out in published form "soon".  (This word comes from
Ichbiah himself, speaking at a local SIGAda meeting
last Tuesday in Silicon Valley.)  See section 8.2.2
of the "Ada Rationale".  I'll summarize it here for
those who don't have a copy.

Consider the following procedure to delete an element from
a doubly linked list:

  type Element;
  type Ptr is access Element;
  type Element is
    record
      Prev,
      Succ  : Ptr;
      Data  : some_type;
    end record;
  E : Ptr;
  procedure Delete (P : in Ptr) is
  begin
    P.Succ.Pred := P.Pred;
    P.Pred.Succ := P.Succ;
    P.Succ := null;
    P.Pred := null;
  end;

A call to this procedure of the form

  Delete (X);

will work regardless of the parameter passing mechanism.  However,
consider now the call:

  Delete (E.Pred);

where the linked list, before the call, has the state:

  Element:        A  B  C  D  E  F

  succ:           B  C  D  E  F  ...
  pred:          ... A  B  C  D  E

If the parameter passing mechanism is by copy, then the desired
effect is achieved, but pass-by-reference will not work (the list
ends up in a state of "chaos").  You can work out the details
yourself, or see Ichbiah's pictures.

The language designers chose to make pass-by-copy the rule to
eliminate problems such as the one above.  Access types allow
the programmer to create and manage aliases.  It was the view
of the language designers not to have parameter passing create
more aliases of which the programmer is unaware.  Another
problem with pass-by-reference is in achieving the desired
semantics on distributed systems with multiple address spaces.

I'll let you ponder these ideas, and leave you with perhaps a
tangential question (the answer for which is similar to this
question):

  Why, for mode out access type parameters, does Ada require
  copy-in of the actual access value?  Obviously the formal
  cannot read the actual's value, so why require that it be
  copied in?  (somewhat of a trick question)

gom
-------
Technical Details
Message-ID: <12245715934.25.MENDAL@Sierra.Stanford.EDU>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!cmcl2!husc6!think!nike!ucbcad!ucbvax!SIERRA.STANFORD.EDU!Mendal
References: <2736@burdvax.UUCP>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!cmcl2!husc6!think!nike!ucbcad!ucbvax!SIERRA.STANFORD.EDU!Mendal
From: Mendal@SIERRA.STANFORD.EDU (Geoff Mendal)
Newsgroups: net.lang.ada
Subject: Re: parameter passing
Message-ID: <12245715934.25.MENDAL@Sierra.Stanford.EDU>
Date: Fri, 10-Oct-86 12:46:41 EDT
Article-I.D.: Sierra.12245715934.25.MENDAL
Posted: Fri Oct 10 12:46:41 1986
Date-Received: Sat, 11-Oct-86 20:55:18 EDT
References: <2736@burdvax.UUCP>
Sender: daemon@ucbvax.BERKELEY.EDU
Organization: The ARPA Internet
Lines: 68