READTABLES


The behaviour of the reader is controlled by a data structure called a "readtable". The reader uses the symbol *readtable* to locate the current readtable. This table controls the interpretation of input characters -- if it is changed then the section LEXICAL CONVENTIONS may not apply. The readtable is an array with 256 entries, one for each of the extended ASCII character codes. Each entry contains one of the following values, with the initial entries assigned to the values indicated:

:white-space
A whitespace character - tab, cr, lf, ff, space
(:tmacro . fun)
terminating readmacro - ( ) " , ; ' `
(:nmacro . fun)
non-terminating readmacro - #
:sescape
Single escape character - \
:mescape
Multiple escape character - |
:constituent
Indicating a symbol constituent (all printing characters not listed above)
NIL
Indicating an invalid character (everything else)
In the case of :TMACRO and :NMACRO, the "fun" component is a function. This can either be a built-in readmacro function or a lambda expression. The function takes two parameters. The first is the input stream and the second is the character that caused the invocation of the readmacro. The readmacro function should return NIL to indicate that the character should be treated as white space or a value consed with NIL to indicate that the readmacro should be treated as an occurance of the specified value. Of course, the readmacro code is free to read additional characters from the input stream. A :nmacro is a symbol constituent except as the first character of a symbol.

As an example, the following read macro allows the square brackets to be used as a more visibly appealing alternative to the SEND function:

(setf (aref *readtable* (char-int #\[)) ; #\[ table entry
      (cons :tmacro
	    (lambda (f c &aux ex) ; second arg is not used
		    (do ()
			((eq (peek-char t f) #\]))
			(setf ex (append ex (list (read f)))))
		    (read-char f) ; toss the trailing #\]
		    (cons (cons 'send ex) NIL))))

(setf (aref *readtable* (char-int #\]))
      (cons :tmacro
	    (lambda (f c)
		    (error "misplaced right bracket"))))
XLISP defines several useful read macros:

	'<expr>	== (quote <expr>)
	`<expr>	== (backquote <expr>)
	,<expr>	== (comma <expr>)
	,@<expr>	== (comma-at <expr>)
	#'<expr>	== (function <expr>)
	#(<expr>...)	== an array of the specified expressions
	#S(<structtype> [<slotname> <value>]...)
== structure of specified type and initial values
#.<expr>
== result of evaluating <expr>
#x<hdigits>
== a hexadecimal number (0-9,A-F)
#o<odigits>
== an octal number (0-7)
#b<bdigits>
== a binary number (0-1)
#| |#
== a comment
#:<symbol>
== an uninterned symbol
#C(r i)
== a complex number
#+<expr>
== conditional on feature expression true
#-<expr>
== conditional on feature expression false
A feature expression is either a symbol or a list where the first element is AND, OR, or NOT and any remaining elements (NOT requires exactly one) are feature expressions. A symbol is true if it is a member (by test function EQ) of the list in global variable
*FEATURES*. Init.lsp defines one initial feature, :XLISP, and the features :TIMES, :GENERIC, :POSFCNS (various position functions), :MATH (complex math), :PC8 (character set), :PACKAGES, and :MULVALS depending on the coresponding feature having been compiled into the XLISP executable. Utility files supplied with XLISP-PLUS generally add new features which are EQ to the keyword made from their file names.


XLISP-PLUS - Version 2.1g - Tom Almy tom.almy@tek.com - 18 JUL 94
Generated with
WebMaker