comp.lang.ada
 help / color / mirror / Atom feed
* Re: Access Discrimnants
@ 1993-06-28  9:23 munnari.oz.au!yoyo.aarnet.edu.au!news.adelaide.edu.au!achilles!andrewd
  0 siblings, 0 replies; 4+ messages in thread
From: munnari.oz.au!yoyo.aarnet.edu.au!news.adelaide.edu.au!achilles!andrewd @ 1993-06-28  9:23 UTC (permalink / raw)


In comp.lang.ada, stt@spock.camb.inmet.com (Tucker Taft) writes:
>In article <20csgf$5tr@huon.itd.adelaide.edu.au>
>  andrewd@achilles.cs.adelaide.edu.au (,2285592, Andrew Dunstan) writes:
[ my question answered]
>>thanks in advance!
>
>You are welcome.
>

Thankyou again, Tucker. As always, you provided a helpful and 
interesting answer to a possibly dumb question.

>
>    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.

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!

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   #                                 #

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Access Discrimnants
@ 1993-06-28 10:12 munnari.oz.au!yoyo.aarnet.edu.au!news.adelaide.edu.au!achilles!andrewd
  0 siblings, 0 replies; 4+ messages in thread
From: munnari.oz.au!yoyo.aarnet.edu.au!news.adelaide.edu.au!achilles!andrewd @ 1993-06-28 10:12 UTC (permalink / raw)


for the purposes of the question I have just posted, please consider
the type Set as private rather than as limited private. Alternatively,
consider that I want to be able to implement the function specified
withing the defining package.

(I just hate follow-up corrections, and here I am doing it myself -
it's been a bad month!)

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   #                                 #

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Access Discrimnants
@ 1993-06-30 15:23 Tucker Taft
  0 siblings, 0 replies; 4+ messages in thread
From: Tucker Taft @ 1993-06-30 15:23 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Access Discrimnants
@ 1993-07-01 13:28 munnari.oz.au!metro!basser.cs.su.oz.au!news.adelaide.edu.au!achilles!andr
  0 siblings, 0 replies; 4+ messages in thread
From: munnari.oz.au!metro!basser.cs.su.oz.au!news.adelaide.edu.au!achilles!andr @ 1993-07-01 13:28 UTC (permalink / raw)


In comp.lang.ada, stt@spock.camb.inmet.com (Tucker Taft) writes:
>In article <20mdas$ps9@huon.itd.adelaide.edu.au>
>  andrewd@achilles.cs.adelaide.edu.au (,2285592, Andrew Dunstan) writes:
[ useful and informative answer to my question]
>>
>>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.
>

Tucker:

Thankyou for once again taking the time to answer my question. I know
how busy you must be, and your unfailing helpfulness is astounding.
Amid all the flame wars etc. in this news group, contributions like
yours are what keep many people like me reading. The Ada community is
surely in your debt, as I am.

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   #                                 #

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1993-07-01 13:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1993-07-01 13:28 Access Discrimnants munnari.oz.au!metro!basser.cs.su.oz.au!news.adelaide.edu.au!achilles!andr
  -- strict thread matches above, loose matches on Subject: below --
1993-06-30 15:23 Tucker Taft
1993-06-28 10:12 munnari.oz.au!yoyo.aarnet.edu.au!news.adelaide.edu.au!achilles!andrewd
1993-06-28  9:23 munnari.oz.au!yoyo.aarnet.edu.au!news.adelaide.edu.au!achilles!andrewd

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