Function set-macro-character, get-macro-character

Syntax:

22.1.5 13

get-macro-character char &optional readtable function, non-terminating-p

set-macro-character char new-function &optional non-terminating-p readtable t

Arguments and Values:

char—a character.

non-terminating-p—a generalized boolean. The default is false.

readtable—a readtable designator. The default is the current readtable.

functionnil, or a designator for a function of two arguments.

new-function—a function designator.

Description:

function or function designator? -kmp 29-Apr-91 I made it be a function designator since this is consistent with the CLtL treatment of symbols as functions, and since some implementation might consider it a feature to carry around the name instead of the definition, so the user could redefine the function and have his new definition take automatically. -kmp 20-Sep-91

get-macro-character returns as its primary value, function, the reader macro function associated with char in readtable (if any), or else nil if char is not a macro character in readtable. The secondary value, non-terminating-p, is true if char is a non-terminating macro character; otherwise, it is false.

set-macro-character causes char to be a macro character associated with the reader macro function new-function (or the designator for new-function) in readtable. If non-terminating-p is true, char becomes a non-terminating macro character; otherwise it becomes a terminating macro character.

This information can be gotten from the Reader Algorithm. -kmp 23-Jan-92 In the simplest case, \param{new-function} may return an \term{object}. This \term{object} is taken to be that whose printed representation was \param{char} and any following characters read by \param{new-function}. 22.1.5 15 \param{New-function} may choose instead to return zero values. In this case, \param{char} and whatever it may have read contribute nothing to the \term{object} being read. 22.1.5 16 \param{New-function} should not have any side effects other than on the \term{stream}; because of backtracking and restarting of the \funref{read} operation, front ends (such as editors and rubout handlers) to the reader may cause \param{new-function} to be called repeatedly during the reading of a single expression in which \param{char} only appears once.

Examples:

 (get-macro-character #\{) → NIL, false
 (not (get-macro-character #\;)) → false

The following is a possible definition for the single-quote reader macro in standard syntax:

 (defun single-quote-reader (stream char)
   (declare (ignore char))
   (list 'quote (read stream t nil t))) → SINGLE-QUOTE-READER
 (set-macro-character #\' #'single-quote-reader) → T

Here single-quote-reader reads an object following the single-quote and returns a list of quote and that object. The char argument is ignored.

The following is a possible definition for the semicolon reader macro in standard syntax:

 (defun semicolon-reader (stream char)
   (declare (ignore char))
   ;; First swallow the rest of the current input line.
   ;; End-of-file is acceptable for terminating the comment.
   (do () ((char= (read-char stream nil #\Newline t) #\Newline)))
   ;; Return zero values.
   (values)) → SEMICOLON-READER
 (set-macro-character #\; #'semicolon-reader) → T

Side Effects:

The readtable is modified.

Affected By:

None.

Exceptional Situations:

None.

See Also:

*readtable*

Notes:

None.