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=-2.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,ecfc0548c2df0d76,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-11-06 08:35:30 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.stueberl.de!teaser.fr!enst.fr!melchior!cuivre.fr.eu.org!melchior.frmug.org!not-for-mail From: "amado.alves" Newsgroups: comp.lang.ada Subject: MI ammunition : linked lists Date: Thu, 6 Nov 2003 16:32:16 -0000 Organization: Cuivre, Argent, Or Message-ID: NNTP-Posting-Host: lovelace.ada-france.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Trace: melchior.cuivre.fr.eu.org 1068136384 33951 80.67.180.195 (6 Nov 2003 16:33:04 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Thu, 6 Nov 2003 16:33:04 +0000 (UTC) To: Return-Path: X-MimeOLE: Produced By Microsoft Exchange V6.0.6470.0 Content-Class: urn:content-classes:message X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: MI ammunition : linked lists thread-index: AcOkg4p9WicfHKS0RRaBk2WPdLGG0g== X-OriginalArrivalTime: 06 Nov 2003 16:32:21.0811 (UTC) FILETIME=[8D7F5830:01C3A483] X-Virus-Scanned: by amavisd-new-20030616-p5 (Debian) at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Gateway to the comp.lang.ada Usenet newsgroup List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Xref: archiver1.google.com comp.lang.ada:2151 Date: 2003-11-06T16:32:16+00:00 A very common programming task where multiple inheritance (MI) would be = handy: implementation of doubly linked lists. A linked list is a chain of nodes. The first node links to the second, = the last node links to the penultimate, and each of the others nodes = links to both the previous and the next. (Each node usually also carries = a payload, which we can ignore here.) First <-----> Second <-----> ... <-----> Penultimate <-----> Last Often (always?) a non OOP design is used with only one type for all = kinds of nodes, with null values in the unused slots: ___________ ______ ______ ___________ | | | | | | | | | Prev=3Dnull |<-----Prev |<--- ... <-----Prev |<-----Prev | | Next---------->| Next-----> ... --->| Next----->| Next=3Dnull | |___________| |______| |______| |___________| An OOP design does away with the ugly nulls (however it introduces = one-of-a-kind objects, which also some people consider ugly): ______ ______ ______ ______ | | | | | | | |<-----Prev |<--- ... <-----Prev |<-----Prev | | Next----->| Next-----> ... --->| Next----->|______| |______| |______| |______| =20 It is clear that the middle nodes combine the attributes of the first = and last nodes. This is where linguistic MI could help: type Node is tagged ...; type Node_Ptr is access Node'Class; type First_Node is new Node with record Next : Node_Ptr; end record; type Last_Node is new Node with record Prev : Node_Ptr; end record; type Middle_Node is new First_Node with Last_Node; Of course the alternative is no big deal, syntactically: type Middle_Node is new Node with record Prev : Node_Ptr; Next : Node_Ptr; end record; But, semantically, MI would allow conversions between Middle_Node and = any the other two extended types. Whether this would be useful for = linked lists remains to be ascertained. I confess I have not implemented = them this way yet. Well, just a thought for those with too much free time on their hands = ;-)