comp.lang.ada
 help / color / mirror / Atom feed
From: Maciej Sobczak <see.my.homepage@gmail.com>
Subject: Re: Ada 2005 puzzle
Date: Fri, 20 Jul 2012 01:09:45 -0700 (PDT)
Date: 2012-07-20T01:09:45-07:00	[thread overview]
Message-ID: <72bc2c23-4a1c-4c09-985e-8cc4c0fd957f@googlegroups.com> (raw)
In-Reply-To: <juaghb$fv9$1@munin.nbi.dk>

W dniu piątek, 20 lipca 2012 04:41:46 UTC+2 użytkownik Randy Brukardt napisał:

> Sure, it&#39;s frequent. But it&#39;s still not what you *really* want, because you 
> almost always need some copying.

No, or at least I cannot find any extensive support for your claim in my work. If I say that I don't need copying, then it means that I *really* don't need it, not that this is still not what I *really* want (I have messed that sentence on purpose). If I'm forced to provide some copy semantics even if it was not identified in the design stage, then it is because some other things (language rules? container design? others?) are messed up.
We should fix what is broken.

> For example, you can&#39;t put limited objects into containers.

Then we have poor containers.

Let's take existing Query_Element-like operations for inspiration. What about:

   procedure Insert (C : in out Container;
      Constructor : not null access function return T);

with intended support for downward closures via local and non-local constructor functions. T can be limited or even class-wide limited (which is even more useful).

With existing rules for in-place return that should be enough - there is no need for explicit access types *outside* of the container and consequently no need for Unchecked_Deallocation. The container might need to use them internally, but this is nothing new and we need not care anyway.

Is there any language corner that I have missed?

Interestingly, I cannot succeed with a test program for the above concept:

procedure Test is

    type T is limited null record;
    
    function Create_T return T is
    begin
        return V : T do
            null;
        end return;
    end Create_T;

    procedure Insert (Constructor : not null access function return T) is
        type T_Ptr is access T;
        P : T_Ptr;
    begin
        P := new T'(Constructor.all);  -- compiler error
    end Insert;

begin
    Insert (Create_T'Access);
end Test;

In the marked line the compiler says: "initialization not allowed for limited types". What initialization?

It *does* work when instead of this:

        P := new T'(Constructor.all);

I use this:

        P := new T'(Create_T);

This suggest that the compiler error message is misleading and in fact the compiler just cannot process what seems to be a valid construct (pun intended).
Is this a compiler bug?

> you need some sort of copy to get the 
> objects into (and something out of) the container.

I argue that with appropriate container interface you don't need any copying and you don't need to expose explicit memory management (not counting compiler bugs).

> I 
> personally would rather be *clever* to *fix* something than to retreat into 
> 1980&#39;s programming that cannot be done right by any technique. But your 
> mileage may vary.

My mileage is that we have to fix what is broken, instead of hacking around it.

-- 
Maciej Sobczak * http://www.msobczak.com * http://www.inspirel.com



  parent reply	other threads:[~2012-07-26 14:29 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-12 12:54 Ada 2005 puzzle Dmitry A. Kazakov
2012-07-12 15:48 ` Adam Beneschan
2012-07-12 16:34   ` Dmitry A. Kazakov
2012-07-19  6:53     ` Randy Brukardt
2012-07-19  7:55       ` Dmitry A. Kazakov
2012-07-20  2:22         ` Randy Brukardt
2012-07-20  7:20           ` Dmitry A. Kazakov
2012-07-21  0:04             ` Randy Brukardt
2012-07-21  8:34               ` Dmitry A. Kazakov
2012-07-24  2:38                 ` Randy Brukardt
2012-07-24  4:23                   ` Adam Beneschan
2012-07-24  7:54                     ` Dmitry A. Kazakov
2012-07-25 23:39                       ` Randy Brukardt
2012-07-26  7:41                         ` Dmitry A. Kazakov
2012-07-26 13:08                           ` Simon Wright
2012-07-26 13:55                             ` Dmitry A. Kazakov
2012-07-27  9:42                               ` AdaMagica
2012-07-27 10:32                                 ` Dmitry A. Kazakov
2012-07-27 11:58                                   ` Georg Bauhaus
2012-07-27 13:04                                     ` Dmitry A. Kazakov
2012-07-28  9:48                                       ` AdaMagica
2012-07-28 10:37                                         ` Dmitry A. Kazakov
2012-07-28 16:59                                           ` AdaMagica
2012-07-28 18:21                                             ` Dmitry A. Kazakov
2012-07-19  8:04       ` Maciej Sobczak
     [not found]         ` <juaghb$fv9$1@munin.nbi.dk>
2012-07-20  7:30           ` Dmitry A. Kazakov
2012-07-21 17:21             ` Vasiliy Molostov
2012-07-21 19:03               ` Dmitry A. Kazakov
2012-07-21 19:37                 ` Vasiliy Molostov
2012-07-21 20:23                   ` Dmitry A. Kazakov
2012-07-21 20:53                     ` Vasiliy Molostov
2012-07-22  7:41                       ` Dmitry A. Kazakov
2012-07-22  8:00                         ` Vasiliy Molostov
2012-07-22  8:19                           ` Dmitry A. Kazakov
2012-07-22  9:06                             ` Vasiliy Molostov
2012-07-22  9:34                               ` Dmitry A. Kazakov
2012-07-20  8:09           ` Maciej Sobczak [this message]
2012-07-20  8:27             ` Dmitry A. Kazakov
2012-07-20 11:30               ` Maciej Sobczak
2012-07-20 12:49                 ` Dmitry A. Kazakov
2012-07-21 22:46                   ` Maciej Sobczak
2012-07-22  8:03                     ` Dmitry A. Kazakov
2012-07-22 10:08               ` Florian Weimer
2012-07-22 11:18                 ` Dmitry A. Kazakov
2012-07-21  0:12             ` Randy Brukardt
2012-07-22  9:52       ` Florian Weimer
replies disabled

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