4.13 Streams
TBoS p.113-121, SD
The zero-place calls '(stinput)' and '(stoutput)' return the standard input and output streams.
In Shen, streams are created to read from or to files. The function to create a stream is
(open string direction ). string is a pathname to the file and direction
is 'in' for source and 'out' for sink.
The primitive read and write functions for streams are 'read-byte' and 'write-byte'. These
read a byte from a source stream or print a string to a sink stream. 'close' closes a stream.
This example reads a binary file.
(0-) (set *mystream* (open "gate-of-consciousness.ico" in))
#INPUT BUFFERED FILE-STREAM (UNSIGNED-BYTE 8) #P"gate-of-consciousness.ico"
(1-) (read-byte (value *mystream*))
0
(2-) (read-byte (value *mystream*))
0
(3-) (read-byte (value *mystream*))
1
(4-) (close (value *mystream*))
[] |
|