A little bit of file-position

Джерело:
Common Lisp Tips

Дата публікації:
27/09/2012 13:28

Постійна адреса новини:
http://www.vsinovyny.com/8323832

A little bit of file-position

 

27/09/2012 13:28 // Common Lisp Tips

When used with one argument, file-position returns an integer representing the stream’s file position:

* (defvar *s* (open "data.bin" :element-type '(unsigned-byte 8))
=> *S*

* (read-byte *s*)
=> 42

* (read-byte *s*)
=> 107

* (file-position *s*)
=> 2

When used with two arguments, file-position sets the stream position:

* (file-position *s* 1)
=> T

* (read-byte *s*)
=> 107

When used this way, the position is often given as an integer, but the function actually accepts a designator. An integer position value represents itself, the keyword :start represents 0 (the first position in the stream), and the keyword :end represents the last position in the stream.

What would life be like without :start and :end? For :start, not too difficult; you could just use 0. But without :end you would need to use some other function, such as file-length, to correctly position the stream at the end.

 

» Читати повністю

 

« Наступна новина з архіву
The four causes of symbol conflicts
  Попередня новина з архіву
A brief history of Lisp
»

 

 
© 2026 www.vsinovyny.com