- set-read-syntax! CHAR-OR-SYMBOL PROCprocedure
When the reader encounters the non-whitespace character CHAR while reading an expression from a given port, then the procedure PROC will be called with that port as its argument. The procedure should return a value that will be returned to the reader:
; A simple RGB color syntax: (set-read-syntax! #\% (lambda (port) (apply vector (map (cut string->number <> 16) (string-chop (read-string 6 port) 2) ) ) ) ) (with-input-from-string "(1 2 %f0f0f0 3)" read) ; ==> (1 2 #(240 240 240) 3)
If CHAR-OR-SYMBOL is a symbol, then a so-called read-mark handler is defined. In that case the handler procedure will be called when a character-sequence of the form #!SYMBOL is encountered.
You can undo special handling of read-syntax by passing #f as the second argument (if the syntax was previously defined via set-read-syntax!).
As a special case, your handler can return zero values, via (values). This causes the reader to completely ignore whatever input you've read, rather than returning some possibly unspecified value. This can be useful in macro context, reading comments, conditional compilation, and so forth. Available in CHICKEN 4.6.6 and later.
Note that all of CHICKEN's special non-standard read-syntax is handled directly by the reader. To disable built-in read-syntax, define a handler that triggers an error (for example).