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

[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.



Thu, 25 Jun 1998 03:00:00 GMT  
 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.
--



Thu, 25 Jun 1998 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Copying byte sequence from integer/real to character array

2. Reading Large Data Files with Kyoto Common Lisp

3. Using Python arrays of bytes for ILU SEQUENCE OF BYTE -- API is inadequate

4. Reading characters and bytes from the same stream

5. What I want from my Common Lisp vendor and the Common Lisp community

6. How to load a lisp file in Allegro Common Lisp

7. lucid common lisp -- C -- Common lisp intercallability

8. Lucid (Sun) Common Lisp vs Allegro (Franz) Common Lisp - the Summary

9. Lucid (Sun) Common Lisp vs Allegro (Franz) Common Lisp

10. Sun Common Lisp vs. Allegro Common Lisp

11. Search character sequences in ASCII file???

12. Search character sequences in ASCII file???

 

 
Powered by phpBB® Forum Software