comp.lang.ada
 help / color / mirror / Atom feed
* Returning a limited object as a class-wide value
@ 2017-11-29  2:05 Victor Porton
  2017-11-29  9:00 ` Dmitry A. Kazakov
  2017-11-29 20:51 ` Randy Brukardt
  0 siblings, 2 replies; 3+ messages in thread
From: Victor Porton @ 2017-11-29  2:05 UTC (permalink / raw)


Let T be a limited tagged type.

I want to define a function F which returns T'Class.

Please show me an example.

I try:

return X: T'Class := T'(others => <>) do
   --- ...
end return;

Right way?

-- 
Victor Porton - http://portonvictor.org


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

* Re: Returning a limited object as a class-wide value
  2017-11-29  2:05 Returning a limited object as a class-wide value Victor Porton
@ 2017-11-29  9:00 ` Dmitry A. Kazakov
  2017-11-29 20:51 ` Randy Brukardt
  1 sibling, 0 replies; 3+ messages in thread
From: Dmitry A. Kazakov @ 2017-11-29  9:00 UTC (permalink / raw)


On 29/11/2017 03:05, Victor Porton wrote:
> Let T be a limited tagged type.
> 
> I want to define a function F which returns T'Class.
> 
> Please show me an example.
> 
> I try:
> 
> return X: T'Class := T'(others => <>) do
>     --- ...
> end return;
> 
> Right way?

Never return limited objects, never use limited aggregates. Both are 
bogus concepts.

Even if compiler perchance compiled your code, your design will not work 
in case you wanted private extensible limited type with kind of 
"constructor" called from the derived type's "constructor".

I tried that, it does not work. The worst thing is that you discover the 
dead end pretty much too late in some distant client packages and have 
to return all way back. Just don't.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


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

* Re: Returning a limited object as a class-wide value
  2017-11-29  2:05 Returning a limited object as a class-wide value Victor Porton
  2017-11-29  9:00 ` Dmitry A. Kazakov
@ 2017-11-29 20:51 ` Randy Brukardt
  1 sibling, 0 replies; 3+ messages in thread
From: Randy Brukardt @ 2017-11-29 20:51 UTC (permalink / raw)


"Victor Porton" <porton@narod.ru> wrote in message 
news:ovl4m6$k5s$1@gioia.aioe.org...
> Let T be a limited tagged type.
>
> I want to define a function F which returns T'Class.
>
> Please show me an example.
>
> I try:
>
> return X: T'Class := T'(others => <>) do
>   --- ...
> end return;
>
> Right way?

Ignoring Dmitry's typical rant, I believe this is correct. You are making a 
new object this way (as copying of limited objects is banned -- that's the 
point).

Remember that a limited function can only be used to initialize a limited 
object or used for a very short lifetime. That's usually enough. You can 
compose limited objects this way, as well, so long as it is used in a 
limited aggregate or function return.

But remember that "limited" is, well, limited for a reason. So there are 
definitely things that can't be done that way.

                                          Randy.



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

end of thread, other threads:[~2017-11-29 20:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-29  2:05 Returning a limited object as a class-wide value Victor Porton
2017-11-29  9:00 ` Dmitry A. Kazakov
2017-11-29 20:51 ` Randy Brukardt

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