Next: , Up: iklib reader   [Index]


6.13.1 Textual input port modes

Reader Syntax: #!vicare
Reader Syntax: #!ikarus

Vicare extends Scheme’s lexical syntax (R6RS Chapter 4) in a variety of ways including:

The syntax extensions are made available by default on all input ports, until the token #!r6rs is read; thus, reading the token #!r6rs disables all extensions to the lexical syntax on the specific port, and the token #!vicare enables them again.

When writing code that is intended to be portable across different Scheme implementations, we should add the token #!r6rs to the top of every script and library that we write; this allows Vicare to alert us when using non–portable features. When writing code that’s intended to be Vicare–specific, we should add the token #!vicare in order to get an immediate error when the code is run under other implementations.

The comment #!ikarus is accepted for backwards compatibility with Ikarus Scheme.

Procedure: port-mode input-port

Accept an input port as argument and return a symbol among: r6rs, vicare. All input ports start under vicare mode and thus accept Vicare–specific reader extensions. When the token #!r6rs is read from a port: its mode changes to r6rs.

> (port-mode (current-input-port))
vicare
> #!r6rs (port-mode (current-input-port))
r6rs
> #!vicare (port-mode (current-input-port))
vicare
Procedure: set-port-mode! input-port mode

Modifiy the lexical syntax accepted by subsequent calls to read on the input port. The mode is a symbol among r6rs and vicare. The effect of setting the port mode is similar to that of reading the token #!r6rs or #!vicare from that port.

> (set-port-mode! (current-input-port) 'r6rs)
> (port-mode (current-input-port))
r6rs

Next: , Up: iklib reader   [Index]