read-file and write-file

Notices and updates
Locked
John_Small
Posts: 12
Joined: Thu May 10, 2007 9:09 pm

read-file and write-file

Post by John_Small »

Suppose read-file allowed an optional 2nd argument

(read-file filename fnc)

This fnc is called once for each line in the file.
But instead of returning the entire file in a str-buffer
it returns a continuation function that can be repeatedly
called until returning EOF. If this is too confusing
suppose it were called read-file-line or something.
The idea here is to dispense with having to test for
EOF and closing the file which is all hidden then just
like it is with read-file. The difference it larger
files don't have to be read entirely into memory
all at once.

Likewise if write-file could differentiate between
a str-buffer and an continuation argument then
it could repeatedly call the continuation (i.e. a function
taking no arguments).

Cutting to the chase instead of changing read-file and write-file
suppose instead (or in addition) that copy-file took
an optional 3rd argument that was a current-line mapping
function. If copy-file returned the name of the destination
file (or nil) we could write something like

(rename-file src (copy-file src dst map-fnc))

or better yet

(map-file src map-fnc)
Last edited by John_Small on Fri Jun 08, 2007 3:05 pm, edited 1 time in total.

rickyboy
Posts: 607
Joined: Fri Apr 08, 2005 7:13 pm
Location: Front Royal, Virginia

Post by rickyboy »

Good. Now, I'm looking forward to seeing your implementation! :-)
(λx. x x) (λx. x x)

Locked