From: Martin Dowie <martin@re.mo.ve.thedowies.com>
Subject: Re: Pop function
Date: Wed, 14 Dec 2011 18:29:09 -0600
Date: 2011-12-14T18:29:09-06:00 [thread overview]
Message-ID: <778917968345601399.621922martin-re.mo.ve.thedowies.com@news.btinternet.com> (raw)
In-Reply-To: 27517259.83.1323907586856.JavaMail.geo-discussion-forums@yqgn9
"Rego, P." <pvrego@gmail.com> wrote:
> Hello,
>
> Given a list type
> type T_List is
> record
> Next : access T_List;
> Item : Integer;
> end record;
> T_List_Ptr is access T_List;
>
> Is it right to implement a pop function like the following? (Free is an
> Unchecked_Deallocation)
> function Pop (Sender : access T_List) return Integer is
> Current_Sender_Ptr : T_List_Ptr := T_List_Ptr (Sender);
> Current_Item : constant T_List := Sender.Item;
> begin
> if Sender /= null then
> if Sender.Next /= null then
> Current_Sender_Ptr := T_List_Ptr (Current_Sender_Ptr.Next);
> end if;
> Free (Current_Sender_Ptr);
> return Current_Item;
> else
> return 0;
> end if;
> end Pop;
>
> I mean, if I set Current_Sender_Ptr := T_List_Ptr
> (Current_Sender_Ptr.Next), it's equivalent to Sender := Sender.Next?
> (which I could not do directly due to in this case it would not be
> allowed an anonymous reference, right?)
If Sender is null, your in trouble before you get to "begin".
Also, is it really ok to return 0 from an empty list rather than raising an
exception?
What does Sender "point to" on return if the head of the list is removed?
-- Martin
--
-- Sent from my iPad
next prev parent reply other threads:[~2011-12-15 0:29 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-15 0:06 Pop function Rego, P.
2011-12-15 0:29 ` Martin Dowie [this message]
2011-12-15 1:23 ` Rego, P.
2011-12-15 2:08 ` Adam Beneschan
2011-12-15 22:59 ` Martin Dowie
2011-12-16 10:27 ` georg bauhaus
2011-12-15 0:34 ` Jeffrey Carter
2011-12-15 1:35 ` Rego, P.
2011-12-15 2:55 ` Alex Mentis
2011-12-15 3:00 ` Alex Mentis
2011-12-15 3:00 ` Jeffrey Carter
2011-12-15 3:41 ` Rego, P.
2011-12-15 8:38 ` Dmitry A. Kazakov
2011-12-15 19:57 ` Jeffrey Carter
2011-12-15 20:15 ` Dmitry A. Kazakov
2011-12-15 21:02 ` Simon Wright
2011-12-15 21:25 ` Jeffrey Carter
2011-12-16 8:23 ` Dmitry A. Kazakov
2011-12-16 0:31 ` Randy Brukardt
2011-12-15 2:06 ` Adam Beneschan
2011-12-15 3:27 ` Rego, P.
2011-12-15 12:43 ` Simon Wright
2011-12-15 15:54 ` Adam Beneschan
2011-12-15 18:34 ` Simon Wright
2011-12-15 19:14 ` Dmitry A. Kazakov
2011-12-15 16:14 ` Adam Beneschan
2011-12-28 13:04 ` Rego, P.
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox