Open In App

Input From Character Streams in LISP

Last Updated : 11 Apr, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

This article is about input from character streams in LISP. Input in LISP can be taken in different ways like input from the user, input from character streams, etc. In LISP input from character streams can be taken from different functions accordingly. Input from character streams can be a string, character, character object, or line from a file. Based on the type of desired output, functions are selected.

Functions To Take Input from Character Streams in LISP

There are different optional arguments along with the function to take input as a character stream. Some character stream input function arguments are input-stream, eof- error-p, and eof- value.

ArgumentUsed for
input-streamthe input-stream argument takes the character stream from which the input is taken. 
eof-error-peof-error-p argument checks if the end of the file is reached while scanning the file. It has a default value of true which gives an error at end of the file otherwise false.
eof-valueIf eof-error-p is false then it returns eof-value.

List of Character Stream Input Functions

  1. read & optional input-stream eof-error-p eof-value recursive-p: This function takes the input stream, constructs the Lisp object based on the description, and returns the object.
  2. read-line & optional input-stream eof-error-p eof-value recursive-p: This function takes the input stream as a parameter and returns the line of the input stream separated by a new line.
  3. read-char & optional input-stream eof-error-p eof-value recursive-p: This function takes input stream as a parameter reads one character and returns the character object.
  4. unread-char character & optional input-stream: This function takes the input stream as the reads a character from the input stream and puts it to the front of it and reads the next character.
  5. read-preserving-whitespace & optional in-stream eof-error-p eof-value recursive-p: This function under special conditions takes in a stream as a parameter and gives information about the character ended with a special token.
  6. read-delimited-list char & optional input-stream recursive-p: This function takes the input stream as a parameter, reads the objects from the character stream followed by a character, and returns the character object.
  7. peek-char & optional peek-type input-stream eof-error-p eof-value recursive-p: This function takes the input stream as a parameter and returns the next character without removing it.
  8. listen & optional input-stream: This function takes the input stream as a parameter and returns the predicate listen as true if the character in the input stream is available immediately, otherwise false.
  9. read-char-no-hang & optional input-stream eof-error-p eof-value recursive-p: It works similarly to read-char but returns nil if it has to wait for the character.
  10. clear-input & optional input-stream: This function clears the buffered input from the input stream.
  11. read-from-string string & optional eof-error-p eof-value & key: start: end: preserve - whitespace: This function takes a string as a parameter, builds an object by taking characters of the string one after the other, and returns the object.
  12. parse-integer string & key: start: end: radix: junk-allowed: This function takes string and starting and end delimiter as parameters and returns the part of a string starting with start and ending with end delimiter.

Returns Value of Character Streams in LISP

FunctionParameterReturns
read & optional input-stream eof-error-p eof-value recursive-pinput-streamLisp object
read-line & optional input-stream eof-error-p eof-value recursive-pinput-streamline of the input stream
read-char & optional input-stream eof-error-p eof-value recursive-pinput-streamone character
unread-char character & optional input-streaminput-streamcharacter
read-preserving-whitespace & optional in-stream eof-error-p eof-value recursive-pinput-streama character with a special token
read-delimited-list char & optional input-stream recursive-pinput-streamcharacter object
peek-char & optional peek-type input-stream eof-error-p eof-value recursive-pinput-streamnext character of the input stream
listen & optional input-stream input-streampredicate listen
read-char-no-hang & optional input-stream eof-error-p eof-value recursive-pinput-streamcharacter
clear-input & optional input-streaminput-stream-
read-from-string string & optional eof-error-p eof-value & key: start: end: preserve - whitespacestringobject
parse-integer string & key: start: end: radix: junk-allowedstring, start, and end delimiterstring with start and end delimiters

Next Article
Article Tags :

Similar Reads