XLISP > XLISP Plus  -  Previous | Next

get-macro-character


Type:   -   defined function (closure)
Source:   -   init.lsp

Syntax

(get-macro-character char)
char - a character
returns - the code associated with the *readtable* entry or NIL

Description

The 'get-macro-character' function returns the code that will be executed when the specified character 'char' is encountered by the XLISP reader. The returned value is taken from 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 NIL , :constituent , :sescape , :mescape , :white-space , a :tmacro dotted pair or a :nmacro dotted pair.

The 'get-macro-character' function will return a NIL value if the table entry is NIL , :constituent , :sescape , :mescape or :white-space. If the table entry is :tmacro or :nmacro , then the code associated with the entry is returned. :tmacro is used for a terminating read-macro. :nmacro is used for a non-terminating read-macro. 'get-macro-character' does not differentiate whether the code returned is a :tmacro or an :nmacro.

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.

(defun get-macro-character (ch)
  (if (consp (aref *readtable* (char-int ch)))
      (cdr (aref *readtable* (char-int ch)))
    nil))

Note: This function is not included in the standard Nyquist distribution. If you want to use it, copy the code above to your 'init.lsp' file.

Examples

(get-macro-character #\()      ; returns #<Subr-: #...>
(get-macro-character #\#)      ; returns #<Subr-: #...>
(get-macro-character #\Space)  ; returns NIL

Note: In the normal XLISP system the following characters have code associated with them in the *readtable*:

  "   #   '   (   )   ,   ;   `

[double-quote, hash, quote, opening parenthesis, closing parenthesis, comma, semicolon, backquote]

Common Lisp: The 'get-macro-character' function is somewhat related to the Common Lisp 'get-dispatch-macro-character' function.

See also the XLISP Plus set-macro-character function.

  Back to Top


XLISP > XLISP Plus  -  Previous | Next