comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: another way to shoot yourself in the foot?
Date: Tue, 24 Jun 2008 09:30:17 +0200
Date: 2008-06-24T09:30:17+02:00	[thread overview]
Message-ID: <1lbujyle8itjn$.vffs9far1ob9.dlg@40tude.net> (raw)
In-Reply-To: 21d80cc3-a3fb-49f5-a46e-6056bbef2ba7@y21g2000hsf.googlegroups.com

On Mon, 23 Jun 2008 21:02:29 -0700 (PDT), george.priv@gmail.com wrote:

> On Jun 23, 3:49 am, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
> wrote:
>> On Sun, 22 Jun 2008 16:44:08 -0400, Robert A Duff wrote:
>>> I don't see that as a problem, and anyway, the same thing can happen
>>> with the existing syntax:
>>
>>> function Foo (...) return String is
>>> begin
>>>    return Result : String (1..200) do  -- Going to return 200 characters
>>>       Result (1) := 'a'; -- Here the result has to be allocated
>>>       if HALT (x) then
>>>          goto Label;
>>>       end if;
>>>    end;  -- Drop already allocated and initialized result
>>>    <<Label>>
>>>    return "Hallo!";  -- Return a completely different thing
>>> end Foo;
>>
>>> The implementation of this is "interesting" (if we replace String by a
>>> build-in-place type).  ;-)
>>
>> How much interesting is it? (:-))
>>
>> Unfortunately the following crazy sample crashes GNAT, but I wonder what
>> could be the result if it compiled:
>>
>> procedure Return_Task is
>>    Just_For_Fun : exception;
>>
>>    task type T is
>>       entry A;
>>    end T;
>>
>>    task body T is
>>    begin
>>       accept A;
>>    end T;
>>
>>    function Interesting return T is
>>    begin
>>       return X : T do
>>          raise Just_For_Fun;
>>       end return;
>>    exception
>>       when Just_For_Fun =>
>>          return X : T;
>>    end Interesting;
>>
>>    X : T := Interesting;
>> begin
>>    X.A;
>> end Return_Task;
>>
>> Should it block?
>>
>> Another question is about the semantics such stuff. In which sense in-place
>> is it? It seems that an in-place initialization might result in n
>> finalizations and n+1 initializations (n>=0) of the same thing.
> 
> Aren't tasks limited types by definitions?

Yes, they are.

> In which case compiler
> should be giving error message..

Ada 2005 introduced "Pickwickian" functions "returning" limited objects,
in-place, upon initialization. In the example, the result task of
Interesting, being constructed in the object X, is first initialized, then
finalized upon exception propagation and, finally, re-initialized again. I
suggest that the example (if legal) should hang forever, because to
finalize T one has to have a rendezvous with its entry A.

All this is confusing and counterintuitive, at least. I mean both
"Pickwickian" functions and the semantics return statements.

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



  reply	other threads:[~2008-06-24  7:30 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-20  9:03 another way to shoot yourself in the foot? fedya_fedyakoff
2008-06-20  9:34 ` Dmitry A. Kazakov
2008-06-20  9:48   ` fedya_fedyakoff
2008-06-20 10:01     ` Ludovic Brenta
2008-06-20 10:05 ` christoph.grein
2008-06-20 10:26   ` Dmitry A. Kazakov
2008-06-20 16:12     ` Adam Beneschan
2008-06-20 15:48   ` Adam Beneschan
2008-06-20 19:27   ` Robert A Duff
2008-06-20 23:37     ` Jeffrey R. Carter
2008-06-21  8:56       ` Dmitry A. Kazakov
2008-06-22 20:44         ` Robert A Duff
2008-06-23  7:49           ` Dmitry A. Kazakov
2008-06-24  4:02             ` george.priv
2008-06-24  7:30               ` Dmitry A. Kazakov [this message]
2008-06-24 17:16                 ` Robert A Duff
2008-06-24 19:15                   ` Jeffrey R. Carter
2008-06-24 20:31                     ` Robert A Duff
2008-06-24 20:50                       ` Ludovic Brenta
2008-06-24 23:02                         ` Robert A Duff
2008-06-24 23:42                         ` Georg Bauhaus
2008-06-24 21:24                       ` Jeffrey R. Carter
2008-06-24 23:24                         ` Robert A Duff
2008-06-25 15:07                       ` Adam Beneschan
2008-06-24 14:59             ` Adam Beneschan
2008-06-24 16:41               ` Dmitry A. Kazakov
2008-06-24 17:20                 ` Robert A Duff
2008-06-24 17:52                   ` Dmitry A. Kazakov
2008-06-24 23:35                     ` Georg Bauhaus
2008-06-25  8:09                       ` Dmitry A. Kazakov
2008-06-25 10:32                         ` Georg Bauhaus
2008-06-25 12:06                           ` Dmitry A. Kazakov
2008-06-22 20:37       ` Robert A Duff
2008-06-22 21:25         ` Jeffrey R. Carter
2008-07-04 20:52           ` Colin Paul Gloster
2008-07-04 22:15             ` (see below)
2008-07-05 16:06               ` Colin Paul Gloster
2008-07-05 13:38             ` Gary Scott
2008-07-05 16:42               ` Colin Paul Gloster
2008-07-05 19:00                 ` Gary Scott
2008-07-09 19:39                   ` Colin Paul Gloster
2008-07-09 20:35                     ` Richard Maine
2008-07-09 22:49                       ` Terence
2008-07-10  1:07                         ` Gary Scott
2008-07-10 14:10                       ` Colin Paul Gloster
2008-07-10 14:57                         ` fj
2008-07-10 16:47                           ` Richard Maine
2008-07-10 17:03                         ` Dick Hendrickson
2008-07-10 17:26                           ` Craig Powers
2008-07-10 19:55                             ` James Giles
2008-07-10 20:45                               ` Dick Hendrickson
2008-07-10 21:22                                 ` Richard Maine
2008-07-10 21:29                                   ` Craig Powers
2008-07-10 20:45                               ` Craig Powers
2008-07-10 19:51                           ` James Giles
2008-07-11 15:02                             ` Colin Paul Gloster
replies disabled

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