Previous: , Up: iklib reader   [Index]


6.13.6 Extending the reader with custom syntaxes

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’.

Reader Syntax: reader-import ?import-set0 ?import-set

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.

Reader Syntax: #<?symbol ?characters>#

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:


Previous: , Up: iklib reader   [Index]