From: daicrkk@googlemail.com
Subject: Overloading operator “=” for anonymous access types?
Date: Fri, 11 Jan 2019 13:46:22 -0800 (PST)
Date: 2019-01-11T13:46:22-08:00 [thread overview]
Message-ID: <167dc83d-daac-49eb-ba79-48866ccde39d@googlegroups.com> (raw)
I am working my way through Barnes' excellent Ada book. This is a code sample for deep comparison of linked lists from section 11.7:
type Cell is
record
Next: access Cell;
Value: Integer;
end record;
function "=" (L, R: access Cell) return Boolean is
begin
if L = null or R = null then -- universal =
return L = R; -- universal = (Line A)
elsif L.Value = R.Value then
return L.Next = R.Next; -- recurses OK (Line B)
else
return False;
end if;
end "=";
I can't seem to wrap my head around why in Line A operator "=" of the universal_access type is called (because of the preference rule), on Line B, however, the user-defined operator "=" is called (which makes recursion possible in the first place), this time with no preference for operator "=" of universal_access.
Both L and R, as well as L.Next and R.Next are of the same anonymous type "access Cell". Why the difference in "dispatching"? Does it have to do with L and R being access parameters? If so, what is the rule there?
I did my best to find anything in the AARM, especially section 4.5.2, but could not make any sense of it.
Cheers.
next reply other threads:[~2019-01-11 21:46 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-11 21:46 daicrkk [this message]
2019-01-12 9:50 ` Overloading operator “=” for anonymous access types? Simon Wright
2019-01-12 14:01 ` Simon Wright
2019-01-12 15:15 ` daicrkk
2019-01-14 23:08 ` Overloading operator "=" " Randy Brukardt
2019-01-15 0:34 ` Shark8
2019-01-15 8:38 ` Dmitry A. Kazakov
2019-01-15 21:00 ` Randy Brukardt
2019-01-16 15:42 ` Dmitry A. Kazakov
2019-01-15 8:51 ` daicrkk
2019-01-15 11:15 ` Simon Wright
2019-01-17 3:20 ` Jere
2019-01-17 8:23 ` Dmitry A. Kazakov
2019-01-17 22:22 ` Randy Brukardt
2019-01-18 10:17 ` Dmitry A. Kazakov
2019-01-18 13:27 ` Jere
2019-01-18 13:42 ` Dmitry A. Kazakov
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox