Copyright © 2004 Gene Michael Stover. All rights reserved. Permission to copy, store, & view this document unmodified & in its entirety is granted.
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.
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.
The Lisp Book source code is not available yet.
There are no DEFVARs.
(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)
(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)
(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)))))
(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))
(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))))))
(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)
(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)
(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)
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.
Gene Michael Stover 2008-04-20