get-line, read-line - read a line from a port


(import (rnrs))                     ;R6RS
(import (rnrs io ports))            ;R6RS
(import (scheme base))              ;R7RS


(get-line textual-input-port)       ;R6RS
(read-line)                         ;R7RS
(read-line textual-input-port)      ;R7RS


Reads from textual-input-port up to and including the linefeed character or end of file, decoding characters in the same manner as get-string-n(3scm) and get-string-n!(3scm).

If a linefeed character is read then a string containing all of the text up to (but not including) the linefeed character is returned, and the port is updated to point just past the linefeed character.

If an end of file is encountered before any linefeed character is read, but some characters have been read and decoded as characters, then a string containing those characters is returned.

If an end of file is encountered before any characters are read, the end-of-file object is returned.

If the port's end-of-line style is not none then all line endings will be read as linefeed characters.
For the purpose of this procedure, an end of line consists of either a linefeed character, a carriage return character, or a sequence of a carriage return character followed by a linefeed character. Implementations may also recognize other end of line characters or sequences.

The default value for textual-input-port is the value returned by current-input-port(3scm).


These procedures return a single value, which is either a string or an end of file object.


;; Return all records in /etc/passwd
(with-input-from-file "/etc/passwd"
  (lambda ()
    (let lp ()
      (let ((line (get-line (current-input-port))))
         (if (eof-object? line)
             (cons line (lp)))))))


This procedure is used to read from linefeed-delimited files.


The R6RS and R7RS variants of this procedure are identical with some subtle differences in how linefeeds are recognized. In R6RS, the port's transcoder is responsible for recognizing character sequences that make up linefeeds, and to translate them into a single linefeed character. This part of the transcoder is active if the eol-style is not none.

The R7RS variant essentially works as if ports can only have eol-style none and moves the recognition of linefeeds into the read-line procedure. This also implies that read-char (3scm) should return each character that makes up a linefeed sequence, such as carriage return followed by linefeed.

R6RS has a single end-of-file object, but R7RS implementations may have several.


This procedure can raise exceptions with the following condition types:
&i/o-read (R6RS)
There was a read error that occurred during an I/O operation.
&assertion (R6RS)
The wrong number of arguments was passed or an argument was outside its domain.
The situations described above are errors. Implementations may signal an error, extend the procedure's domain of definition to include such arguments, or fail catastrophically.


get-char(3scm), read(3scm), eol-style(7scm)




This procedure first appeared in R6RS. The R7RS variant is described with text mostly taken from R6RS.


This page is part of the scheme-manpages project. It includes materials from the RnRS documents. More information can be found at

Markup created by unroff 1.0sc,    March 04, 2023.