[plt-scheme] reading a whole file
Eli Barzilay wrote:
> The only question is how many functions to have in that interface.
> Currently, I see 16 of them:
>
> file->string
> file->strings ; list of strings, read with read-line
> file->bytes
> file->bytess ; bad name, and perhaps not needed anyway
> port->... ; port versions of all of the above
> string->file ; reverse direction
>
> I hope that there's some way to cut all that down somehow... (The
> file/port cannot be done based on the input value if the two functions
> come from scheme/port and scheme/file, some keyword argument that
> makes it return bytes/string, or a list of lines seems ugly.)
I think that the line versions are not worth the effort (for/list with
line iteration is already available). You could get rid of file-> by
using call-with-input-file or with-input-from-file (the argument would
default to current-input-port as in read). The same goes for reverse
direction (and no line versions, rather lift a good 'join list with
strings between' from some SRFI; OTOH we could use a
join-strings-to-port since this should be more efficient than list
rewriting followed by string-append).
--
regards,
Jakub Piotr Cłapa