[plt-scheme] How to seek backward an input file

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue Mar 15 23:21:48 EST 2005

At Sat, 12 Mar 2005 23:12:00 +0100, libe4 at free.fr wrote:
> How can I seek backward for something one or two lines before in a file with
> Scheme opened with (open-input-file... ?

You may want to use the `file-position' function. With one argument, it
gives you the current position of the file pointer. With two arguments,
the second argument is used to set the file position (so you could set
it to be one less than the current position to back up on byte).

Depending on your application, another possibility is to peek ahead in
the port instead of reading from the port (in which case you can avoid
having to back up, because peeking doesn't go forward).

Matthew



Posted on the users mailing list.