comp.lang.ada
 help / color / mirror / Atom feed
From: Dmitry A. Kazakov <mailbox@dmitry-kazakov.de>
Subject: Re: Redefining := (was: The "()" operator revisited.)
Date: Mon, 19 Jan 2004 12:33:02 +0100
Date: 2004-01-19T12:33:02+01:00	[thread overview]
Message-ID: <djdn001ohl2n5fq1qfui6094kjkrm1ao3i@4ax.com> (raw)
In-Reply-To: 100gmej9varun91@corp.supernews.com

On Fri, 16 Jan 2004 15:37:27 -0600, "Randy Brukardt"
<randy@rrsoftware.com> wrote:

>"Jeffrey Carter" <spam@spam.com> wrote in message
>news:ltHNb.11315$1e.3373@newsread2.news.pas.earthlink.net...
>> Robert A Duff wrote:
>>
>> > It has to do with mutable record types (defaulted discrims).
>> > That's unfortunate; if you want to redefine ":=" for a non-mutable
>> > type, it's pretty annoying to be told you can't do that because
>> > mutable types exist in the language.
>
>Bob's comment is a bit misleading. The problem is that since mutable types
>exist in the language, you can't redefine ":=" for any types. That occurs
>because of composition issues. You want user-defined ":=" to compose, such
>that a larger type containing a component of a type using user-defined ":="
>uses the user-defined ":=". Now, consider:
>
>     type Something ...
>     procedure ":=" (Target : out Something; Source : in Something);
>
>     type Mutable (B : Boolean := False) is record
>          case B is
>                  when True =>
>                          S : Something;
>                  when False =>
>                          C : Character;
>          end case;
>    end record;
>
>    A_True : Mutable(True);
>    A_False : Mutable(False);
>
>    Obj : Mutable;
>
>    Obj := A_True; -- ??
>
>How does the predefined ":=" for Mutable work? It needs to call the
>user-defined ":=" for component S. But in this example, what do you pass for
>the LHS? It doesn't have a component S!

Of course, Mutable.":=" is kind of "multiple dispatching". There are
four variants of it:

case LHS.B is
   when True =>
      case RHS.B is
         when True =>
            call to ":=" on Something;
         when False =>
            finalize Character;
            call copy-constructor on Something
      end case;
   when False =>
      case RHS.B is
         when True =>
            finalize Something;
            call copy-constructor on Character
         when False =>
            call to ":=" on Character;
      end case;
end case;

Provided we had proper constructors of course! (:-))

Assignment can always be consistently generated out of assignments of
components and destructors/copy-constructors. The reverse is wrong, as
your example clearly shows. Even more obvious example:

X : constant Something := Initial;
   -- should the user-defined ":=" be called here? (:-))
   -- If, yes then what would be LHS?

--
Regards,
Dmitry A. Kazakov
www.dmitry-kazakov.de



  reply	other threads:[~2004-01-19 11:33 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-01-12 17:53 The "()" operator revisited Frank J. Lhota
2004-01-12 18:38 ` Frank J. Lhota
2004-01-12 22:26 ` Robert A Duff
2004-01-13 16:29   ` Frank J. Lhota
2004-01-13  9:24 ` Dmitry A. Kazakov
2004-01-13 16:44   ` Frank J. Lhota
2004-01-13 17:13     ` Hyman Rosen
2004-01-13 22:27     ` Randy Brukardt
2004-01-14  2:30     ` Stephen Leake
2004-01-14  9:04     ` Dmitry A. Kazakov
2004-01-17  0:15       ` Kenneth Almquist
2004-01-17 21:15         ` Robert A Duff
2004-01-19 10:25         ` Dmitry A. Kazakov
2004-01-13 13:13 ` Marin David Condic
2004-01-13 17:38   ` Warren W. Gay VE3WWG
2004-01-13 19:09     ` Robert A Duff
2004-01-15 17:30       ` Warren W. Gay VE3WWG
2004-01-15 18:11         ` Robert A Duff
2004-01-15 19:36           ` tmoran
2004-01-15 20:35             ` Robert A Duff
2004-01-17  5:48               ` Robert I. Eachus
2004-01-16  1:52           ` Redefining := (was: The "()" operator revisited.) Jeffrey Carter
2004-01-16 21:37             ` Randy Brukardt
2004-01-19 11:33               ` Dmitry A. Kazakov [this message]
2004-01-16  3:11           ` The "()" operator revisited Mark A. Biggar
2004-01-16 13:28             ` Hyman Rosen
2004-01-16 16:19             ` Robert A Duff
2004-01-16 18:09             ` Warren W. Gay VE3WWG
2004-01-16 13:56           ` Frank J. Lhota
2004-01-16 16:14             ` Robert A Duff
2004-01-16 21:29               ` Frank J. Lhota
replies disabled

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