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: "Robert I. Eachus" Subject: Re: Self-referential types Date: 1999/10/12 Message-ID: <3803B5E3.F96A6DD4@mitre.org>#1/1 X-Deja-AN: 535994786 Content-Transfer-Encoding: 7bit References: <7ttb4a$8mq$1@nnrp1.deja.com> <3802f2db_2@news1.prserv.net> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@news.mitre.org X-Trace: top.mitre.org 939766965 9932 129.83.41.77 (12 Oct 1999 22:22:45 GMT) Organization: The MITRE Corporation Mime-Version: 1.0 NNTP-Posting-Date: 12 Oct 1999 22:22:45 GMT Newsgroups: comp.lang.ada Date: 1999-10-12T22:22:45+00:00 List-Id: Matthew Heaney wrote: > 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. I have to butt in here. It may be how you do MI in Ada, and it is one way, but I find it ugly. If you treat a private access type as the object, then you have to do a bit more work inside the package, but the exterior looks much cleaner, and the users don't have to use 'Access at all. (Often you don't need it inside the package either.) The linked list example becomes: generic type Element is private; --or limited private package Lists is type List is private; procedure Append(L: in out List; E: in Element); procedure Prepend(L: in out List; E: in Element); procedure Pop(L: in out List; E: out Element); function Is_Empty(L: List) return Boolean; function First(L: List) return Element; function Last(L: List) return Element; -- etc private type Real_List_Element; type List is access all List; type Real_List_Element is record E: Element; -- if Element is limited private, you need to declare another access -- type and use it here. Next, Previous: List; end record; end Lists; -- Robert I. Eachus with Standard_Disclaimer; use Standard_Disclaimer; function Message (Text: in Clever_Ideas) return Better_Ideas is...