From: Laurent <daemon2@internet.lu>
Subject: Why does that work?
Date: Tue, 3 Mar 2015 14:36:59 -0800 (PST)
Date: 2015-03-03T14:36:59-08:00 [thread overview]
Message-ID: <7ffd1bf0-b815-474d-a4f2-cf471db0be37@googlegroups.com> (raw)
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
next reply other threads:[~2015-03-03 22:36 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-03 22:36 Laurent [this message]
2015-03-04 5:51 ` Why does that work? 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
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