The 'set-macro-character' function installs the code that will be
executed when the specified character 'char-num' is encountered by the XLISP
reader. The 'function' is placed in the
*readtable* system variable which contains
the reader table array. The table is 128 entries [0..127] for each of the
7-bit ASCII characters that
XLISP can read. Each entry in the table must be
one of
The 'set-macro-character' function only allows you to put in a
terminating read-macro function :tmacro or
a non-terminating read-macro-function
:nmacro. If the 'termflag' is present and
non-
The 'function' takes two parameters, an input stream specification, and an integer that is the character value. The 'function' should return NIL if the character is 'white-space' or a value consed with NIL to return the value. The function 'set-macro-character' always returns T .
(defun set-macro-character (ch fun &optional tflag) (setf (aref *readtable* (char-int ch)) (cons (if tflag :tmacro :nmacro) fun)) t)
Note: The 'set-macro-character' function is not included in the standard Nyquist distribution. If you want to use it, copy the code to your 'init.lsp' file.
(print "hi") % comment ; prints "hi" and gives ; error: unbound variable - % ; because % is viewed as a variable (setq semi (get-macro-character #\;)) ; get semi-colon code (SET-MACRO-CHARACTER #\% semi T) ; set % to work as a comment (print "hi") % comment ; prints "hi" and no error because ; % is now a comment character in *READTABLE*
Note: In the normal XLISP system the following characters have code associated with them in the *readtable*:
" # ' ( ) , ; `
[double-quote, hash, single quote, opening parenthesis, closing parenthesis, comma, semicolon, backquote.]
Common Lisp: The 'set-macro-character function' is somewhat related to the Common Lisp 'set-dispatch-macro-character' function.
See also the XLISP Plus get-macro-character function.