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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,e94a7e4f6f888766 X-Google-Attributes: gid103376,public From: "Matthew Heaney" Subject: Re: Self-referential types Date: 1999/10/12 Message-ID: <3802f2db_2@news1.prserv.net>#1/1 X-Deja-AN: 535732202 Content-transfer-encoding: 7bit References: <7ttb4a$8mq$1@nnrp1.deja.com> Content-Type: text/plain; charset="US-ASCII" X-Complaints-To: abuse@prserv.net X-Trace: 12 Oct 1999 08:35:39 GMT, 129.37.62.16 Organization: Global Network Services - Remote Access Mail & News Services Mime-version: 1.0 Newsgroups: comp.lang.ada Date: 1999-10-12T00:00:00+00:00 List-Id: In article , "Vladimir Olensky" 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. This is something a lot of programmers haven't learned yet. 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); --!!! 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. > Access attributes can not be applied to type. Wrong. > It may only be applied to some object but not to its description. Wrong. > Also compiles are probably giving misleading error messages. No, the compiler was correct. -- The new standards [for science curricula in Kansas] do not forbid the teaching of evolution, but the subject will no longer be included in statewide tests for evaluating students--a virtual guarantee, given the realities of education, that this central concept of biology will be diluted or eliminated, thus reducing courses to something like chemistry without the periodic table, or American history without Lincoln. Stephen Jay Gould, Time, 23 Aug 1999