From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.7 required=5.0 tests=BAYES_00,INVALID_DATE, MSGID_SHORT,REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!utgpu!attcan!uunet!lll-winken!lll-tis!ames!mailrus!eecae!netnews.upenn.edu!rutgers!gatech!hubcap!billwolf From: billwolf@hubcap.clemson.edu (William Thomas Wolfe,2847,) Newsgroups: comp.lang.ada Subject: Re: Garbage Collection Message-ID: <3917@hubcap.UUCP> Date: 15 Dec 88 19:13:41 GMT References: <4159@enea.se> Sender: news@hubcap.UUCP Reply-To: billwolf@hubcap.clemson.edu List-Id: >From article <4159@enea.se>, by sommar@enea.se (Erland Sommarskog): > But you have to write the same boring code for [destroying] > every ADT you implement! If there were an ability to iterate over the fields of a generic record parameter, standard generics for recursively destroying certain classes of structures (e.g., n-ary trees) could be written, thus automating the process to some extent. The reason we must suffer writing the same code repeatedly is that Ada does not permit us to abstract over arbitrary record structures. > Let's say that you write a package for double-linked lists. You provide > a procedure for taking an element out of a list. Should you free the > memory allocated? You don't know because the caller may or may not still > keep an reference to the element. He may be totally uninterested in it, > but he may also want to insert it in another list. When the list is instantiated, the user tells us what type of object is to be kept in the list, and provides us with procedures for assignment and equality. Objects are copied into and out of the list. When an object is to be removed from the list, the local copy of the object which is stored within the list is destroyed. Now if the user wants, a pointer type can be supplied as the type of object to be listed, and the user-supplied equality function can compare the objects pointed to rather than the pointers themselves. The user then bears all responsibility for managing the "external storage", and can track his/her own references. There is no implementor's dilemma here whatsoever. Bill Wolfe wtwolfe@hubcap.clemson.edu