Open In App

Input From Character Streams in LISP

Last Updated : 11 Apr, 2023
Improve
Improve
Like Article
Like
Save
Share
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.

Argument Used for
input-stream the input-stream argument takes the character stream from which the input is taken. 
eof-error-p eof-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-value If 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

Function Parameter Returns
read & optional input-stream eof-error-p eof-value recursive-p input-stream Lisp object
read-line & optional input-stream eof-error-p eof-value recursive-p input-stream line of the input stream
read-char & optional input-stream eof-error-p eof-value recursive-p input-stream one character
unread-char character & optional input-stream input-stream character
read-preserving-whitespace & optional in-stream eof-error-p eof-value recursive-p input-stream a character with a special token
read-delimited-list char & optional input-stream recursive-p input-stream character object
peek-char & optional peek-type input-stream eof-error-p eof-value recursive-p input-stream next character of the input stream
listen & optional input-stream  input-stream predicate listen
read-char-no-hang & optional input-stream eof-error-p eof-value recursive-p input-stream character
clear-input & optional input-stream input-stream
read-from-string string & optional eof-error-p eof-value & key: start: end: preserve – whitespace string object
parse-integer string & key: start: end: radix: junk-allowed string, start, and end delimiter string with start and end delimiters

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads