comp.lang.ada
 help / color / mirror / Atom feed
From: "news.oxy.com" <Vladimir_Olensky@oxy.com>
Subject: Re: Self-referential types
Date: 1999/10/12
Date: 1999-10-12T00:00:00+00:00	[thread overview]
Message-ID: <s06ji18vh1s47@corp.supernews.com> (raw)
In-Reply-To: 3802f2db_2@news1.prserv.net


Matthew Heaney wrote in message <3802f2db_2@news1.prserv.net>...
>In article <s04ql7cqh1s45@corp.supernews.com> , "Vladimir Olensky"
><vladimir_olensky@yahoo.com> wrote:
>
>> How it is  possible to initialize access variable
>> by the initial value that is access attribute to type ?
>
>Yes, of course it's possible to initialize an access object that is an
>access to a type!
>
>For a limited type T, then inside the declaration of the type, the
>expression T'Access refers to the "current instance" of the type.


Very good clarification indeed.

>This is something a lot of programmers haven't learned yet.

Let alone people which primary occupation is not  programming
( as for me my primary occupation is telecommunications).

>This is the basis for programming with access discriminants, which is
>how you do MI in Ada95.
>
>For example:
>
>  type Handle_Type (Stack : access Stack_Type) is
>    limited null record;
>
>  type Stack_Type is
>    limited record
>      Handle : Handle_Type (Stack_Type'Access);  --!!!
>      <other stuff>
>    end record;
>
>
>Here's another example:
>
>  type T is tagged limited private;
>...
>private
>
>  function Do_Get_Default (O : T) return T2;
>
>  function Get_Default (O : T'Class) return T2;
>
>  type T is
>    tagged limited record
>       O : T2 := Get_Default (T'Access);  --!!!
>    end record;
>
>
>Where
>
>  function Get_Default (O : T'Class) return T2 is
>  begin
>    return Do_Get_Default (O);
>  end;
>
>
>This is the idiom you use if you want to let a descendent type change
>the default of component declared by the ancestor.
>


All this is very interesting indeed.
As for me I  never used such thing and was not sure  that it makes any sense
to apply  access attrubute to anything except oject instance.
In other languages there exists "Self" parameter and when it is used in
class declarations it refers to current class instance.

You might  put a short article regarding this issue to Adapower.
I am sure it will be very useful.

>> Access attributes can not be applied to type.
>Wrong.

It is wrong  only for limited types.
For types that are not limited it is true.

>> It may only be  applied to some object but not to its description.
>Wrong.

The same as above.
For non limited types compiler gives you an error message:
------------------------------------------------------
Wrong_Initialization : List_Type := Cell_Type'Access;

test.adb:14:37: "Access" attribute cannot be applied to type
gnatmake: "test.adb" compilation error
-----------------------------------------------------------------
This can make one think that it is always true .
If GNAT would give you additional info  that such
construct could be applied only to limited types this
could make person  to look deeper to that (at least out
of curiosity ).


Again thanks for good  clarification. It is very useful.

Regards,
Vladimir Olensky







  parent reply	other threads:[~1999-10-12  0:00 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <7ttb4a$8mq$1@nnrp1.deja.com>
1999-10-12  0:00 ` Self-referential types Robert A Duff
1999-10-12  0:00 ` Vladimir Olensky
1999-10-12  0:00   ` Matthew Heaney
1999-10-12  0:00     ` Richard D Riehle
1999-10-12  0:00     ` news.oxy.com [this message]
1999-10-12  0:00       ` Matthew Heaney
1999-10-12  0:00       ` Ted Dennison
1999-10-12  0:00         ` Stanley R. Allen
1999-10-13  0:00           ` Ted Dennison
1999-10-13  0:00         ` Vladimir Olensky
1999-10-14  0:00         ` Multiple Inheritance in Ada 95 [was Re: Self-referential types] Tucker Taft
1999-10-12  0:00     ` Self-referential types Ted Dennison
1999-10-12  0:00       ` Matthew Heaney
1999-10-12  0:00     ` Robert I. Eachus
1999-10-12  0:00       ` Matthew Heaney
1999-10-13  0:00         ` Robert I. Eachus
1999-10-13  0:00           ` Brian Rogoff
1999-10-15  0:00             ` Robert I. Eachus
1999-10-15  0:00               ` Marin David Condic
1999-10-15  0:00                 ` Robert I. Eachus
1999-10-18  0:00                   ` Robert Dewar
1999-10-19  0:00                     ` Robert I. Eachus
1999-10-18  0:00               ` Robert Dewar
1999-10-18  0:00                 ` Ed Falis
1999-10-19  0:00                   ` Robert Dewar
1999-10-18  0:00                 ` Brian Rogoff
     [not found]               ` <7u86su$o5v$1@nntp8.atl.mindspring.net>
1999-10-18  0:00                 ` Robert I. Eachus
1999-10-22  0:00                   ` Richard D Riehle
1999-10-22  0:00                     ` Robert I. Eachus
     [not found]               ` <slrn80fl9f.68j.aidan@skinner.demon.co.uk>
1999-10-19  0:00                 ` Wes Groleau
1999-10-21  0:00                   ` Robert Dewar
1999-10-21  0:00                     ` Comments (was: Self-referential types) Wes Groleau
1999-10-21  0:00                       ` Ehud Lamm
1999-10-22  0:00                         ` Ted Dennison
1999-10-23  0:00                           ` Ehud Lamm
1999-10-23  0:00                         ` Robert Dewar
1999-10-23  0:00                           ` Ehud Lamm
1999-10-23  0:00                             ` Comments Georg Bauhaus
1999-10-24  0:00                               ` Comments Ehud Lamm
1999-10-26  0:00                                 ` Comments Robert I. Eachus
1999-10-28  0:00                                   ` Comments Jerry van Dijk
1999-10-28  0:00                                     ` Comments Ted Dennison
1999-10-25  0:00                             ` Comments (was: Self-referential types) Wes Groleau
1999-10-23  0:00                       ` M.
     [not found]                       ` <Pine.A41.3.96-heb-2.07.991021191504.30582K-100000@pluto.mscc.huji. <381477c9.e1388ff3@ftw.rsc.raytheon.com>
1999-10-25  0:00                         ` Larry Kilgallen
1999-10-21  0:00                     ` Self-referential types Larry Kilgallen
1999-10-21  0:00                     ` Jean-Pierre Rosen
1999-10-21  0:00                       ` Robert Dewar
1999-10-22  0:00                     ` Richard D Riehle
1999-10-23  0:00                       ` Robert A Duff
1999-10-23  0:00                         ` Richard D Riehle
1999-10-24  0:00                       ` Michel DELARCHE
1999-10-13  0:00         ` Ted Dennison
1999-10-13  0:00           ` Matthew Heaney
1999-10-13  0:00         ` Vladimir Olensky
1999-10-13  0:00           ` Vladimir Olensky
1999-10-18  0:00           ` Robert Dewar
1999-10-18  0:00             ` Vladimir Olensky
1999-10-18  0:00             ` Laurent Guerby
     [not found] ` <3802597B.9205AEE8@averstar.com>
1999-10-12  0:00   ` Ted Dennison
1999-10-12  0:00     ` Matthew Heaney
1999-10-13  0:00       ` Ted Dennison
replies disabled

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