comp.lang.ada
 help / color / mirror / Atom feed
From: Laurent <daemon2@internet.lu>
Subject: Re: Why does that work?
Date: Wed, 4 Mar 2015 10:38:54 -0800 (PST)
Date: 2015-03-04T10:38:54-08:00	[thread overview]
Message-ID: <ea515d02-1155-44ba-b111-fab3cb2b637c@googlegroups.com> (raw)
In-Reply-To: <lyy4nc1x8m.fsf@pushface.org>

On Wednesday, March 4, 2015 at 6:35:55 PM UTC+1, Simon Wright wrote:
> David Botton writes:
> 
> >> Ah great again a case of the lights are on but nobody at home.
> >
> > Rude.
> 
> I think OP is allowed to be rude about himself!

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.

Thanks

Laurent


  reply	other threads:[~2015-03-04 18:38 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 [this message]
2015-03-05 19:13         ` jan.de.kruyf
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