
Reading a sequence of (characters|bytes) from a file in Common Lisp
I've looked in CLTL1 and CLTL2 (I don't have access to the ANSI Common
Lisp standard, alas), but perhaps I'm missing something:
Is there any way in Common Lisp to read a sequence (of characters
or bytes) of a specified length from a file all at once?
I started looking for this because in other languages I often find out the
size of a file and then read the entire file into memory at once using a
single function call (C's read, Python's file.read (), perl's read, etc),
perform some transformation on it (perhaps using a regexp), and then write
it out; as far as I can tell, in Common Lisp I have to read each character
or byte seperately.
I thought this was a little odd, since it's not unusual to want to read n
bytes at once, and since having a function in the runtime to do it can
significantly improve effciency, especially in languages that are often
implemented as interpreters. For instance, Aubrey Jaffer's SCM
implementation of Scheme has uniform vectors (where all the elements of
the vector are of the same type) and uniform-vector-read! and
uniform-vector-write, and using these functions to read and write
a file in large chunks is *much* faster than reading a character at a time
or a line; almost as fast as C, in fact.
--