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.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.236.45.38 with SMTP id o26mr1437218yhb.32.1425422219252; Tue, 03 Mar 2015 14:36:59 -0800 (PST) X-Received: by 10.140.91.10 with SMTP id y10mr24516qgd.39.1425422219209; Tue, 03 Mar 2015 14:36:59 -0800 (PST) Path: border1.nntp.dca1.giganews.com!nntp.giganews.com!w8no253957qac.0!news-out.google.com!c1ni204qar.1!nntp.google.com!j7no10645375qaq.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Tue, 3 Mar 2015 14:36:59 -0800 (PST) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=83.99.113.5; posting-account=sDyr7QoAAAA7hiaifqt-gaKY2K7OZ8RQ NNTP-Posting-Host: 83.99.113.5 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <7ffd1bf0-b815-474d-a4f2-cf471db0be37@googlegroups.com> Subject: Why does that work? From: Laurent Injection-Date: Tue, 03 Mar 2015 22:36:59 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: number.nntp.giganews.com comp.lang.ada:192405 Date: 2015-03-03T14:36:59-08:00 List-Id: Hi Why does It.L.Head or Tail work? It is of type Iterator defined as: type Iterator (L : access List) is record This : List_Ptr:= null; end record; If It points to the first node in the List L then It.This.Previous = null and if It points to the last node in the List L then It.This.Next = null. The pointers are working only in one direction I think? So if I am the pointer I will never see the head or the tail of the list. Probably a too simple/naive view. So how can It "know" something about the Head or Tail of the List? Is that caused by L: access List? In my test program all the nodes are known at compile time. Didn't have the time to write a test to see what happens if I add one node to the list at runtime. Wouldn't that somehow cause a runtime error or simply not work as intended? Just a small example: procedure Add_To_End (L : access List; Element : in Element_Type) is It : Iterator (L); begin -- Add_To_End if It.L.Head = null then -- List L is empty It.L.Head := new List_Node'(Element, null, null); It.L.Tail := It.L.Head; else It.L.Tail.Next := new List_Node'(Element, null, It.L.Tail); It.L.Tail := It.L.Tail.Next; end if; end Add_To_End; Hm the first time I whine about something working and I didn't expect it :) Thanks Laurent