macroslispcommon-lispclisp

Describe for LISP-Macros


I have used CLISP for some time now, and I'd say, that I finally came to "understand" macros. Now I have one question here: Is there something similar to describe for functions but for macros? I would like to put a docstring in my macro so that someone can look at it using a "describe-esk" function / macro on my macro. If that wasn't clear enough, maybe this code example will clear it up for you:

(defmacro while (test &body body)
  "sexier while loop - usage: (while (< x 10) (princ x) (setf x (+ x 1)))"
  (list 'loop 'while test 'do (cons 'progn body)))

(describe-macro 'while)
#=>sexier while loop - usage: (while (< x 10) (princ x) (setf x (+ x 1)))
#=>args: test, body

Thank you very much.


Solution

  • (documentation <x> 'function) will provide you with the documentation of <x> as a function or macro:

    > (documentation 'collecting 'function)
    "Collect things into a list forwards.
    
    Within the body of this macro The form `(COLLECT THING)' will collect
    THING into the list returned by COLLECTING.  COLLECT is a local
    function so can be passed as an argument, or returned.  COLLECT
    returns its argument. See WITH-COLLECTORS for which this COLLECTING is
    now a shim"
    

    describe may also tell you useful things. Typically programming environments like SLIME will also have all sorts of useful help available. I don't know SLIME very well, but in LW the Show Documentation command when the cursor is over collecting pops up a window which shows

    Documentation for (defmacro collecting):
    Arguments: (&body forms)
    <docstring as above>