Next: , Up: Streams   [Contents][Index]

5.24.1 Input Streams

These are the possible types of input stream, for the functions which use them see Input Functions.


Characters are read from the file object file, for the functions which manipulate file objects see Files.


Each time an input character is required the function is called with no arguments. It should return the character read (an integer) or false if for some reason no character is available.

function should also be able to ‘unread’ one character. When this happens the function will be called with one argument—the value of the last character read. The function should arrange it so that the next time it is called it returns this character. A possible implementation could be,

(defvar ms-unread-char nil
  "If true the character which was pushed back.")

(defun my-stream (#!optional unread-char)
  (if unread-char
      (setq ms-unread-char unread-char)
    (if ms-unread-char
          (setq ms-unread-char nil))
      ;; Normal case -- read and return a character from somewhere

Read from the stream stored in the variable standard-input.

It is also possible to use a string as an input stream. The string to be read from must be applied to the make-string-input-stream function and the result from this function used as the input stream.

Function: make-string-input-stream string #!optional start

Returns an input stream which will supply the characters of the string string in order starting with the character at position start (or from position zero if this argument is undefined).

(read (make-string-input-stream "(1 . 2)"))
    ⇒ (1 . 2)
Variable: standard-input

The input stream which is used when no other is specified or is false.

Applications that embed Librep, or dynamically loaded extensions, may provide further input stream types.

Next: , Up: Streams   [Contents][Index]