Lisp Book

Gene Michael Stover

created Monday, 31 May 2004
updated Saturday, 2005 June 18

Copyright © 2004 Gene Michael Stover. All rights reserved. Permission to copy, store, & view this document unmodified & in its entirety is granted.


Contents

1 Introduction

Lisp Book is a Lisp program that eats Lisp souce code & produces a cross-referenced document for human consuption.

As of Monday, 31 May 2004, Lisp Book is totally experimental. It's non-function. It's a work in progress. Some of the text in this article was generated by a proto version of Lisp Book. I'm not sure the idea is worth persuing; it was just a quick experiment.

As of Saturday, 2005 June 18, I think I wrote the very first draft of this - single sitting kind of stuff, & haven't looked at it again until now. It is safe to ignore.

2 License

The Lisp Book source code I describe is licensed according to the GNU Lesser General Public License.

This article is not covered by the Gnu Lesser General Public License. It is covered by its own copyright notice which is at the beginning of the article.

3 Obtaining

The Lisp Book source code is not available yet.

4 All Defuns

5 All Defvars

There are no DEFVARs.


6 LISPBOOK

File: lispbook.lisp
(DEFUN LISPBOOK (LST STRM)
  "Produce a Lisp Book from the Lisp source files in LST.  Each element in
LST is a pathname for a Lisp file.  Output goes to STRM which must be an
output stream which can write characters."
  (LET ((INDEX (SCAN-FILES LST)))
    (WRITE-SECTION-DEFUN INDEX STRM)
    (WRITE-SECTION-DEFVAR INDEX STRM)
    (DOLIST (X INDEX) (WRITE-SECTION X STRM))
    (FORMAT STRM "~%"))
  'LISPBOOK)


7 LISPBOOK-MYSELF

File: lispbook.lisp
(DEFUN LISPBOOK-MYSELF ()
  (WITH-OPEN-FILE
      (STRM (MAKE-PATHNAME :NAME "lispbook" :TYPE "tex")
            :DIRECTION
            :OUTPUT
            :IF-EXISTS
            :SUPERSEDE
            :IF-DOES-NOT-EXIST
            :CREATE)
    (LISPBOOK (LIST (MAKE-PATHNAME :NAME "lispbook" :TYPE "lisp")) STRM))
  'LISPBOOK-MYSELF)


8 MAKE-LABEL

File: lispbook.lisp
(DEFUN MAKE-LABEL (ITEM)
  "Return a LaTeX label for the item.  The label is a string."
  (COND
   ((AND (LISTP (FIRST ITEM)) (MEMBER (FIRST (FIRST ITEM)) '(DEFUN DEFVAR)))
    (FORMAT NIL "~A-~A" (FIRST (FIRST ITEM)) (SECOND (FIRST ITEM))))
   (T (FORMAT NIL "huh-~A" (FIRST ITEM)))))


9 SCAN-FILE

File: lispbook.lisp
(DEFUN SCAN-FILE (PN)
  "PN names a Lisp source code file.  Scan the file to produce an index.
Return the index."
  (LET (INDEX)
    (WITH-OPEN-FILE (STRM PN)
      (DO ((X (READ STRM NIL STRM) (READ STRM NIL STRM)))
          ((EQ X STRM))
        (WHEN (AND (LISTP X) (MEMBER (CAR X) '(DEFUN DEFVAR)))
          (PUSH (LIST X PN) INDEX))))
    INDEX))


10 SCAN-FILES

File: lispbook.lisp
(DEFUN SCAN-FILES (LST)
  "LST is a list of pathnames that identify Lisp source files.  Load the
files into an index.  Return the index."
  (SORT (COPY-LIST (APPLY #'APPEND (MAPCAR #'SCAN-FILE LST)))
        #'STRING-LESSP
        :KEY
        #'(LAMBDA (X) (SYMBOL-NAME (SECOND (FIRST X))))))


11 WRITE-SECTION

File: lispbook.lisp
(DEFUN WRITE-SECTION (X STRM)
  "Write a LaTeX section about the index item X.  It may be a DEFUN or a
DEFVAR."
  (LET ((*PRINT-PRETTY* T) (*PRINT-LENGTH* NIL))
    (FORMAT STRM
            "~%~%\\section{~A}~&\\label{~A}"
            (SECOND (FIRST X))
            (MAKE-LABEL X))
    (FORMAT STRM
            "~&\\noindent {\\bf File}: ~{~A/~}~A.~A"
            (PATHNAME-DIRECTORY (SECOND X))
            (PATHNAME-NAME (SECOND X))
            (PATHNAME-TYPE (SECOND X)))
    (FORMAT STRM "~&\\begin{verbatim}~&~S~&\\end{}{verbatim}" (FIRST X)))
  'WRITE-SECTION)


12 WRITE-SECTION-DEFUN

File: lispbook.lisp
(DEFUN WRITE-SECTION-DEFUN (INDEX STRM)
  "Write a section that lists all the DEFUNs."
  (FORMAT STRM "~%~%\\section{All Defuns}")
  (COND
   ((FIND 'DEFUN
          INDEX
          :KEY
          #'(LAMBDA (X) (AND (LISTP (FIRST X)) (FIRST (FIRST X)))))
    (FORMAT STRM "~&\\begin{itemize}")
    (DOLIST (X INDEX)
      (WHEN (AND (LISTP (FIRST X)) (EQ (FIRST (FIRST X)) 'DEFUN))
        (FORMAT STRM
                "~&\\item \\htmladdnormallink{~A}{~A}"
                (SECOND (FIRST X))
                (MAKE-LABEL X))))
    (FORMAT STRM "~&\\end{itemize}"))
   (T (FORMAT STRM "~%~%There are no ~As." 'DEFUN)))
  'WRITE-SECTION-DEFUN)


13 WRITE-SECTION-DEFVAR

File: lispbook.lisp
(DEFUN WRITE-SECTION-DEFVAR (INDEX STRM)
  "Write a section that lists all the DEFVARs."
  (FORMAT STRM "~%~%\\section{All Defvars}")
  (COND
   ((FIND 'DEFVAR
          INDEX
          :KEY
          #'(LAMBDA (X) (AND (LISTP (FIRST X)) (FIRST (FIRST X)))))
    (FORMAT STRM "~&\\begin{itemize}")
    (DOLIST (X INDEX)
      (WHEN (AND (LISTP (FIRST X)) (EQ (FIRST (FIRST X)) 'DEFVAR))
        (FORMAT STRM
                "~&\\item \\htmladdnormallink{~A}{~A}"
                (SECOND (FIRST X))
                (MAKE-LABEL X))))
    (FORMAT STRM "~&\\end{itemize}"))
   (T (FORMAT STRM "~%~%There are no ~As." 'DEFVAR)))
  'WRITE-SECTION-DEFVAR)

A. Other File Formats

This document is available in multi-file HTML format at http://lisp-p.org/lbo/.

This document is available in DVI format at http://lisp-p.org/lbo/lbo.dvi.

This document is available in PostScript format at http://lisp-p.org/lbo/lbo.ps.

Bibliography

Fou
Free Software Foundation.
Lesser general public license.
world wide web.
http://www.gnu.org/licenses/licenses.html#LGPL.

Gene Michael Stover 2008-04-20