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

Syntax:

22.1.5 24 !!! Name this function1 argument something better. -kmp 15-Oct-91

get-dispatch-macro-character disp-char sub-char &optional readtable function

22.1.5 23

set-dispatch-macro-character disp-char sub-char new-function &optional readtable t

Arguments and Values:

disp-char—a character.

sub-char—a character.

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

function—a function designator or nil.

I made this a function designator. See reasoning for get-macro-character. -kmp 20-Sep-91new-function—a function designator.

Description:

set-dispatch-macro-character causes new-function to be called when disp-char followed by sub-char is read. 22.1.5 22If sub-char is a lowercase letter, it is converted to its uppercase equivalent. It is an error if sub-char is one of the ten decimal digits.

set-dispatch-macro-character installs a new-function to be called when a particular dispatching macro character pair is read. New-function is installed as the dispatch function to be called when readtable is in use and when disp-char is followed by sub-char.

This information is now available elsewhere. !!! current input stream? this means the stream on which the char was seen. be more specific so people don't think this is standard input or something weird like that. The three arguments to \param{new-function} are the current input \term{stream}, \param{sub-char}, and the \term{integer} whose decimal representation appeared between \param{disp-char} and \param{sub-char}, or \nil\ if no decimal integer appeared there; .For more information about how the new-function is invoked, see Section 2.1.4.4 (Macro Characters).

get-dispatch-macro-character retrieves the dispatch function associated with disp-char and sub-char in readtable.

get-dispatch-macro-character returns the macro-character function for sub-char under disp-char, or nil if there is no function associated with sub-char. If sub-char is a decimal digit, get-dispatch-macro-character returns nil.

Examples:

!!! The use of (values) here is really questionable! -kmp 1-May-91

 (get-dispatch-macro-character #\# #\{) → NIL
 (set-dispatch-macro-character #\# #\{        ;dispatch on #{
    #'(lambda(s c n)
        (let ((list (read s nil (values) t)))  ;list is object after #n{
          (when (consp list)                   ;return nth element of list
            (unless (and n (< 0 n (length list))) (setq n 0))
            (setq list (nth n list)))
         list))) → T
 #{(1 2 3 4) → 1
 #3{(0 1 2 3) → 3
 #{123 → 123
22.1.5 27If it is desired that #$foo : as if it were (dollars foo).

(defun |#$-reader| (stream subchar arg)
   (declare (ignore subchar arg))
   (list 'dollars (read stream t nil t))) → |#$-reader|
 (set-dispatch-macro-character #\# #\$ #'|#$-reader|) → T
\code (get-dispatch-macro-character #\\# #\\\{) \EV NIL (unless (get-dispatch-macro-character #\\# #\\x) (warn "Hexadecimal input (#x<ddd>) is disabled")) \EV NIL (let ((previous-fun (get-dispatch-macro-character #\\# #\\\{))) (when previous-fun (set-dispatch-macro-character #\\# #\\\{ #'(lambda (stream char arg) (setq stream *debug-io*) (when *debug-macro-chars* (format *trace-output* "~&Occurrence of ~C~C on stream ~S" #\\# #\\\{ stream)) (list (funcall previous-fun stream char)))))) \EV NIL \endcode

See Also:

Section 2.1.4.4 (Macro Characters)

Side Effects:

The readtable is modified.

Affected By:

*readtable*.

Exceptional Situations:

22.1.5 26For either function, an error is signaled if disp-char is not a dispatching macro character in readtable.

See Also:

*readtable*

Notes:

It is necessary to use make-dispatch-macro-character to set up the dispatch character before specifying its sub-characters.