From: Javi on
Hi again, I have some problem between access assignations. "List" has
in its definition a private access to ListNode (First, Last). Why
can't I do the assignation: L.List := L.Last ? it does produce an
"accessibilty error check". If both values are null, I can not either
do the assignation.

-----------
....
procedure putItem (L : in out List; It : in ItemList) is
begin
if L.Last = null then
L.Last := new ListNode'(Item => It, next => null);
print(L.Last.Item); --DBG this prints OK, the Item was
properly assigned
L.First := L.Last; -- this fails, L.First and L.Last are both
the same type access ListNode
....
----------


I'm very sorry because of bothering you with this simple questions,
thanks again.
From: Robert A Duff on
Javi <fjvera(a)gmail.com> writes:

> Hi again, I have some problem between access assignations. "List" has
> in its definition a private access to ListNode (First, Last). Why
> can't I do the assignation: L.List := L.Last ? it does produce an
> "accessibilty error check". If both values are null, I can not either
> do the assignation.
>
> -----------
> ...
> procedure putItem (L : in out List; It : in ItemList) is
> begin
> if L.Last = null then
> L.Last := new ListNode'(Item => It, next => null);
> print(L.Last.Item); --DBG this prints OK, the Item was
> properly assigned
> L.First := L.Last; -- this fails, L.First and L.Last are both
> the same type access ListNode
> ...
> ----------
>
>
> I'm very sorry because of bothering you with this simple questions,
> thanks again.

No need to apologize -- your question is a reasonable one. But you're
more likely to get an answer if you post a complete compilable example,
and explain in detail what "this fails" means.

- Bob
From: Jeffrey R. Carter on
Javi wrote:
> L.Last := new ListNode'(Item => It, next => null);
> L.First := L.Last; -- this fails, L.First and L.Last are both
> the same type access ListNode

I suspect you're saying that type List has components such as

type List is record
First : access Listnode;
Last : access Listnode;
...
end record;

The solution is simple: Don't use anonymous types. Use a named type instead:

type Node_Ptr is access Listnode; -- Using '_' is The Ada Way.

type List is record
First : Node_Ptr;
Last : Node_Ptr;
...
end record;

Anonymous types are a horrible thing and should be avoided whenever possible.

--
Jeff Carter
"Sir Robin the-not-quite-so-brave-as-Sir-Lancelot,
who had nearly fought the Dragon of Angnor,
who nearly stood up to the vicious Chicken of Bristol,
and who had personally wet himself at the
Battle of Badon Hill."
Monty Python & the Holy Grail
68
From: Stephen Leake on
"Jeffrey R. Carter" <spam.jrcarter.not(a)acm.nospam.org> writes:

> Javi wrote:
>> L.Last := new ListNode'(Item => It, next => null);
>> L.First := L.Last; -- this fails, L.First and L.Last are both
>> the same type access ListNode
>
> I suspect you're saying that type List has components such as
>
> type List is record
> First : access Listnode;
> Last : access Listnode;

In particular, these are _not_ the "same type". In C, they would be,
because there "same type" means "same contents". In Ada, "same type"
means "same name". The types here have _no_ name; they are
anonymous. So they are not the same.

--
-- Stephe