Search code examples
lispcommon-lispsbclreserved-words

Lisp: Where can I find a list of reserved characters for sbcl?


Is anyone able to point to a list of reserved characters for Lisp? I'm trying to start up some non-trivial programs for learning purposes. I can find the functions that already exist using emacs, but I can't find a compiled list of reserved characters and strings like `, ,, and #\.

Most tutorials tend to talk about them only when they're applicable to the specific example, or they talk about high-level expression syntax.


Solution

  • You mean like characters which are not allowed in symbols in Common Lisp? Given that SBCL is an implementation of the Common Lisp language?

    Actually there are virtually none. If you use a character/string like , or #\, then one can escape them:

    CL-USER 16 > '( | a A | |,| |#\\.| a\ \,\ )
    (| a A | \, \#\\. A\ \,\ )
    
    CL-USER 17 > (mapcar #'symbol-name *)
    (" a A " "," "#\\." "A , ")
    
    CL-USER 18 > (mapcar #'length *)
    (5 1 3 4)
    

    Additionally here is an overview for characters in the default s-expression reader: 2.1.4 Character Syntax Types and 2.4 Standard Macro Characters

    Note that Common Lisp was defined before Unicode was a thing. But nowadays many Unicode aware implementations also allow Unicode 'characters' in symbols.

    * (list (code-char 300) (code-char 323) (code-char 812))
    (#\LATIN_CAPITAL_LETTER_I_WITH_BREVE #\LATIN_CAPITAL_LETTER_N_WITH_ACUTE
     #\COMBINING_CARON_BELOW)
    * (coerce * 'string)
    "ĬŃ̬"
    * (make-symbol *)
    #:ĬŃ̬