comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: point by point advantages of Ada
Date: Tue, 7 Jan 2003 13:34:35 -0600
Date: 2003-01-07T13:34:35-06:00	[thread overview]
Message-ID: <v1maut4scctn6c@corp.supernews.com> (raw)
In-Reply-To: y9qS9.98932$hK4.8017421@bgtnsc05-news.ops.worldnet.att.net

James S. Rogers wrote in message ...
>"David Thompson" <david.thompson1@worldnet.att.net> wrote in message
>news:24oS9.30853$p_6.2594702@bgtnsc04-news.ops.worldnet.att.net...
>> Ada uses return type to resolve overloading (at compile time), but
>> not to dispatch (possibly at run time).  (C++ and Java do neither.)
>
>Quoting from "Ada as a Second Language" by Cohen:
>"If a primitive function of a type T has a result of type T, but no
parameters
>of type T or access T, a call on the function can be either
nondispatching or
>dispatching depending on the context."
>
>This is clearly more than simple overload resolution.

But it's not quite dispatching on the tag of the result (which you can't
know). But it is dispatching on the tag of result that you need. Here is
a quick example of it:

      type T is tagged ...
      function Build_It (I : in Integer) return T; --(1)
      procedure Copy (Target : out T; Source : in T);

      type NT is new T ...
      function Build_It (I : in Integer) return NT; --(2)
      type NNT is new T ...
      function Build_It (I : in Integer) return NNT; --(3)


      procedure Do_Something (Obj : in out T'Class) is
      begin
           ...
           Copy (Obj, Build_It(10)); -- Here is the dispatching on
result type.
           ...
      end Do_Something;

This call to Copy is dispatching. The first parameter is dynamically
tagged, and the second is tag-indeterminate. Since Build_It has no
dispatching parameters, it takes the tag to dispatch on from the
enclosing call of Copy (RM 3.9.2(18)). That means that if the tag of Obj
is T, then Build_It (1) is called, if Obj is NT, then Build_It (2) is
called, and so on.

This is convinient for constructor functions, because it means that the
right one will automatically be called in a dispatching context. It also
means that the tag check (which insures that both operands have the
correct tag) can't fail for this call, so Constraint_Error can't be
raised by this call. OTOH, I've never actually used this capability in
practice.

                 Randy Brukardt.






  reply	other threads:[~2003-01-07 19:34 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-26 21:57 point by point advantages of Ada Russ
2002-12-27 10:54 ` Ingo Marks
2002-12-27 21:11   ` Keith Thompson
2002-12-27 21:31     ` Robert A Duff
2002-12-29 18:31 ` Colin Paul Gloster
2002-12-29 20:09   ` James S. Rogers
2003-01-06 23:13     ` David Thompson
2003-01-07  1:35       ` James S. Rogers
2003-01-07 19:34         ` Randy Brukardt [this message]
2003-01-07 21:53           ` Warren W. Gay VE3WWG
2003-01-08  0:36             ` Richard Riehle
2003-01-08 17:50               ` Warren W. Gay VE3WWG
2003-01-08 20:31             ` Randy Brukardt
2003-01-13 16:37               ` Mark Biggar
2002-12-29 21:56   ` Hyman Rosen
2002-12-29 22:30     ` John R. Strohm
2002-12-29 23:16       ` Hyman Rosen
2003-01-02 14:24         ` Wes Groleau
2003-01-03  8:20           ` Hyman Rosen
2003-01-03 14:00             ` Wes Groleau
2003-01-08 20:55               ` Georg Bauhaus
2002-12-29 19:20 ` chris.danx
replies disabled

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