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.30.41 with SMTP id j29mr10957695yha.28.1425582828187; Thu, 05 Mar 2015 11:13:48 -0800 (PST) X-Received: by 10.140.31.134 with SMTP id f6mr207484qgf.33.1425582827989; Thu, 05 Mar 2015 11:13:47 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.glorb.com!peer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!hl2no3718838igb.0!news-out.google.com!db6ni44597igc.0!nntp.google.com!hl2no5030151igb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Thu, 5 Mar 2015 11:13:47 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=105.236.22.103; posting-account=orbgeAkAAADzWCTlruxuX_Ts4lIq8C5J NNTP-Posting-Host: 105.236.22.103 References: <7ffd1bf0-b815-474d-a4f2-cf471db0be37@googlegroups.com> <3a73a17d-2c37-47d2-9049-522632c24c15@googlegroups.com> <2a87cf3b-8621-4f5e-89a5-be4045eba583@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <84f081dc-3d9d-4229-9b83-82854621e8de@googlegroups.com> Subject: Re: Why does that work? From: jan.de.kruyf@gmail.com Injection-Date: Thu, 05 Mar 2015 19:13:48 +0000 Content-Type: text/plain; charset=ISO-8859-1 X-Received-Bytes: 3690 X-Received-Body-CRC: 1360526448 Xref: news.eternal-september.org comp.lang.ada:25113 Date: 2015-03-05T11:13:47-08:00 List-Id: On Wednesday, March 4, 2015 at 8:38:58 PM UTC+2, Laurent wrote: > Right. I am always amazed who different my thinking is when I suffer under a f*cking migraine attack. Even if the pain is gone by swallowing some pills but the logic is still suffering :( > > procedure Remove_Node (It : in Iterator) is > Temp : List_Ptr := It.This; > > begin -- Remove_Node > > if It.This = null then -- List is empty or no node found > Ada.Text_IO.Put_Line ("No item to delete"); > > elsif It.This.Previous = null then -- case 1: It = First node > It.L.Head := It.This.Next; > It.This.Next.Previous:= null; > Dispose (X => Temp); > > elsif It.This.Next = null then -- case 2: It = Last node > It.L.Tail := It.This.Previous; > It.This.Previous.Next := null; > Dispose (X => Temp); > > else -- case 3: It is an intermediate node > It.This.Previous.Next := It.This.Next; > It.This.Next.Previous := It.This.Previous; > Dispose (X => Temp); > end if; > end Remove_Node; > > It is this procedure which works differently than I expected. Because I have no direct access to the list L and its head/tail. > > The first one I posted doesn't even need an iterator. > > The first solution I figured out was horrible and allowed something stupid like searching in L3 but trying to delete in L2 : > > GL_Int.Remove_Node (List=> L3'Access, It => Aux_IO.Search (L => L3'Access, Element => Search_For)); > > But using the iterator I have a workaround but I don't understand how that is possible. > > GL_Int.Remove_Node ( It => Aux_IO.Search (L => L3'Access, Element => Search_For)); > > I thought that the iterator is part of the list but that could be wrong. So the list is part of the iterator. Aka it is not the spaceship which moves but the universe around it? (sry couldn't resist citing the explanation from Futurama((tm))). > > So if someone could clarify this. > > play some sweet music while you read this: http://kto.web.elte.hu/teaching/ada/books/ase.pdf After you finished the migraine will be gone _and_ you will have the answer to your question. This version is a bit old, but still it has all you need to know to solve this issue. And it is by a very competent teacher. May peace be with you. j.