Q: file IO? 
Author Message
 Q: file IO?

No doubt this is a dumb question, but ... I'm having trouble making it out,
even relying on the R^4RS and the texts that I often find useful.

How to do file IO?  For example, I want to open a file read to the 50-th
line, replace it with a new 50-th line (there may be a 51-st line, etc.),
and then close the file.  What is the Scheme-y way to do that?  Do I open
a temp file, copy the first 49 lines, etc.?  Or is there a (typical of
the language) pretty way to do it?

Thanks in advance; if I see this one thing then I'm sure I can do the
others that I have to do (I'm using SCM, if that matters).  If someone
posts a reply, I'd appreciate a cc, if possible, as my news feed is a bit
flaky lately.




Sun, 11 Apr 1999 03:00:00 GMT  
 Q: file IO?

Quote:

>How to do file IO?  For example, I want to open a file read to the 50-th
>line, replace it with a new 50-th line (there may be a 51-st line, etc.),
>and then close the file.  What is the Scheme-y way to do that?  Do I open
>a temp file, copy the first 49 lines, etc.?  Or is there a (typical of
>the language) pretty way to do it?

Are there any popular operating systems where you can *do* that?
The only operating system I've used where you could seek to a line
was VM/CMS.

In UNIX, if the new line you write is longer than the old one, you
will corrupt the next line, while if the new line is shorter than
the old one, garbage at the end of the old line will remain.  The
same is true in MS-DOS, OS/2, Win3.x, Win95, Win-NT, and MacOS.  In
VMS (and OpenVMS) it is even more intersting:  if you seek to a
record in a file of variable-length lines and rewrite that record,
if the new record is exactly the same size as the old one, well and
good, but if it is not, the file is truncated at that point.

So, "seek to line N and rewrite it with a possibly different line" is
not something you can do in C, Pascal, Ada, Visual Basic, you name it,
not because of the language but because of the operating system.  CMS
_does_ support it, but it's unusual.

Scheme has many merits, but patching around the limitations of
operating system file services is not one of them.

--
Mixed Member Proportional---a *great* way to vote!
Richard A. O'Keefe; http://www.cs.rmit.edu.au/%7Eok; RMIT Comp.Sci.



Mon, 12 Apr 1999 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. newbie obj files Qs

2. file io with verilog, reading file into a reg

3. mixing IO#read and IO#syswrite

4. Perl IO to Ruby IO help needed

5. IMPORT IO, FROM IO IMPORT ?

6. IMPORT IO, FROM IO IMPORT ?

7. IMPORT IO, FROM IO IMPORT ?

8. BUG?: HP-UX 10.20 and IO#gets followed by IO#puts

9. BUG? IO.seek conflicts with IO.sysread

10. VAX Ada sequential IO and Direct IO - (nf)

11. VAX Ada sequential IO and Direct IO

12. VAX Ada sequential IO and Direct IO

 

 
Powered by phpBB® Forum Software