(defun read-from-string (string) (read (make-string-input-stream string)))
The *readtable* system
variable contains the reader table array.
See also the
(defun print-readtable () (dotimes (index 128) (format t "ASCII-~a ~a = ~a~%" (cond ((<= 0 index 9) (format nil "00~a" index)) ((<= 10 index 99) (format nil "0~a" index)) (t index)) (if (< 31 index 127) (code-char index) (case index (0 "[null] ") (1 "[start of heading] ") (2 "[start of text] ") (3 "[end of text] ") (4 "[end of transmission] ") (5 "[enquiry] ") (6 "[acknowledge] ") (7 "[terminal bell] ") (8 "[backspace] ") (9 "[horizontal tab] ") (10 "[line feed] ") (11 "[vertical tab] ") (12 "[form feed] ") (13 "[carriage return] ") (14 "[shift out] ") (15 "[shift in] ") (16 "[data link escape] ") (17 "[device control 1, xon] ") (18 "[device control 2] ") (19 "[device control 3, xoff]") (20 "[device control 4] ") (21 "[negative acknowledge] ") (22 "[synchronous idle] ") (23 "[end transmission block]") (24 "[cancel line] ") (25 "[end of medium] ") (26 "[substitute] ") (27 "[escape] ") (28 "[file separator] ") (29 "[group separator] ") (30 "[record separator] ") (31 "[unit separator] ") (127 "[delete]"))) (aref *readtable* index))))
(defun get-macro-character (char) (if (consp (aref *readtable* (char-code char))) (cdr (aref *readtable* (char-int char))) nil))
The '
The 'get-macro-character' function will return a
NIL value if the table entry is
The function returned may be a built-in read-macro function or a user defined lambda expression. 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.
Examples:
(get-macro-character #\() => #<Subr-(null): #...> (get-macro-character #\#) => #<Subr-(null): #...> (get-macro-character #\Space) => NIL
(defun set-macro-character (char function &optional terminate-p) (setf (aref *readtable* (char-code char)) (cons (if terminate-p :tmacro :nmacro) function)) t)
The '
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 .
Examples:
> (print "hi") % comment "hi" "hi" error: unbound variable - % ; % is interpreted as a variable > (setq readtable-backup *readtable*) #( ... very-long-value ... ) > (set-macro-character #\% (get-macro-character #\;) t) T > (print "hi") % comment "hi" ; no error because "hi" ; % is now a comment character > (setq *readtable* readtable-backup) #( ... very-long-value ... )
Important: before manipulating the XLISP *readtable* it's always a good idea to store the original contents in some other variable.