lispcommon-lispreader-macro

What is the meaning of #+: and #-: in common lisp


I am reading the cl-fad/load.lisp code tonight, and I found there are symbols #+: and #-: in the front of expression or string.

What's these symbols meaning?


Solution

  • These are a read-time conditionalization facility: #+ and #- let you decide what expression to read based on Feature Expressions.

    E.g.,

    #+:allegro (require :osi)
    #+:sbcl (require :sb-executable)
    

    means that when running under allegro, the module :osi will be loaded, but when running under sbcl, the module :sb-executable will be loaded by require.

    Under all other implementations require will not be called at all because read will skip over the forms.

    You can check not just the implementation name, but a specific feature, e.g.,

    #+(<= (integer-length most-positive-fixnum) 32)
    code for a 32-bit lisp
    #+(> (integer-length most-positive-fixnum) 32)
    code for a 64-bit lisp
    

    In addition to selecting code based on implementation, this allows one to easily "comment out" a section of your code (i.e., the next sexp):

    #+(or) (this code will be skipped over by any lisp reader
            because (or) returns nil)