On this page:
read-all
read-all-syntax
Version: 5.2.1

21 Ports

Carl Eastlund <cce@racket-lang.org>

This library is unstable; compatibility will not be maintained. See Unstable: May Change Without Warning for more information.

 (require unstable/port)

This module provides tools for port I/O.

(read-all [reader port])  list?
  reader : (-> any/c) = read
  port : input-port? = (current-input-port)
This function produces a list of all the values produced by calling (reader) while current-input-port is set to port, up until it produces eof.

Examples:

> (read-all read (open-input-string "1 2 3"))

'(1 2 3)

> (parameterize ([current-input-port (open-input-string "a b c")])
    (read-all))

'(a b c)

(read-all-syntax [reader port])  (syntax/c list?)
  reader : (-> (or/c syntax? eof-object?)) = read
  port : input-port? = (current-input-port)
This function produces a syntax object containing a list of all the syntax objects produced by calling (reader) while current-input-port is set to port, up until it produces eof. The source location of the result spans the entire portion of the port that was read.

Examples:

(define port1 (open-input-string "1 2 3"))
> (port-count-lines! port1)
> (read-all-syntax read-syntax port1)

#<syntax:1:0 (1 2 3)>

(define port2 (open-input-string "a b c"))
> (port-count-lines! port2)
> (parameterize ([current-input-port port2])
    (read-all-syntax))

#<syntax:1:0 (a b c)>