[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

looking for fseek and ftell in lisp

Jim Newton

12/3/2015 2:35:00 PM

Does anyone know how to do the equivalent of fseek and ftell using lisp streams?
I.e., I want to get the file position, do some reading, and then return to a previous
position. Is it possible?

Jim
2 Answers

Carlos

12/3/2015 3:24:00 PM

0

On 03/12/2015 15:35, Jim Newton wrote:
> Does anyone know how to do the equivalent of fseek and ftell using lisp streams?
> I.e., I want to get the file position, do some reading, and then return to a previous
> position. Is it possible?

(file-position f) and (file-position f new-pos).
--


Pascal J. Bourguignon

12/3/2015 3:56:00 PM

0

Jim Newton <jimka.issy@gmail.com> writes:

> Does anyone know how to do the equivalent of fseek and ftell using lisp streams?
> I.e., I want to get the file position, do some reading, and then return to a previous
> position. Is it possible?

FILE-POSITION does both.
But NOT on STREAM. Only on FILE-STREAM.

Notice, FILE-POSITION is NOT an accessor! It is a function that takes
an optional new position.

Notice also that FILE-POSITION doesn't necessarily return a number of
octets since the beginning of the file (contrarily to POSIX ftell), and
doesn't take a number of octets since the beginning of the file
(contrarily to POSIX fseek). Therefore you can only pass to
FILE-POSITION, positions that you got from FILE-POSITION (and from the
same unchanged file prefix).

In lisp, for binary streams file positions are numbers of BYTES since
the beginning of the file (so if your file is a file of (unsigned-byte
24), then file positions will be 1/3 or 1/4 the number of octets,
depending on how the implementation writes bytes. If your bytes are
(unsigned-byte 3), file positions might have an even more complex
relationship with the number of octets.

And for character streams, it's even worse, check the clhs.

--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk