comp.lang.ada
 help / color / mirror / Atom feed
From: ryer@inmet.UUCP
Subject: Re: Reference Semantics, assignment
Date: 8 Dec 88 17:36:00 GMT	[thread overview]
Message-ID: <124000027@inmet> (raw)
In-Reply-To: 25128@sri-unix.SRI.COM


/* Written  8:07 pm  Dec  6, 1988 by trent@sri-unix.UUCP in inmet:comp.lang.ada */
/* ---------- "Re: Reference Semantics, assignment" ---------- */
In the above article stachour@umn-cs.cs.umn.edu (Paul Stachour) writes:
>In article <3739@hubcap.UUCP> billwolf@hubcap.clemson.edu writes:
>>    OK, we're sold on the benefits of reference semantics.  Let's assume
>>    that "in out" parameters are always passed by reference.  Now why

Actually, :-), LRM 6.2(7, last sentence) states that such an assumption 
is either irrelevant or makes the program erroneous. :-)

>>    should it be impossible for the programmer to choose pass-by-value,
>>    as in "in" and "out" modes?  

Actually, I'd like the programmer to be always able to specify the method
used. (as s/he is likely to know better than the compiler which is
more efficient in some circumstances)

BTW, check the phrasing of LRM 6.2(especially 7&11). It implies to
me that pass by reference is only allowed for arrays, records and
task types (and only at the discretion of the compiler vender). Any
comments on this? I base my statement on LRM 6.2(7): (emphasis mine)
"[Arrays, records and tasks may be passed by copy], *as for scalar
types*. [...] Alternatively, an implementation may acheive these 
effects by reference...". This wording, combined with the qualification
"For parameters of array and record types" in LRM 6.2(11), leads me
to believe that pass-by-reference is verboten for scalar variables.
If this was not the intent, I would suggest a rewording.

But that aside, I wanted to mention something related to the 
assignment overloading discussion. To wit, many people have pointed
out that source level assignment semantics are not used in parameter
passing. I disagree. First, there are no source level assignment
semantics, as writing an ":=" is not allowed. :-) Assignment semantics
are defined only at the language level in Ada. Second, given this, 
I would argue that even if assignment semantics are not explicitly
called by parameter passing, the effects of Ada parameter passing
are indistinguishable from Ada assignment.

In an assignment, a value is copied to the variable and subtype
checked. In "in" or "in out" parameter passing, a value is 
copied and subtype checked. The effect is exactly as though 
the programmer had typed "<FormalParam> := <ActualParam>" (followed
at return by "<ActualParam> := <FormalParam>" for "in out"s). For
"out" parameters, an ":=" must have been called explicitly. Since
they are equivilent, and since ":=" is not overloadable, I'm not
surprised the LRM didn't state this explicitly...it would be
redundant.

The arguments that assignment should be overloadable seem to revolve 
around the complaint (the valid complaint) that Ada type semantics are 
inadequate. I.e. that the idea of type constraints needs expanding.
(to include user defined constraint checks, which *could* be implemented
as overloaded assignment) Overloading assignment *would* require
that the overloaded assignment be used in parameter passing, but
that is not a significant departure from the current parameter
passing scheme...only from the current assignment scheme.

Now, of course, the problem with this is that the programmer might
"override" type checking with hir assignment operation. I would claim
that writing an assignment operation is the same as providing an
expanded ADT for the type. If the programmer writes an assignment
operator, s/he is *defining* a new semantics for the type. Of course,
this makes proving correctness harder. *Of course*. So does tasking, 
so does unchecked programming, so do generics, so do many other
useful things. 

Now, admittedly, it might be better to allow user-defined constraint
checks for ADTs than to allow overloaded assignment. I suspect that
there would be even more complaints about this suggestion than about
assignment overloading. (one reason for this is that it would require
a whole new syntax) Of course, doing it this way would require that 
type checking be allowed to modify the result and not raise a constraint
error if it felt like it...get's pretty evil, huh? In many ways, 
asking for overloaded assignment is a kludge. It doesn't really solve
the problems with Ada type semantics, it just provides a workaround.

-- 
"Our little lives get complicated
 It's a simple thing
 Simple as a flower
 And that's a complicated thing"                     ../ray\..
