Structural Informatics Group (SIG) logo
Home | Projects | Demos | Downloads | Publications | Local Info | About Us | New site
Go to the first, previous, next, last section, table of contents.

set-macro-character

set-macro-character

type: defined function (closure) 
location: extension
source file: init.lsp
Common LISP compatible: related
supported on: all machines

SYNTAX

(set-macro-character <char-num> <function>  [ <termflag> ] )
        <char-num>      -       an integer expression
        <function>      -       a function definition
        <termflag>      -       an expression - NIL or non-NIL

DESCRIPTION

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 NIL, :CONSTITUENT, :SESCAPE, :MESCAPE, :WHITE-SPACE, a :TMACRO dotted pair or a :NMACRO dotted pair. 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-NIL, then the <function> will be put in *READTABLE* as a :TMACRO entry. If <termflag> is not present or NIL, then <function> will be put in *READTABLE* as a :NMACRO entry. The <function> can be a built-in read-macro function or a user defined defun symbol or a 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. The function SET-MACRO-CHARACTER always returns T.

EXAMPLES

(print "hi") % comment                  ; prints  "hi"  and gives
                                        ; error: unbound variable - %
                                        ; because percent 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*:

" # ' ( ) , ; `

NOTE: The functions GET-MACRO-CHARACTER and SET-MACRO-CHARACTER are created in the INIT.LSP file. If they do not exist in your XLISP system, you might be having a problem with INIT.LSP. Before you start XLISP, look in the directory you are currently in, and check to see if there is an INIT.LSP.

COMMON LISP COMPATIBILITY: The SET-MACRO-CHARACTER function is somewhat related to the Common LISP SET-DISPATCH-MACRO-CHARACTER function.


Go to the first, previous, next, last section, table of contents.