comp.lang.ada
 help / color / mirror / Atom feed
From: jan.de.kruyf@gmail.com
Subject: Re: Why does that work?
Date: Thu, 5 Mar 2015 11:13:47 -0800 (PST)
Date: 2015-03-05T11:13:47-08:00	[thread overview]
Message-ID: <84f081dc-3d9d-4229-9b83-82854621e8de@googlegroups.com> (raw)
In-Reply-To: <ea515d02-1155-44ba-b111-fab3cb2b637c@googlegroups.com>

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.


  reply	other threads:[~2015-03-05 19:13 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-03 22:36 Why does that work? Laurent
2015-03-04  5:51 ` Laurent
2015-03-04 15:46   ` David Botton
2015-03-04 17:35     ` Simon Wright
2015-03-04 18:38       ` Laurent
2015-03-05 19:13         ` jan.de.kruyf [this message]
2015-03-05 21:16           ` Laurent
2015-03-06  0:51             ` Ada Video Course David Botton
2015-03-06 15:42               ` Jacob Sparre Andersen
2015-03-06 17:01                 ` G.B.
2015-03-06 21:17                 ` David Botton
2015-03-06  6:20             ` Why does that work? jan.de.kruyf
2015-03-06 13:28               ` Laurent
2015-03-06 14:07                 ` G.B.
2015-03-06 14:24                   ` jan.de.kruyf
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox