From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,699cc914522aa7c4 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news1.google.com!news4.google.com!newsfeed2.dallas1.level3.net!news.level3.com!newsfeed-00.mathworks.com!kanaga.switch.ch!ezmp3.switch.ch!news-zh.switch.ch!switch.ch!cernne03.cern.ch!not-for-mail From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Re: Structured exception information Date: Tue, 16 Jan 2007 10:04:48 +0100 Organization: CERN News Message-ID: References: <1168881460.179633.196040@l53g2000cwa.googlegroups.com> NNTP-Posting-Host: abpc10883.cern.ch Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: cernne03.cern.ch 1168938288 30472 137.138.37.241 (16 Jan 2007 09:04:48 GMT) X-Complaints-To: news@@cern.ch NNTP-Posting-Date: Tue, 16 Jan 2007 09:04:48 +0000 (UTC) User-Agent: Thunderbird 1.5.0.9 (X11/20061220) In-Reply-To: <1168881460.179633.196040@l53g2000cwa.googlegroups.com> Xref: g2news2.google.com comp.lang.ada:8158 Date: 2007-01-16T10:04:48+01:00 List-Id: claude.simon@equipement.gouv.fr wrote: > when My_Type is an indefinite subtype. > > type My_type (<>) is ... for example > > Then, when you declare an object of that type you must provide an > initialization expression (a constructor call !). If I understand correctly: procedure Hello is package P is type T(<>) is private; function Constructor(S : String) return T; private type T(I : Integer) is record null; end record; end P; package body P is function Constructor(S : String) return T is begin return (I => 0); end Constructor; end P; X : P.T := P.Constructor("some params"); begin null; end Hello; (of course, package is nested for presentation only) I have initially thought that discriminated types limit me in terms of what parameter types can be used for constructing them, but actually there is no such limitation - constructor function can have whatever parameter types it wants and the discriminant is irrelevant. It does not feel like a genuine part of the object model (you know, in C++ it is much simpler, more readable, maintainable, etc. ;-) ), but seems to work. OK, so putting aside the fact that my compiler can not swallow it, is it possible to make T Limited_Controlled as well? This is my guess: -- file p.ads with Ada.Finalization; package P is type T(<>) is limited private; function Constructor(S : String) return T; private type T(I : Integer) is new Ada.Finalization.Limited_Controlled with record null; end record; end P; -- file p.adb package body P is function Constructor(S : String) return T is begin return (I => 0); -- NOTE end Constructor; end P; -- file hello.adb with P; procedure Hello is X : P.T := P.Constructor("some params"); begin null; end Hello; It should be impossible to create X in any other way - this is the exact effect that I want to achieve. My compiler does not like it (but it's not really Ada2005), so I cannot verify it. Is the code above correct? BTW - in the line marked as NOTE the compiler says that aggregate type cannot be limited. Is it true for Ada2005? -- Maciej Sobczak : http://www.msobczak.com/ Programming : http://www.msobczak.com/prog/