/* End of text from inmet:comp.lang.ada */

  reply	other threads:[~1988-12-08 17:36 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1988-11-14 13:20 Ada language revision Stanley Roger Allen, AdaDude
1988-11-15 23:28 ` Wilmer Rivers
1988-11-16 19:06   ` William Thomas Wolfe,2847,
1988-11-17 15:34     ` Stephe Leake
1988-11-18 16:39       ` Steve Tynor
1988-11-18 19:22       ` Ron Guilmette
1988-11-23 22:22       ` William Thomas Wolfe,2847,
1988-11-29 15:35         ` Stephe Leake
1988-11-18  0:32     ` Ron Guilmette
1988-11-22 14:37       ` Stephe Leake
1988-11-23 13:37         ` Dennis Doubleday
1988-11-23 19:41           ` Steve Tynor
1988-11-23 21:14             ` Richard Pattis
1988-11-25 20:36             ` Robert Firth
1988-11-29 15:12           ` limited private types Stephe Leake
1988-12-01 23:06             ` Ron Guilmette
1988-12-05  1:48               ` Paul Stachour
1988-12-05 12:31                 ` Reference Semantics William Thomas Wolfe,2847,
1988-12-06  0:29                   ` Paul Stachour
1988-12-07  1:07                     ` Reference Semantics, assignment overloading, etc Ray Trent
1988-12-08 17:36                       ` ryer [this message]
1988-12-06 16:56               ` limited private types ryer
1988-12-06 20:09               ` stt
1988-12-07 15:51               ` Stephe Leake
1988-11-21 15:40   ` Ada language revision stt
  -- strict thread matches above, loose matches on Subject: below --
1988-11-28 22:19 Collective response to := messages Geoff Mendal
1988-11-29 14:39 ` Dennis Doubleday
1988-11-29 21:08 ` Ray Trent
1988-11-30 14:37   ` Stephe Leake
1988-12-01 14:54     ` David S. Rosenblum
1988-12-02 20:21       ` William Thomas Wolfe,2847,
1988-12-04 21:15         ` David S. Rosenblum
1988-12-04 23:27           ` William Thomas Wolfe,2847,
1988-12-05 14:46             ` David S. Rosenblum
1988-12-05 21:23               ` William Thomas Wolfe,2847,
1988-12-07 17:33                 ` Stephe Leake
1988-12-07 16:03               ` Definition of pass by reference Robert Eachus
1988-12-07 17:15             ` Collective response to := messages Stephe Leake
1988-12-07 16:07       ` Stephe Leake
1988-12-09  3:15         ` David S. Rosenblum
1988-12-01 21:31     ` Ray Trent
1988-12-07 16:21       ` Stephe Leake
1988-11-30 16:29   ` David S. Rosenblum
1988-11-30 18:29     ` William Thomas Wolfe,2847,
1988-11-30 22:28       ` David S. Rosenblum
1988-12-01  3:09         ` William Thomas Wolfe,2847,
1988-12-01 15:16           ` David S. Rosenblum
1988-12-02 19:31             ` William Thomas Wolfe,2847,
1988-12-04 21:03               ` David S. Rosenblum
1988-12-05  2:34                 ` William Thomas Wolfe,2847,
1988-12-05 14:07                   ` David S. Rosenblum
1988-12-07 17:26                     ` Stephe Leake
1988-12-06 19:16                 ` Collective response to := messa stt
1988-12-09  3:39                   ` David S. Rosenblum
1988-11-30 19:13     ` CORRECTION Re: Collective response to := messages David S. Rosenblum
1988-12-01 18:31     ` Ray Trent
1988-12-02 14:49       ` David S. Rosenblum
1988-12-05 17:33         ` Collective response to := messa stt
1988-11-30 18:24   ` Collective response to := messages Robert Eachus
1988-12-02 14:58     ` David S. Rosenblum
1988-12-02 19:34   ` Mark C. Adolph
1988-12-05 17:15     ` Collective response to := messa stt
1988-11-29 21:44 ` Collective response to := messages William Thomas Wolfe,2847,
1989-07-26 20:34 Memory Access Question tony
1989-07-27 13:06 ` richard a hammond
1989-07-27 18:53   ` Ray Trent
1989-07-28  0:48     ` Mike Murphy
1989-08-02 13:23       ` Mike Walsh
1989-08-02 20:20         ` Mike Murphy
1989-07-29  0:00 ` Brian Sullivan
replies disabled

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