comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: limited /non-limited tagged type
Date: Fri, 4 Mar 2011 19:26:48 -0800 (PST)
Date: 2011-03-04T19:26:48-08:00	[thread overview]
Message-ID: <b77e1f60-3757-44d7-a054-9067a42b18cb@y31g2000prd.googlegroups.com> (raw)
In-Reply-To: 40bfb845-7868-4536-886b-496e8dc82cb4@hd10g2000vbb.googlegroups.com


After looking more closely at the OP's example code, I can think of a
possible case where one *could* argue that a new feature in Ada would
be useful, although I think it's way too obscure to consider adding
anything like this.

package Foo is
    type Object is tagged private;
    procedure Copy (Dest : out Object'Class; Source : in
Object'Class);
private
    type Object is tagged record ... end record;
end Foo;

where the body of Copy says "Dest := Source" and maybe performs some
other functions.

It wouldn't work to make the partial view of Object limited, because
then another package could extend Object by adding a component of
limited type to it, and then Dest := Source, when given objects of
that new type, would copy a limited component, which is a no-no.
However, ***IF*** Ada had a way to say that Object isn't really
limited but still doesn't have assignment visibly defined (i.e.
partially limited??), then things might work.  Since it isn't really
limited, it couldn't be extended with a limited component.  And it
would accomplish the purpose that the OP seems to want: forcing other
packages to use the Copy operation (which wouldn't be overridden, but
would still copy all the components in any type extension) instead of
":=".  I don't know if this really is what's wanted.  I'm sort of
guessing.  Anyway, I think the chance of a feature like this being
added is somewhere between zero and less than zero, and I'm certainly
not going to propose one.

I'd still need more info on just what the OP's needs are.  But if it's
something like I guessed, then perhaps a Copy routine that takes
Object'Class parameters instead of Object is what is wanted.  And
while there's no way to get the compiler to reject other uses of := ,
there's a way to make them blow up at runtime: add a component to
Object whose type is derived from Ada.Finalization.Controlled, and
define an Adjust routine that raises an exception unless a Boolean
flag in the body of Foo is set, and of course Copy would be the only
routine that sets it.

                                  -- Adam



  parent reply	other threads:[~2011-03-05  3:26 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-04 18:56 limited /non-limited tagged type Hacid
2011-03-04 19:54 ` Edward Fish
2011-03-04 21:18   ` Hacid
2011-03-05  0:17     ` Edward Fish
2011-03-04 20:10 ` Georg Bauhaus
2011-03-04 21:55   ` Hacid
2011-03-04 22:21     ` Hacid
2011-03-05  1:20       ` Randy Brukardt
2011-03-04 22:22     ` Georg Bauhaus
2011-03-04 22:40       ` Hacid
2011-03-05  1:29         ` Georg Bauhaus
2011-03-04 23:34 ` Adam Beneschan
2011-03-05  3:26 ` Adam Beneschan [this message]
2011-03-05 16:48   ` Hacid
replies disabled

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