comp.lang.ada
 help / color / mirror / Atom feed
* Overloading operator “=” for anonymous access types?
@ 2019-01-11 21:46 daicrkk
  2019-01-12  9:50 ` Simon Wright
  0 siblings, 1 reply; 17+ messages in thread
From: daicrkk @ 2019-01-11 21:46 UTC (permalink / 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.

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2019-01-18 13:42 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-11 21:46 Overloading operator “=” for anonymous access types? daicrkk
2019-01-12  9:50 ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox