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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,7fcf9180e7ba7ab1 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!feeder.news-service.com!newsfeed.straub-nv.de!news-1.dfn.de!news.dfn.de!news.uni-weimar.de!not-for-mail From: stefan-lucks@see-the.signature Newsgroups: comp.lang.ada Subject: Re: A suggestion for resource management Date: Sun, 22 Aug 2010 15:09:21 +0200 Organization: Bauhaus-Universitaet Weimar Message-ID: References: <8762z4gcoi.fsf@mid.deneb.enyo.de> Reply-To: stefan-lucks@see-the.signature NNTP-Posting-Host: medsec1.medien.uni-weimar.de Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Trace: tigger.scc.uni-weimar.de 1282475159 15504 141.54.178.228 (22 Aug 2010 11:05:59 GMT) X-Complaints-To: news@tigger.scc.uni-weimar.de NNTP-Posting-Date: Sun, 22 Aug 2010 11:05:59 +0000 (UTC) X-X-Sender: lucks@medsec1.medien.uni-weimar.de In-Reply-To: <8762z4gcoi.fsf@mid.deneb.enyo.de> Xref: g2news1.google.com comp.lang.ada:13605 Date: 2010-08-22T15:09:21+02:00 List-Id: On Sat, 21 Aug 2010, Florian Weimer wrote: > The example at the end of section B.4 could use the Scoped pragma in > this way: > > procedure Test_External_Formats is > ... > COBOL_File : File_Type; > ... > > begin > Open (COBOL_File, Name => "Some_File"); > pragma Scoped (Close (COBOL_File)); > > loop > ... > exception > when End_Error => ... > end Test_External_Formats; > I don't quite why this needs an extra pragma -- your example is, apparently, easy to handle by current Ada's capacities: procedure New_Test_External_Formats is ... COBOL_File : File_Type; procedure Close_Cobol_File is begin Close(COBOL_FILE); end Close_Cobol_File; Finisher: Finish_Package.Finisher; -- The type Finish_Package.Finisher is derived from -- Ada.Finalization.Limited_Controlled. ... begin Open (COBOL_File, Name => "Some_File"); -- pragma Scoped (Close (COBOL_File)); -- we don't need the pragma Finisher.Set(Close_Cobol_File'Access); -- we will call Close_Cobol_File -- when Finisher goes out of scope loop ... exception when End_Error => ... end Test_External_Formats; The only disadvantage of this approach, in comparison to your pragma, is the need to define a parameterless procedure Close_Cobol_File. But defining such parameterless procedures is a design pattern you get used to anyway, when working with Ada.Containers. -- ------ Stefan Lucks -- Bauhaus-University Weimar -- Germany ------ Stefan dot Lucks at uni minus weimar dot de ------ I love the taste of Cryptanalysis in the morning! ------