Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Reading a sequence of (characters|bytes) from a file in Common Lisp

73 views
Skip to first unread message

Erik Naggum

unread,
Jan 7, 1996, 3:00:00 AM1/7/96
to
[T. Kurt Bond]

| 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?

ANSI CL has `read-sequence', which destructively modify a sequence with
elements read from a stream, and `write-sequence', which writes elements
from the sequence directly to a stream. "An efficient implementation is
more likely to exist for the case where the sequence is a vector with the
same element type as the stream" (from the standard).

#<Erik 3030007432>
--
the problem with this "information superhighway" is mainly that if you ask
people to go play in it, they don't even understand when they get run over.

T. Kurt Bond

unread,
Jan 7, 1996, 3:00:00 AM1/7/96
to tkb
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.
--
T. Kurt Bond, t...@wvlink.mpl.com

0 new messages