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,901038687c38f61c X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Idiom for a class and an object in Ada Date: Wed, 20 Oct 2004 10:39:42 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de C6T4bpsBLl/I1mSweForhgWKJ69x1eDBneAe57t00h1oGu/lI= User-Agent: 40tude_Dialog/2.0.12.1 Xref: g2news1.google.com comp.lang.ada:5500 Date: 2004-10-20T10:39:42+02:00 List-Id: On Wed, 20 Oct 2004 07:24:31 GMT, Matthew Heaney wrote: > For reasons I can't fathom, many Ada95 developers still have a very > Ada83 mindset. Probably because Ada 83 was good! (:-)) > package P is > > type T (<>) is limited private; > > procedure Op (O : in T); > > function Object1 return T; > function Object2 return T; > > private > > type T is limited record ...; > > end P; This approach is difficult to follow with read-write objects, because it then forces to use indirection. > This is exactly how Text_IO works. The objects returned by functions > Standard_Input, Standard_Output, etc, correspond to the functions > Object1 and Object2 above. Yes and the price is heavy: procedure Put(File : in File_Type; Item : in Character); writes into *in* File! Even if File_Type is considered to be an "iterator", "access window" etc, rather than the file, then definitely Put and Get should *change* it. So what is File_Type? It is a language construct to provide a work-around for the pattern above, i.e. a hack. A bit watery for an IDIOM. > This is the canonical Ada95 idiom for controlling instance creation, and > for declaring well-known objects. Yes, but it lacks an ability to create non-constant objects on the stack, and it requires an extra indirection level. There should be a way for forward object declarations. type X (<>) is limited private; A : X renames private; -- Forward rename or so A : X := private; -- Forward initialization or A : private X; private type X is record Field : Integer; end record; A : X := (Field => 123); Then of course there should be a way for in-place modification of the result for by-reference types and copy-out/copy-in for all others. Anonymous access results are good, but I'd prefer a more elaborated solution without access types. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de