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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!mx05.eternal-september.org!.POSTED!not-for-mail From: Jeffrey Carter Newsgroups: comp.lang.ada Subject: Re: Seeking for papers about tagged types vs access to subprograms Date: Sun, 12 May 2013 11:56:50 -0700 Organization: Also freenews.netfront.net; news.tornevall.net Message-ID: References: <1vrhb7oc4qbob$.q02vuouyovp5$.dlg@40tude.net> <19lrzzbgm77v6.1dzpgqckptaj6.dlg@40tude.net> <1bfhq7jo34xpi.p8n2vq6yjsea.dlg@40tude.net> <12gn9wvv1gwfk.10ikfju4rzmnj.dlg@40tude.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sun, 12 May 2013 18:53:07 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="656ea2f23126f57fb36504d2d15a002c"; logging-data="10867"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19/eAu5oz+397eUHUn+O5YvJbBvrdfBHT0=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0 In-Reply-To: Cancel-Lock: sha1:eS26UQi65SSlclNYu6nkJRU6dg4= Xref: news.eternal-september.org comp.lang.ada:15530 Date: 2013-05-12T11:56:50-07:00 List-Id: On 05/12/2013 01:10 AM, Niklas Holsti wrote: > > You mean like this: > > function Open (File : in Closed_File) return Open_File; > function Close (File : in Open_File ) return Closed_File; > > I agree that this is a possible approach. This would work, but at the > cost of writing the parameter/object name twice in each call: > > File : File_Object; > ... > File := Open (File); > File := Close (File); I'm not sure I see the point in having an object for a closed file, other than the requirements of low-level languages in which such things were 1st implemented. Why not something like type File_Info (<>) is tagged limited private; function Open (Name : ...; ...) return File_Info; function Create (Name : ...; ...) return File_Info; function Read (File : in out File_Info) return ...; procedure Write (File : in out File_Info; Item : in ...); declare File : File_Info := Open ("junk", ...); begin Data := Read (File); ... end; A File_Info must be opened or created when declared, and is closed when it's finalized. -- Jeff Carter "C++ is like giving an AK-47 to a monk, shooting him full of crack and letting him loose in a mall and expecting him to balance your checking account 'when he has the time.'" Drew Olbrich 52