Previous: iklib reader misc, Up: iklib reader [Index]
When the source code reader is in #!vicare
mode, it is possible
to include “here documents” processed (at read–time) by custom
functions. This feature works only when reading source code for
libraries or programs, at present it does not work at the
REPL.
Let’s see how it works. Assuming the following library is in the search path:
(library (libdemo) (export doit) (import (rnrs)) (define (doit input-string) (read (open-string-input-port input-string))))
let’s consider this program file:
#!vicare (reader-import (libdemo)) (program (demo) (import (rnrs)) (display #<doit 456>#) (newline) (flush-output-port (current-output-port)))
we see that at the beginning of a program file (before the
program
form) we have:
(reader-import (libdemo))
and in the body of the program we have the block:
#<doit 456>#
such block is converted by the reader to the form:
(doit "456")
notice that whitespace characters after the symbol "doit" are discarded.
Such form is handed to eval
and evaluated in the context of the
lexical environment resulting from importing (libdemo)
; the
result of the evaluation is returned to the reader for inclusion in its
output. So the reader gets the symbolic expression ‘456’.
This symbolic expression supports the same format of import
; it
is not a syntactic binding, rather it is a symbolic expression processed
by the source code reader. This expression can be present only at the
beginning of a program or library file, before the program
or
library
form; it is recognised only when the input port is in
#!vicare
mode.
The import sets are used to initialise an interaction environment for subsequent code evaluation.
A reader syntax recognised only when the input port is in
#!vicare
mode. The argument ?symbol must be a symbol. The
argument ?characters, up to and excluding ‘>#’, are read to
compose an input string.
The argument ?symbol must be:
begin
. In this case the: the input string is
interpreted as a list of Scheme forms representing definitions and
expressions to be evaluated in the interaction environment established
by the reader-import
syntax.
reader-import
syntax. In this case: the input
string is handed to the ?symbol function or syntax as single
operand; the result of such application must be a single return value
which becomes a datum for the reader.
Previous: iklib reader misc, Up: iklib reader [Index]