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: backlog1.nntp.ams3.giganews.com!backlog1.nntp.ams2.giganews.com!backlog1.nntp.ams.giganews.com!backlog1.nntp.dca.giganews.com!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!newsfeed-00.mathworks.com!nntp.TheWorld.com!.POSTED!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Seeking for papers about tagged types vs access to subprograms Date: Sun, 12 May 2013 18:15:24 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <19lrzzbgm77v6.1dzpgqckptaj6.dlg@40tude.net> <1bfhq7jo34xpi.p8n2vq6yjsea.dlg@40tude.net> <12gn9wvv1gwfk.10ikfju4rzmnj.dlg@40tude.net> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls6.std.com 1368396924 7525 192.74.137.71 (12 May 2013 22:15:24 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Sun, 12 May 2013 22:15:24 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:YGxWvo3/EgVJpcvtI0tFxwmZjss= Xref: number.nntp.dca.giganews.com comp.lang.ada:181609 Date: 2013-05-12T18:15:24-04:00 List-Id: Jeffrey Carter writes: > I'm not sure I see the point in having an object for a closed file, Yeah, I was about to post basically the same thing. A closed file is pretty useless. It's like an uninitialized variable -- you can't do anything with it. > other than the requirements of low-level languages in which such things > were 1st implemented. Low-level languages like Ada 83? ;-) >...Why not something like > > type File_Info (<>) is tagged limited private; Yes, but I would have separate types for Input_File and Output_File. Possibly another type for the rare case when you want to read and write to/from the same file handle. > function Open (Name : ...; ...) return File_Info; > function Create (Name : ...; ...) return File_Info; Note that these are build-in-place functions. You can't call them as the right-hand side of an assignment statement. > 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; You could use it as above, or like this: Grind_Upon_File(Open("junk", ...)); Or like this: X := new File_Info'(Open(...)); But you couldn't use it like this: File : File_Info; -- Illegal! ... -- some code that computes File_Name File := Open (File_Name); -- Illegal! which is a limitation, compared to the current design of Text_IO and friends. > A File_Info must be opened or created when declared, and is closed when > it's finalized. Right. - Bob