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: 30 Jun 93 15:23:13 GMT From: agate!howland.reston.ans.net!noc.near.net!inmet!spock!stt@ucbvax.Berkeley .EDU (Tucker Taft) Subject: Re: Access Discrimnants Message-ID: List-Id: In article <20mdas$ps9@huon.itd.adelaide.edu.au> andrewd@achilles.cs.adelaide.edu.au (,2285592, Andrew Dunstan) writes: >> >> type Set is limited private; >> -- Abstract "Set" of Item_Type type >> procedure Add_Item(To : in out Set; Item : Item_Type); >> . . . >> >> type Set_Iterator(Over : access Set) is limited private; >> -- Iterator over a given set, designated by the access discrim > >Given these declarations, can one say something like: > >function some_func(s1,s2 : set) return set is > result : set; > it1 : iterator(s1'access) -- or it2 : iterator(s2'unchecked_access); > >Of course, s1 and s2 could be copied to local aliased sets, but that >would seem to be a bit of a waste if one were sure no dangling >references would be created. You cannot take 'Access of a formal parameter, unless it is of a tagged type. Hence, you will have to make it visible that Set is a tagged type. [Aside: The reason we restrict 'Access on formals to tagged types is that most other types can be passed by copy; for tagged types we require pass-by-reference.] As you mentioned in your followup, you will probably want to make Set a nonlimited private type, so you can do assignment, etc. So this now becomes: type Set is tagged private; Internally Set will probably be derived from Finalization.Controlled, so you can define your own Duplicate and Finalize operations (for assignment and scope exit). Another issue is that access discriminants give read-write access to their designated objects. Hence, you can't initialize one with a pointer to a constant (and IN parameters are considered constants). So you will have to make the parameters IN OUT mode, which means you have to change over to a procedure (since functions can't have IN OUT parameters). An alternative solution to both of the above problems is to use access parameters for the function to begin with: function Some_Func(S1, S2 : access Set) return Set is Result : Set; It1 : Iterator(S1); . . . then you put the 'Access on the call to Some_Func: Print_Set(Some_Func(Set1'Access, Set2'Access)); >Sigh. I'll get the hang of this soon. I just can't wait for GNAT to >come out so that I can start experimenting instead of just reading >and writing and asking questions! Keep those questions coming. Probably many other people have similar questions anyway. >cheers > >andrew > ># Andrew Dunstan # There's nothing good or bad # ># net: # # ># adunstan@steptoe.adl.csa.oz.au # but thinking makes it so. # ># or: andrewd@cs.adelaide.edu.au # # S. Tucker Taft stt@inmet.com Ada 9X Mapping/Revision Team Intermetrics, Inc. Cambridge, MA 02138