read-file and write-file

Started by John_Small, June 07, 2007, 04:38:29 PM

Previous topic - Next topic

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)

rickyboy

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