From: stefan-lucks@see-the.signature
Subject: Re: A suggestion for resource management
Date: Sun, 22 Aug 2010 15:09:21 +0200
Date: 2010-08-22T15:09:21+02:00 [thread overview]
Message-ID: <Pine.LNX.4.64.1008221453530.32484@medsec1.medien.uni-weimar.de> (raw)
In-Reply-To: <8762z4gcoi.fsf@mid.deneb.enyo.de>
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! ------
next prev parent reply other threads:[~2010-08-22 13:09 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-21 16:20 A suggestion for resource management Florian Weimer
2010-08-21 19:07 ` Dmitry A. Kazakov
2010-08-21 19:47 ` Florian Weimer
2010-08-21 20:53 ` Dmitry A. Kazakov
2010-08-21 21:09 ` Florian Weimer
2010-08-22 6:40 ` Dmitry A. Kazakov
2010-08-23 23:22 ` Randy Brukardt
2010-08-21 20:34 ` Niklas Holsti
2010-08-21 21:01 ` Florian Weimer
2010-08-22 10:53 ` Niklas Holsti
2010-08-22 15:29 ` Florian Weimer
2010-08-22 16:12 ` Florian Weimer
2010-08-23 12:25 ` Niklas Holsti
2010-09-04 19:09 ` Florian Weimer
2010-09-07 10:14 ` Niklas Holsti
2010-08-22 11:32 ` Georg Bauhaus
2010-08-23 23:37 ` Randy Brukardt
2010-08-22 13:09 ` stefan-lucks [this message]
2010-08-22 14:30 ` Florian Weimer
2010-08-22 15:09 ` 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