From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 17 Oct 92 23:32:09 GMT From: noc.near.net!inmet!spock!stt@uunet.uu.net (Tucker Taft) Subject: Re: User-defined assignment Message-ID: <1992Oct17.233209.16059@inmet.camb.inmet.com> List-Id: In article <1992Oct17.175730.17448@software.org> smithd@software.org (Doug Smith) writes: > . . . >Unfortunately, if user-defined assignment is not available, >the guidelines explaining how to do memory management and >garbage collection will be pretty sparce (as in Ada). There >is no need to explain the correct way to use a feature that >doesn't exist. I should probably clarify that Ada 9X *does* provide support for user-defined initialization and finalization. This is provided for all limited types that are derivatives (direct or indirect) of a predefined tagged type System.Controlled. The operations are called Initialize and Finalize, and are called at the "appropriate" time. However, since this is restricted to "limited" types, the user must define their own "Assign" procedure (or equivalent) rather than rely on ":=". Therefore, this sort of user-defined assignment is supported, and Initialize and Finalize work correctly, in the presence of exceptions and abort. (What this means is that Finalize is performed on an object if and only if Initialize is performed on the object, and both Initialize and Finalize defer abort until they complete, once they get started.) However, a more complete kind of support for user-defined assignmet would allow the user to simply use the ":=" operation, and have it invoke user-defined code. Unfortunately, this is only the tip of the iceberg. Assignment is used implicitly in subprogram calls for by-copy parameters, in creating aggregates, in explicit and implicit initialization, on function return, in assignment for composite types, etc. By restricting user-defined finalization to limited types, we avoid all of this hairy stuff, though the programmer can still implement roughly equivalent operations using explicit subprograms. E.g., Assign for assignment statements, Copy for explicit copying, Make for constructing a value (like an aggregate), and discriminants for controlling the Initialize procedure. Of course, this is not as friendly or flexible as being able to define ":=" for any type, and having it used automatically everywhere it is appropriate. However, it is significantly easier to implement, while still giving the user the essential capability of control over initialization and finalization, which are sufficient to implement memory management and garbage collection. So the question is how much Ada implementor expense and effort is justified relative to the benefits of the additional friendliness and flexibility. Will this have the tendency to make Ada compilers even more complex and expensive, or is there some straightforward approach that can be implemented at reasonable cost that will provide sufficient benefit. >Doug Smith >smithd@software.org S. Tucker Taft stt@inmet.com Ada 9X Mapping/Revision Team ada9x-mrt@inmet.com (don't forget !topic) Intermetrics, Inc. Cambridge, MA 02138