From nsiivola at common-lisp.net Mon Mar 8 10:49:17 2010 From: nsiivola at common-lisp.net (Nikodemus Siivola) Date: Mon, 08 Mar 2010 05:49:17 -0500 Subject: [alexandria-cvs] [alexandria.git] updated branch master: 0358465... faster WHICHEVER Message-ID: The branch master has been updated: via 035846561e47e1f7531f21e49cacc58f007cfc9b (commit) from 66bd88d5eab762a6080ec4be197b82570d9e7b49 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 035846561e47e1f7531f21e49cacc58f007cfc9b Author: Nikodemus Siivola Date: Mon Mar 8 10:46:37 2010 +0200 faster WHICHEVER O(log n) instead of O(n). Patch by: Gustavo ----------------------------------------------------------------------- Summary of changes: control-flow.lisp | 23 ++++++++++++++--------- 1 files changed, 14 insertions(+), 9 deletions(-) diff --git a/control-flow.lisp b/control-flow.lisp index 42a88f9..bf64728 100644 --- a/control-flow.lisp +++ b/control-flow.lisp @@ -52,15 +52,20 @@ returns the values of DEFAULT if no keys match." (setf possibilities (mapcar (lambda (p) (macroexpand p env)) possibilities)) (if (every (lambda (p) (constantp p)) possibilities) `(svref (load-time-value (vector , at possibilities)) (random ,(length possibilities))) - (with-gensyms (function) - `(let ((,function (lambda () ,(pop possibilities)))) - (declare (function ,function)) - ,@(let ((p 1)) - (mapcar (lambda (possibility) - `(when (zerop (random ,(incf p))) - (setf ,function (lambda () ,possibility)))) - possibilities)) - (funcall ,function))))) + (labels ((expand (possibilities position random-number) + (if (null (cdr possibilities)) + (car possibilities) + (let* ((length (length possibilities)) + (half (truncate length 2)) + (second-half (nthcdr half possibilities)) + (first-half (butlast possibilities (- length half)))) + `(if (< ,random-number ,(+ position half)) + ,(expand first-half position random-number) + ,(expand second-half (+ position half) random-number)))))) + (with-gensyms (random-number) + (let ((length (length possibilities))) + `(let ((,random-number (random ,length))) + ,(expand possibilities 0 random-number))))))) (defmacro xor (&rest datums) "Evaluates its argument one at a time, from left to right. If more then one -- Alexandria hooks/post-receive From nsiivola at common-lisp.net Mon Mar 8 10:52:54 2010 From: nsiivola at common-lisp.net (Nikodemus Siivola) Date: Mon, 08 Mar 2010 05:52:54 -0500 Subject: [alexandria-cvs] updated branch master: b5cc04c... missing earmuff in tests.lisp Message-ID: The branch master has been updated: via b5cc04c27491e872065821b7f2aae24d3701b6c0 (commit) from 035846561e47e1f7531f21e49cacc58f007cfc9b (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit b5cc04c27491e872065821b7f2aae24d3701b6c0 Author: Nikodemus Siivola Date: Mon Mar 8 10:52:04 2010 +0200 missing earmuff in tests.lisp Patch by: Peter Graves ----------------------------------------------------------------------- Summary of changes: tests.lisp | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/tests.lisp b/tests.lisp index f717402..e2904cc 100644 --- a/tests.lisp +++ b/tests.lisp @@ -7,7 +7,7 @@ (in-package :alexandria-tests) -(defun run-tests (&key ((:compiled *compile-tests))) +(defun run-tests (&key ((:compiled *compile-tests*))) (do-tests)) ;;;; Arrays -- Alexandria hooks/post-receive From nsiivola at common-lisp.net Mon Mar 8 10:57:26 2010 From: nsiivola at common-lisp.net (Nikodemus Siivola) Date: Mon, 08 Mar 2010 05:57:26 -0500 Subject: [alexandria-cvs] updated branch master: 681f873... minimal README Message-ID: The branch master has been updated: via 681f8735c613fa96a9cf12ddf76ce45197745011 (commit) from b5cc04c27491e872065821b7f2aae24d3701b6c0 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 681f8735c613fa96a9cf12ddf76ce45197745011 Author: Nikodemus Siivola Date: Mon Mar 8 12:57:12 2010 +0200 minimal README ----------------------------------------------------------------------- Summary of changes: README | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) create mode 100644 README diff --git a/README b/README new file mode 100644 index 0000000..930e7ec --- /dev/null +++ b/README @@ -0,0 +1,3 @@ +Alexandria + +A collection of portable public domain utilities for Common Lisp. -- Alexandria hooks/post-receive From nsiivola at common-lisp.net Mon Mar 8 11:27:26 2010 From: nsiivola at common-lisp.net (Nikodemus Siivola) Date: Mon, 08 Mar 2010 06:27:26 -0500 Subject: [alexandria-cvs] updated branch master: a2c71ef... add usage and all targets to doc/Makefile Message-ID: The branch master has been updated: via a2c71efed048596cb0fbc734e814248d00a2601f (commit) from 681f8735c613fa96a9cf12ddf76ce45197745011 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit a2c71efed048596cb0fbc734e814248d00a2601f Author: Nikodemus Siivola Date: Mon Mar 8 13:25:49 2010 +0200 add usage and all targets to doc/Makefile Running "clean" by default is was a bit odd... Reported by: Daniel Herring ----------------------------------------------------------------------- Summary of changes: doc/Makefile | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-) diff --git a/doc/Makefile b/doc/Makefile index 5ae667c..22d1c5f 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -1,4 +1,9 @@ -.PHONY: clean html pdf +.PHONY: usage all clean html pdf + +usage: + @echo "Targets: all, clean, html, pdf" + +all: html pdf clean: rm -rf include *.aux *.cp *.fn *.fns *.ky *.log *.pg *.toc *.tp *.tps *.vr *.pdf *.html -- Alexandria hooks/post-receive From nsiivola at common-lisp.net Mon Mar 8 11:50:37 2010 From: nsiivola at common-lisp.net (Nikodemus Siivola) Date: Mon, 08 Mar 2010 06:50:37 -0500 Subject: [alexandria-cvs] updated branch master: 34949e1... new macro: ENSUREF Message-ID: The branch master has been updated: via 34949e184e892240d0197bae46ad0924fcb2f51b (commit) from a2c71efed048596cb0fbc734e814248d00a2601f (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 34949e184e892240d0197bae46ad0924fcb2f51b Author: Nikodemus Siivola Date: Mon Mar 8 13:48:49 2010 +0200 new macro: ENSUREF Code by: Tobias C. Rittweiler ----------------------------------------------------------------------- Summary of changes: control-flow.lisp | 39 +++++++++++++++++++++++++++++++++++++++ package.lisp | 1 + 2 files changed, 40 insertions(+), 0 deletions(-) diff --git a/control-flow.lisp b/control-flow.lisp index bf64728..8225442 100644 --- a/control-flow.lisp +++ b/control-flow.lisp @@ -104,3 +104,42 @@ NIL." "Like CL:MULTIPLE-VALUE-PROG1, except it saves the values of the second form." `(progn ,first-form (multiple-value-prog1 ,second-form , at body))) + +(defmacro ensuref (place thing &rest more &environment env) + "If PLACE evaluates to NIL set it to THING, otherwise leave PLACE unchanged. + +\(ENSUREF PLACE THING) is approximately equivalent to + + (SETF PLACE (OR PLACE THING)) + +except that ENSUREF ensures that PLACE is evaluated only once, and except that +PLACE isn't set at all if it evaluated to NIL. + +Example: + + (let ((a nil) + (b :foo) + (c (list 1 2 nil 4))) + (ensuref a :a + b :b + (third c) :c) + (values a b c)) + + ==> :A, :FOO, (1 2 :C 4) +" + (multiple-value-bind (gvars vals gstorevars setter getter) + (get-setf-expansion place env) + (when (second gstorevars) + (error "ENSUREF does not support setting multiple values ~ + via the (VALUES ...) place.")) + (if (null more) + (let ((gstorevar (first gstorevars)) + (gtmp (gensym "CURVAL+"))) + `(let ,(mapcar #'list gvars vals) + (let ((,gtmp ,getter)) + (if ,gtmp + ,gtmp + (let ((,gstorevar ,thing)) + ,setter))))) + `(progn (ensuref ,place ,thing) + (ensuref , at more))))) diff --git a/package.lisp b/package.lisp index 81c1e58..61ba06c 100644 --- a/package.lisp +++ b/package.lisp @@ -230,4 +230,5 @@ #:symbolicate #:assoc-value #:rassoc-value + #:ensuref )) -- Alexandria hooks/post-receive From nsiivola at common-lisp.net Mon Mar 8 12:02:24 2010 From: nsiivola at common-lisp.net (Nikodemus Siivola) Date: Mon, 08 Mar 2010 07:02:24 -0500 Subject: [alexandria-cvs] updated branch master: 2dfc9b5... fix: assoc-value setter now always returns the new value Message-ID: The branch master has been updated: discards 34949e184e892240d0197bae46ad0924fcb2f51b (commit) discards a2c71efed048596cb0fbc734e814248d00a2601f (commit) discards 681f8735c613fa96a9cf12ddf76ce45197745011 (commit) discards b5cc04c27491e872065821b7f2aae24d3701b6c0 (commit) discards 035846561e47e1f7531f21e49cacc58f007cfc9b (commit) discards 66bd88d5eab762a6080ec4be197b82570d9e7b49 (commit) This update discarded existing revisions and left the branch pointing at a previous point in the repository history. * -- * -- N (2dfc9b549ef963f4d2a895d0404259a5e69b6151) \ O -- O -- O (34949e184e892240d0197bae46ad0924fcb2f51b) The removed revisions are not necessarilly gone - if another reference still refers to them they will stay in the repository. No new revisions were added by this update. Summary of changes: README | 3 -- control-flow.lisp | 62 +++++++--------------------------------------------- doc/Makefile | 9 +------ package.lisp | 1 - tests.lisp | 2 +- 5 files changed, 12 insertions(+), 65 deletions(-) delete mode 100644 README diff --git a/README b/README deleted file mode 100644 index 930e7ec..0000000 --- a/README +++ /dev/null @@ -1,3 +0,0 @@ -Alexandria - -A collection of portable public domain utilities for Common Lisp. diff --git a/control-flow.lisp b/control-flow.lisp index 8225442..42a88f9 100644 --- a/control-flow.lisp +++ b/control-flow.lisp @@ -52,20 +52,15 @@ returns the values of DEFAULT if no keys match." (setf possibilities (mapcar (lambda (p) (macroexpand p env)) possibilities)) (if (every (lambda (p) (constantp p)) possibilities) `(svref (load-time-value (vector , at possibilities)) (random ,(length possibilities))) - (labels ((expand (possibilities position random-number) - (if (null (cdr possibilities)) - (car possibilities) - (let* ((length (length possibilities)) - (half (truncate length 2)) - (second-half (nthcdr half possibilities)) - (first-half (butlast possibilities (- length half)))) - `(if (< ,random-number ,(+ position half)) - ,(expand first-half position random-number) - ,(expand second-half (+ position half) random-number)))))) - (with-gensyms (random-number) - (let ((length (length possibilities))) - `(let ((,random-number (random ,length))) - ,(expand possibilities 0 random-number))))))) + (with-gensyms (function) + `(let ((,function (lambda () ,(pop possibilities)))) + (declare (function ,function)) + ,@(let ((p 1)) + (mapcar (lambda (possibility) + `(when (zerop (random ,(incf p))) + (setf ,function (lambda () ,possibility)))) + possibilities)) + (funcall ,function))))) (defmacro xor (&rest datums) "Evaluates its argument one at a time, from left to right. If more then one @@ -104,42 +99,3 @@ NIL." "Like CL:MULTIPLE-VALUE-PROG1, except it saves the values of the second form." `(progn ,first-form (multiple-value-prog1 ,second-form , at body))) - -(defmacro ensuref (place thing &rest more &environment env) - "If PLACE evaluates to NIL set it to THING, otherwise leave PLACE unchanged. - -\(ENSUREF PLACE THING) is approximately equivalent to - - (SETF PLACE (OR PLACE THING)) - -except that ENSUREF ensures that PLACE is evaluated only once, and except that -PLACE isn't set at all if it evaluated to NIL. - -Example: - - (let ((a nil) - (b :foo) - (c (list 1 2 nil 4))) - (ensuref a :a - b :b - (third c) :c) - (values a b c)) - - ==> :A, :FOO, (1 2 :C 4) -" - (multiple-value-bind (gvars vals gstorevars setter getter) - (get-setf-expansion place env) - (when (second gstorevars) - (error "ENSUREF does not support setting multiple values ~ - via the (VALUES ...) place.")) - (if (null more) - (let ((gstorevar (first gstorevars)) - (gtmp (gensym "CURVAL+"))) - `(let ,(mapcar #'list gvars vals) - (let ((,gtmp ,getter)) - (if ,gtmp - ,gtmp - (let ((,gstorevar ,thing)) - ,setter))))) - `(progn (ensuref ,place ,thing) - (ensuref , at more))))) diff --git a/doc/Makefile b/doc/Makefile index 22d1c5f..99d6afa 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -1,9 +1,4 @@ -.PHONY: usage all clean html pdf - -usage: - @echo "Targets: all, clean, html, pdf" - -all: html pdf +.PHONY: clean html pdf clean: rm -rf include *.aux *.cp *.fn *.fns *.ky *.log *.pg *.toc *.tp *.tps *.vr *.pdf *.html @@ -12,7 +7,7 @@ clean: # to bootrap documentation for now. include: sbcl --eval '(progn (require :asdf) (require :alexandria) (rename-package :alexandria :alexandria))' \ - --eval '(load (merge-pathnames "doc/manual/docstrings.lisp" (posix-getenv "SBCL_SOURCE_ROOT")))' \ + --eval '(load (merge-pathnames "doc/manual/docstrings" (posix-getenv "SBCL_SOURCE_ROOT")))' \ --eval '(sb-texinfo:generate-includes "include/" :alexandria)' \ --eval '(quit)' mv include/fun-alexandria-type=.texinfo include/fun-alexandria-type-equal.texinfo diff --git a/package.lisp b/package.lisp index 61ba06c..81c1e58 100644 --- a/package.lisp +++ b/package.lisp @@ -230,5 +230,4 @@ #:symbolicate #:assoc-value #:rassoc-value - #:ensuref )) diff --git a/tests.lisp b/tests.lisp index e2904cc..f717402 100644 --- a/tests.lisp +++ b/tests.lisp @@ -7,7 +7,7 @@ (in-package :alexandria-tests) -(defun run-tests (&key ((:compiled *compile-tests*))) +(defun run-tests (&key ((:compiled *compile-tests))) (do-tests)) ;;;; Arrays -- Alexandria hooks/post-receive From nsiivola at common-lisp.net Tue Mar 9 14:18:24 2010 From: nsiivola at common-lisp.net (Nikodemus Siivola) Date: Tue, 09 Mar 2010 09:18:24 -0500 Subject: [alexandria-cvs] updated branch master: d4a72df... robuster docstring generation Message-ID: The branch master has been updated: via d4a72df548269ed8cffb35876307c6ecb20625c1 (commit) from 2dfc9b549ef963f4d2a895d0404259a5e69b6151 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit d4a72df548269ed8cffb35876307c6ecb20625c1 Author: Nikodemus Siivola Date: Mon Mar 8 10:29:14 2010 +0200 robuster docstring generation SBCL makes a directory called doc/manual/docstrings; this interferes with loading the lisp file if the SBCL source tree had documentation built in it unless we use an explicit .lisp suffix. Patch by: Daniel Herring ----------------------------------------------------------------------- Summary of changes: doc/Makefile | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/doc/Makefile b/doc/Makefile index 99d6afa..5ae667c 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -7,7 +7,7 @@ clean: # to bootrap documentation for now. include: sbcl --eval '(progn (require :asdf) (require :alexandria) (rename-package :alexandria :alexandria))' \ - --eval '(load (merge-pathnames "doc/manual/docstrings" (posix-getenv "SBCL_SOURCE_ROOT")))' \ + --eval '(load (merge-pathnames "doc/manual/docstrings.lisp" (posix-getenv "SBCL_SOURCE_ROOT")))' \ --eval '(sb-texinfo:generate-includes "include/" :alexandria)' \ --eval '(quit)' mv include/fun-alexandria-type=.texinfo include/fun-alexandria-type-equal.texinfo -- Alexandria hooks/post-receive From nsiivola at common-lisp.net Tue Mar 9 14:22:56 2010 From: nsiivola at common-lisp.net (Nikodemus Siivola) Date: Tue, 09 Mar 2010 09:22:56 -0500 Subject: [alexandria.git] updated branch master: ada02b0... faster WHICHEVER Message-ID: The branch master has been updated: via ada02b061aac7cbbf43145beaf5d27d78f9e9fcc (commit) from d4a72df548269ed8cffb35876307c6ecb20625c1 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit ada02b061aac7cbbf43145beaf5d27d78f9e9fcc Author: Nikodemus Siivola Date: Mon Mar 8 10:46:37 2010 +0200 faster WHICHEVER Call RANDOM just once, and build an inline binary search tree for O(log n) goodness instead of O(n). Patch by: Gustavo ----------------------------------------------------------------------- Summary of changes: control-flow.lisp | 23 ++++++++++++++--------- 1 files changed, 14 insertions(+), 9 deletions(-) diff --git a/control-flow.lisp b/control-flow.lisp index 42a88f9..bf64728 100644 --- a/control-flow.lisp +++ b/control-flow.lisp @@ -52,15 +52,20 @@ returns the values of DEFAULT if no keys match." (setf possibilities (mapcar (lambda (p) (macroexpand p env)) possibilities)) (if (every (lambda (p) (constantp p)) possibilities) `(svref (load-time-value (vector , at possibilities)) (random ,(length possibilities))) - (with-gensyms (function) - `(let ((,function (lambda () ,(pop possibilities)))) - (declare (function ,function)) - ,@(let ((p 1)) - (mapcar (lambda (possibility) - `(when (zerop (random ,(incf p))) - (setf ,function (lambda () ,possibility)))) - possibilities)) - (funcall ,function))))) + (labels ((expand (possibilities position random-number) + (if (null (cdr possibilities)) + (car possibilities) + (let* ((length (length possibilities)) + (half (truncate length 2)) + (second-half (nthcdr half possibilities)) + (first-half (butlast possibilities (- length half)))) + `(if (< ,random-number ,(+ position half)) + ,(expand first-half position random-number) + ,(expand second-half (+ position half) random-number)))))) + (with-gensyms (random-number) + (let ((length (length possibilities))) + `(let ((,random-number (random ,length))) + ,(expand possibilities 0 random-number))))))) (defmacro xor (&rest datums) "Evaluates its argument one at a time, from left to right. If more then one -- Alexandria hooks/post-receive From nsiivola at common-lisp.net Tue Mar 9 14:59:21 2010 From: nsiivola at common-lisp.net (Nikodemus Siivola) Date: Tue, 09 Mar 2010 09:59:21 -0500 Subject: [alexandria.git] updated branch master: 81213e2... missing earmuff in tests.lisp Message-ID: The branch master has been updated: via 81213e29188d5ef8456b45a86c4ea765a69b283f (commit) from ada02b061aac7cbbf43145beaf5d27d78f9e9fcc (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 81213e29188d5ef8456b45a86c4ea765a69b283f Author: Nikodemus Siivola Date: Mon Mar 8 10:52:04 2010 +0200 missing earmuff in tests.lisp Patch by: Peter Graves ----------------------------------------------------------------------- Summary of changes: tests.lisp | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/tests.lisp b/tests.lisp index f717402..e2904cc 100644 --- a/tests.lisp +++ b/tests.lisp @@ -7,7 +7,7 @@ (in-package :alexandria-tests) -(defun run-tests (&key ((:compiled *compile-tests))) +(defun run-tests (&key ((:compiled *compile-tests*))) (do-tests)) ;;;; Arrays -- Alexandria hooks/post-receive From nsiivola at common-lisp.net Tue Mar 9 14:59:53 2010 From: nsiivola at common-lisp.net (Nikodemus Siivola) Date: Tue, 09 Mar 2010 09:59:53 -0500 Subject: [alexandria.git] updated branch master: 01a5b9b... minimal README Message-ID: The branch master has been updated: via 01a5b9bfcf13f927c38c59b3ad90bece3c0ecf2a (commit) from 81213e29188d5ef8456b45a86c4ea765a69b283f (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 01a5b9bfcf13f927c38c59b3ad90bece3c0ecf2a Author: Nikodemus Siivola Date: Mon Mar 8 12:57:12 2010 +0200 minimal README ----------------------------------------------------------------------- Summary of changes: README | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) create mode 100644 README diff --git a/README b/README new file mode 100644 index 0000000..930e7ec --- /dev/null +++ b/README @@ -0,0 +1,3 @@ +Alexandria + +A collection of portable public domain utilities for Common Lisp. -- Alexandria hooks/post-receive From nsiivola at common-lisp.net Tue Mar 9 16:53:04 2010 From: nsiivola at common-lisp.net (Nikodemus Siivola) Date: Tue, 09 Mar 2010 11:53:04 -0500 Subject: [alexandria.git] updated branch master: 829db7c... documentation updates Message-ID: The branch master has been updated: via 829db7c7cb06d0a1693af9d25292d666be3eb487 (commit) via b098d0fdb56da9a7ab7c040a6afd5d0b3e38208d (commit) from 01a5b9bfcf13f927c38c59b3ad90bece3c0ecf2a (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 829db7c7cb06d0a1693af9d25292d666be3eb487 Author: Nikodemus Siivola Date: Tue Mar 9 18:51:46 2010 +0200 documentation updates Add bunch of missing symbols to the manual, and go over several docstrings reformatting them for the benefit of the documentation generator. (A crapton of symbols are still not in the manual.) commit b098d0fdb56da9a7ab7c040a6afd5d0b3e38208d Author: Nikodemus Siivola Date: Tue Mar 9 18:50:29 2010 +0200 copy docstrings.lisp from SBCL Easier to work with like this. Note: the code has already mutated a bit. ----------------------------------------------------------------------- Summary of changes: arrays.lisp | 9 +- control-flow.lisp | 4 +- doc/Makefile | 7 +- doc/alexandria.texinfo | 138 +++++--- doc/docstrings.lisp | 864 ++++++++++++++++++++++++++++++++++++++++++++++++ functions.lisp | 1 + lists.lisp | 13 +- macros.lisp | 49 ++- numbers.lisp | 2 +- package.lisp | 2 +- sequences.lisp | 13 +- symbols.lisp | 5 +- 12 files changed, 1021 insertions(+), 86 deletions(-) create mode 100644 doc/docstrings.lisp diff --git a/arrays.lisp b/arrays.lisp index 146d7d3..670880f 100644 --- a/arrays.lisp +++ b/arrays.lisp @@ -5,9 +5,11 @@ (fill-pointer (and (array-has-fill-pointer-p array) (fill-pointer array))) (adjustable (adjustable-array-p array))) - "Returns an undisplaced copy of ARRAY, with same fill-pointer -and adjustability (if any) as the original, unless overridden by -the keyword arguments." + "Returns an undisplaced copy of ARRAY, with same fill-pointer and +adjustability (if any) as the original, unless overridden by the keyword +arguments. Performance depends on efficiency of general ADJUST-ARRAY in the +host lisp -- for most cases a special purpose copying function is likely to +perform better." (let ((dims (array-dimensions array))) ;; Dictionary entry for ADJUST-ARRAY requires adjusting a ;; displaced array to a non-displaced one to make a copy. @@ -16,4 +18,3 @@ the keyword arguments." :element-type element-type :fill-pointer fill-pointer :adjustable adjustable :displaced-to array) dims))) - diff --git a/control-flow.lisp b/control-flow.lisp index bf64728..0aafb2a 100644 --- a/control-flow.lisp +++ b/control-flow.lisp @@ -88,8 +88,8 @@ value." (defmacro nth-value-or (nth-value &body forms) "Evaluates FORM arguments one at a time, until the NTH-VALUE returned by one -of the forms is non-NIL. It then returns all the values returned by evaluating -that form. If none of the forms return a non-nil nth value, this form returns +of the forms is true. It then returns all the values returned by evaluating +that form. If none of the forms return a true nth value, this form returns NIL." (once-only (nth-value) (with-gensyms (values) diff --git a/doc/Makefile b/doc/Makefile index 5ae667c..0782a87 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -6,11 +6,10 @@ clean: # Hook into the super sekrit texinfo generator in the SBCL tree -- this is just a quick way # to bootrap documentation for now. include: - sbcl --eval '(progn (require :asdf) (require :alexandria) (rename-package :alexandria :alexandria))' \ - --eval '(load (merge-pathnames "doc/manual/docstrings.lisp" (posix-getenv "SBCL_SOURCE_ROOT")))' \ - --eval '(sb-texinfo:generate-includes "include/" :alexandria)' \ + sbcl --eval '(progn (require :asdf) (require :alexandria))' \ + --load docstrings.lisp \ + --eval '(sb-texinfo:generate-includes "include/" (list :alexandria) :base-package :alexandria)' \ --eval '(quit)' - mv include/fun-alexandria-type=.texinfo include/fun-alexandria-type-equal.texinfo pdf: include texi2pdf alexandria.texinfo diff --git a/doc/alexandria.texinfo b/doc/alexandria.texinfo index fc620dd..d9b23ce 100644 --- a/doc/alexandria.texinfo +++ b/doc/alexandria.texinfo @@ -13,10 +13,10 @@ @end direntry @copying - at quotation Alexandria software and associated documentation are in the public domain: + at quotation Authors dedicate this work to public domain, for the benefit of the public at large and to the detriment of the authors' heirs and successors. Authors intends this dedication to be an overt act of @@ -31,11 +31,13 @@ domain: built upon, or otherwise exploited by anyone for any purpose, commercial or non-commercial, and in any way, including by methods that have not yet been invented or conceived. + at end quotation In those legislations where public domain dedications are not recognized or possible, Alexandria is distributed under the following terms and conditions: + at quotation Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, @@ -70,19 +72,6 @@ terms and conditions: @ifnottex - at menu -* Hash Table Utilities:: -* Higher Order Functions:: -* List Manipulation:: -* Sequence Manipulation:: -* Macro Writing Utilities:: -* Symbol Utilities:: -* Array Utilities:: -* Type Designator Manipulation:: -* Mathematical Utilities:: -* Features:: - at end menu - @node Top @comment node-name, next, previous, up @top sbcl @@ -90,14 +79,24 @@ terms and conditions: @insertcopying @menu +* Hash Tables:: +* Data and Control Flow:: +* Conses:: +* Sequences:: +* Macro Writing:: +* Symbols:: +* Arrays:: +* Types:: +* Numbers:: @end menu @end ifnottex - at node Hash Table Utilities + at node Hash Tables @comment node-name, next, previous, up - at section Hash Table Utilities + at chapter Hash Tables + at include include/fun-alexandria-ensure-gethash.texinfo @include include/fun-alexandria-copy-hash-table.texinfo @include include/fun-alexandria-maphash-keys.texinfo @include include/fun-alexandria-maphash-values.texinfo @@ -108,43 +107,76 @@ terms and conditions: @include include/fun-alexandria-alist-hash-table.texinfo @include include/fun-alexandria-plist-hash-table.texinfo - at node Higher Order Functions + at node Data and Control Flow @comment node-name, next, previous, up - at section Higher Order Functions + at chapter Data and Control Flow + + at include include/macro-alexandria-define-constant.texinfo + at include include/macro-alexandria-ensure-functionf.texinfo + at include include/macro-alexandria-multiple-value-prog2.texinfo + at include include/macro-alexandria-named-lambda.texinfo + at include include/macro-alexandria-nth-value-or.texinfo + at include include/macro-alexandria-if-let.texinfo + at include include/macro-alexandria-when-let.texinfo + at include include/macro-alexandria-when-let-star.texinfo + at include include/macro-alexandria-switch.texinfo + at include include/macro-alexandria-cswitch.texinfo + at include include/macro-alexandria-eswitch.texinfo + at include include/macro-alexandria-whichever.texinfo + at include include/macro-alexandria-xor.texinfo @include include/fun-alexandria-disjoin.texinfo @include include/fun-alexandria-conjoin.texinfo @include include/fun-alexandria-compose.texinfo + at include include/fun-alexandria-ensure-function.texinfo @include include/fun-alexandria-multiple-value-compose.texinfo @include include/fun-alexandria-curry.texinfo @include include/fun-alexandria-rcurry.texinfo - at node List Manipulation + at node Conses @comment node-name, next, previous, up - at section List Manipulation + at chapter Conses @include include/type-alexandria-proper-list.texinfo @include include/type-alexandria-circular-list.texinfo + @include include/macro-alexandria-appendf.texinfo @include include/macro-alexandria-nconcf.texinfo - at include include/fun-alexandria-circular-list.texinfo + at include include/macro-alexandria-remove-from-plistf.texinfo + at include include/macro-alexandria-delete-from-plistf.texinfo + at include include/macro-alexandria-reversef.texinfo + at include include/macro-alexandria-nreversef.texinfo + at include include/macro-alexandria-unionf.texinfo + at include include/macro-alexandria-nunionf.texinfo + + at include include/macro-alexandria-doplist.texinfo + @include include/fun-alexandria-circular-list-p.texinfo @include include/fun-alexandria-circular-tree-p.texinfo @include include/fun-alexandria-proper-list-p.texinfo + + at include include/fun-alexandria-alist-plist.texinfo + at include include/fun-alexandria-plist-alist.texinfo + at include include/fun-alexandria-circular-list.texinfo + at include include/fun-alexandria-make-circular-list.texinfo + at include include/fun-alexandria-ensure-car.texinfo + at include include/fun-alexandria-ensure-cons.texinfo + at include include/fun-alexandria-ensure-list.texinfo + at include include/fun-alexandria-flatten.texinfo @include include/fun-alexandria-lastcar.texinfo @include include/fun-alexandria-setf-lastcar.texinfo + at include include/fun-alexandria-proper-list-length.texinfo @include include/fun-alexandria-make-circular-list.texinfo - at include include/fun-alexandria-ensure-list.texinfo - at include include/fun-alexandria-sans.texinfo @include include/fun-alexandria-mappend.texinfo @include include/fun-alexandria-map-product.texinfo + at include include/fun-alexandria-remove-from-plist.texinfo + at include include/fun-alexandria-delete-from-plist.texinfo @include include/fun-alexandria-set-equal.texinfo @include include/fun-alexandria-setp.texinfo - at include include/fun-alexandria-flatten.texinfo - at node Sequence Manipulation + at node Sequences @comment node-name, next, previous, up - at section Sequence Manipulation + at chapter Sequences @include include/type-alexandria-proper-sequence.texinfo @@ -152,70 +184,82 @@ terms and conditions: @include include/macro-alexandria-removef.texinfo @include include/fun-alexandria-rotate.texinfo - at include include/fun-alexandria-suffle.texinfo + at include include/fun-alexandria-shuffle.texinfo @include include/fun-alexandria-random-elt.texinfo @include include/fun-alexandria-emptyp.texinfo @include include/fun-alexandria-sequence-of-length-p.texinfo + at include include/fun-alexandria-length-equals.texinfo @include include/fun-alexandria-copy-sequence.texinfo @include include/fun-alexandria-first-elt.texinfo @include include/fun-alexandria-setf-first-elt.texinfo @include include/fun-alexandria-last-elt.texinfo @include include/fun-alexandria-setf-last-elt.texinfo @include include/fun-alexandria-starts-with.texinfo + at include include/fun-alexandria-starts-with-subseq.texinfo @include include/fun-alexandria-ends-with.texinfo + at include include/fun-alexandria-ends-with-subseq.texinfo + at include include/fun-alexandria-map-combinations.texinfo + at include include/fun-alexandria-map-derangements.texinfo + at include include/fun-alexandria-map-permutations.texinfo - at node Macro Writing Utilities + at node Macro Writing @comment node-name, next, previous, up - at section Macro Writing Utilities + at chapter Macro Writing - at include include/macro-alexandria-with-unique-names.texinfo @include include/macro-alexandria-once-only.texinfo + at include include/macro-alexandria-with-gensyms.texinfo + at include include/macro-alexandria-with-unique-names.texinfo + at include include/fun-alexandria-featurep.texinfo + at include include/fun-alexandria-parse-body.texinfo + at include include/fun-alexandria-parse-ordinary-lambda-list.texinfo - at node Symbol Utilities + at node Symbols @comment node-name, next, previous, up - at section Symbol Utilities + at chapter Symbols @include include/fun-alexandria-ensure-symbol.texinfo @include include/fun-alexandria-format-symbol.texinfo @include include/fun-alexandria-make-keyword.texinfo + at include include/fun-alexandria-make-gensym.texinfo @include include/fun-alexandria-make-gensym-list.texinfo + at include include/fun-alexandria-symbolicate.texinfo - at node Array Utilities + at node Arrays @comment node-name, next, previous, up - at section Array Utilities + at chapter Arrays @include include/type-alexandria-array-index.texinfo + at include include/type-alexandria-array-length.texinfo @include include/fun-alexandria-copy-array.texinfo - at node Type Designator Manipulation + at node Types @comment node-name, next, previous, up - at section Type Designator Manipulation + at chapter Types - at include include/fun-alexandria-of-type.texinfo - at include include/fun-alexandria-type-equal.texinfo + at include include/type-alexandria-string-designator.texinfo @include include/macro-alexandria-coercef.texinfo + at include include/fun-alexandria-of-type.texinfo + at include include/fun-alexandria-type-equals.texinfo - at node Mathematical Utilities + at node Numbers @comment node-name, next, previous, up - at section Mathematical Utilities + at chapter Numbers @include include/macro-alexandria-maxf.texinfo @include include/macro-alexandria-minf.texinfo + at include include/fun-alexandria-binomial-coefficient.texinfo + at include include/fun-alexandria-count-permutations.texinfo @include include/fun-alexandria-clamp.texinfo @include include/fun-alexandria-lerp.texinfo + at include include/fun-alexandria-factorial.texinfo + at include include/fun-alexandria-subfactorial.texinfo @include include/fun-alexandria-gaussian-random.texinfo @include include/fun-alexandria-iota.texinfo + at include include/fun-alexandria-map-iota.texinfo @include include/fun-alexandria-mean.texinfo @include include/fun-alexandria-median.texinfo @include include/fun-alexandria-variance.texinfo @include include/fun-alexandria-standard-deviation.texinfo - at c FIXME: get a better section name - at node Features - at comment node-name, next, previous, up - at section Features - - at include include/fun-alexandria-featurep.texinfo - @bye diff --git a/doc/docstrings.lisp b/doc/docstrings.lisp new file mode 100644 index 0000000..2ff7dff --- /dev/null +++ b/doc/docstrings.lisp @@ -0,0 +1,864 @@ +;;; -*- lisp -*- + +;;;; A docstring extractor for the sbcl manual. Creates +;;;; @include-ready documentation from the docstrings of exported +;;;; symbols of specified packages. + +;;;; This software is part of the SBCL software system. SBCL is in the +;;;; public domain and is provided with absolutely no warranty. See +;;;; the COPYING file for more information. +;;;; +;;;; Written by Rudi Schlatte , mangled +;;;; by Nikodemus Siivola. + +;;;; TODO +;;;; * Verbatim text +;;;; * Quotations +;;;; * Method documentation untested +;;;; * Method sorting, somehow +;;;; * Index for macros & constants? +;;;; * This is getting complicated enough that tests would be good +;;;; * Nesting (currently only nested itemizations work) +;;;; * doc -> internal form -> texinfo (so that non-texinfo format are also +;;;; easily generated) + +;;;; FIXME: The description below is no longer complete. This +;;;; should possibly be turned into a contrib with proper documentation. + +;;;; Formatting heuristics (tweaked to format SAVE-LISP-AND-DIE sanely): +;;;; +;;;; Formats SYMBOL as @code{symbol}, or @var{symbol} if symbol is in +;;;; the argument list of the defun / defmacro. +;;;; +;;;; Lines starting with * or - that are followed by intented lines +;;;; are marked up with @itemize. +;;;; +;;;; Lines containing only a SYMBOL that are followed by indented +;;;; lines are marked up as @table @code, with the SYMBOL as the item. + +(eval-when (:compile-toplevel :load-toplevel :execute) + (require 'sb-introspect)) + +(defpackage :sb-texinfo + (:use :cl :sb-mop) + (:shadow #:documentation) + (:export #:generate-includes #:document-package) + (:documentation + "Tools to generate TexInfo documentation from docstrings.")) + +(in-package :sb-texinfo) + +;;;; various specials and parameters + +(defvar *texinfo-output*) +(defvar *texinfo-variables*) +(defvar *documentation-package*) +(defvar *base-package*) + +(defparameter *undocumented-packages* '(sb-pcl sb-int sb-kernel sb-sys sb-c)) + +(defparameter *documentation-types* + '(compiler-macro + function + method-combination + setf + ;;structure ; also handled by `type' + type + variable) + "A list of symbols accepted as second argument of `documentation'") + +(defparameter *character-replacements* + '((#\* . "star") (#\/ . "slash") (#\+ . "plus") + (#\< . "lt") (#\> . "gt") + (#\= . "equals")) + "Characters and their replacement names that `alphanumize' uses. If +the replacements contain any of the chars they're supposed to replace, +you deserve to lose.") + +(defparameter *characters-to-drop* '(#\\ #\` #\') + "Characters that should be removed by `alphanumize'.") + +(defparameter *texinfo-escaped-chars* "@{}" + "Characters that must be escaped with #\@ for Texinfo.") + +(defparameter *itemize-start-characters* '(#\* #\-) + "Characters that might start an itemization in docstrings when + at the start of a line.") + +(defparameter *symbol-characters* "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890*:-+&#'" + "List of characters that make up symbols in a docstring.") + +(defparameter *symbol-delimiters* " ,.!?;") + +(defparameter *ordered-documentation-kinds* + '(package type structure condition class macro)) + +;;;; utilities + +(defun flatten (list) + (cond ((null list) + nil) + ((consp (car list)) + (nconc (flatten (car list)) (flatten (cdr list)))) + ((null (cdr list)) + (cons (car list) nil)) + (t + (cons (car list) (flatten (cdr list)))))) + +(defun whitespacep (char) + (find char #(#\tab #\space #\page))) + +(defun setf-name-p (name) + (or (symbolp name) + (and (listp name) (= 2 (length name)) (eq (car name) 'setf)))) + +(defgeneric specializer-name (specializer)) + +(defmethod specializer-name ((specializer eql-specializer)) + (list 'eql (eql-specializer-object specializer))) + +(defmethod specializer-name ((specializer class)) + (class-name specializer)) + +(defun ensure-class-precedence-list (class) + (unless (class-finalized-p class) + (finalize-inheritance class)) + (class-precedence-list class)) + +(defun specialized-lambda-list (method) + ;; courtecy of AMOP p. 61 + (let* ((specializers (method-specializers method)) + (lambda-list (method-lambda-list method)) + (n-required (length specializers))) + (append (mapcar (lambda (arg specializer) + (if (eq specializer (find-class 't)) + arg + `(,arg ,(specializer-name specializer)))) + (subseq lambda-list 0 n-required) + specializers) + (subseq lambda-list n-required)))) + +(defun string-lines (string) + "Lines in STRING as a vector." + (coerce (with-input-from-string (s string) + (loop for line = (read-line s nil nil) + while line collect line)) + 'vector)) + +(defun indentation (line) + "Position of first non-SPACE character in LINE." + (position-if-not (lambda (c) (char= c #\Space)) line)) + +(defun docstring (x doc-type) + (cl:documentation x doc-type)) + +(defun flatten-to-string (list) + (format nil "~{~A~^-~}" (flatten list))) + +(defun alphanumize (original) + "Construct a string without characters like *`' that will f-star-ck +up filename handling. See `*character-replacements*' and +`*characters-to-drop*' for customization." + (let ((name (remove-if (lambda (x) (member x *characters-to-drop*)) + (if (listp original) + (flatten-to-string original) + (string original)))) + (chars-to-replace (mapcar #'car *character-replacements*))) + (flet ((replacement-delimiter (index) + (cond ((or (< index 0) (>= index (length name))) "") + ((alphanumericp (char name index)) "-") + (t "")))) + (loop for index = (position-if #'(lambda (x) (member x chars-to-replace)) + name) + while index + do (setf name (concatenate 'string (subseq name 0 index) + (replacement-delimiter (1- index)) + (cdr (assoc (aref name index) + *character-replacements*)) + (replacement-delimiter (1+ index)) + (subseq name (1+ index)))))) + name)) + +;;;; generating various names + +(defgeneric name (thing) + (:documentation "Name for a documented thing. Names are either +symbols or lists of symbols.")) + +(defmethod name ((symbol symbol)) + symbol) + +(defmethod name ((cons cons)) + cons) + +(defmethod name ((package package)) + (short-package-name package)) + +(defmethod name ((method method)) + (list + (generic-function-name (method-generic-function method)) + (method-qualifiers method) + (specialized-lambda-list method))) + +;;; Node names for DOCUMENTATION instances + +(defgeneric name-using-kind/name (kind name doc)) + +(defmethod name-using-kind/name (kind (name string) doc) + (declare (ignore kind doc)) + name) + +(defmethod name-using-kind/name (kind (name symbol) doc) + (declare (ignore kind)) + (format nil "~@[~A:~]~A" (short-package-name (get-package doc)) name)) + +(defmethod name-using-kind/name (kind (name list) doc) + (declare (ignore kind)) + (assert (setf-name-p name)) + (format nil "(setf ~@[~A:~]~A)" (short-package-name (get-package doc)) (second name))) + +(defmethod name-using-kind/name ((kind (eql 'method)) name doc) + (format nil "~A~{ ~A~} ~A" + (name-using-kind/name nil (first name) doc) + (second name) + (third name))) + +(defun node-name (doc) + "Returns TexInfo node name as a string for a DOCUMENTATION instance." + (let ((kind (get-kind doc))) + (format nil "~:(~A~) ~(~A~)" kind (name-using-kind/name kind (get-name doc) doc)))) + +(defun short-package-name (package) + (unless (eq package *base-package*) + (car (sort (copy-list (cons (package-name package) (package-nicknames package))) + #'< :key #'length)))) + +;;; Definition titles for DOCUMENTATION instances + +(defgeneric title-using-kind/name (kind name doc)) + +(defmethod title-using-kind/name (kind (name string) doc) + (declare (ignore kind doc)) + name) + +(defmethod title-using-kind/name (kind (name symbol) doc) + (declare (ignore kind)) + (format nil "~@[~A:~]~A" (short-package-name (get-package doc)) name)) + +(defmethod title-using-kind/name (kind (name list) doc) + (declare (ignore kind)) + (assert (setf-name-p name)) + (format nil "(setf ~@[~A:~]~A)" (short-package-name (get-package doc)) (second name))) + +(defmethod title-using-kind/name ((kind (eql 'method)) name doc) + (format nil "~{~A ~}~A" + (second name) + (title-using-kind/name nil (first name) doc))) + +(defun title-name (doc) + "Returns a string to be used as name of the definition." + (string-downcase (title-using-kind/name (get-kind doc) (get-name doc) doc))) + +(defun include-pathname (doc) + (let* ((kind (get-kind doc)) + (name (nstring-downcase + (if (eq 'package kind) + (format nil "package-~A" (alphanumize (get-name doc))) + (format nil "~A-~A-~A" + (case (get-kind doc) + ((function generic-function) "fun") + (structure "struct") + (variable "var") + (otherwise (symbol-name (get-kind doc)))) + (alphanumize (let ((*base-package* nil)) + (short-package-name (get-package doc)))) + (alphanumize (get-name doc))))))) + (make-pathname :name name :type "texinfo"))) + +;;;; documentation class and related methods + +(defclass documentation () + ((name :initarg :name :reader get-name) + (kind :initarg :kind :reader get-kind) + (string :initarg :string :reader get-string) + (children :initarg :children :initform nil :reader get-children) + (package :initform *documentation-package* :reader get-package))) + +(defmethod print-object ((documentation documentation) stream) + (print-unreadable-object (documentation stream :type t) + (princ (list (get-kind documentation) (get-name documentation)) stream))) + +(defgeneric make-documentation (x doc-type string)) + +(defmethod make-documentation ((x package) doc-type string) + (declare (ignore doc-type)) + (make-instance 'documentation + :name (name x) + :kind 'package + :string string)) + +(defmethod make-documentation (x (doc-type (eql 'function)) string) + (declare (ignore doc-type)) + (let* ((fdef (and (fboundp x) (fdefinition x))) + (name x) + (kind (cond ((and (symbolp x) (special-operator-p x)) + 'special-operator) + ((and (symbolp x) (macro-function x)) + 'macro) + ((typep fdef 'generic-function) + (assert (or (symbolp name) (setf-name-p name))) + 'generic-function) + (fdef + (assert (or (symbolp name) (setf-name-p name))) + 'function))) + (children (when (eq kind 'generic-function) + (collect-gf-documentation fdef)))) + (make-instance 'documentation + :name (name x) + :string string + :kind kind + :children children))) + +(defmethod make-documentation ((x method) doc-type string) + (declare (ignore doc-type)) + (make-instance 'documentation + :name (name x) + :kind 'method + :string string)) + +(defmethod make-documentation (x (doc-type (eql 'type)) string) + (make-instance 'documentation + :name (name x) + :string string + :kind (etypecase (find-class x nil) + (structure-class 'structure) + (standard-class 'class) + (sb-pcl::condition-class 'condition) + ((or built-in-class null) 'type)))) + +(defmethod make-documentation (x (doc-type (eql 'variable)) string) + (make-instance 'documentation + :name (name x) + :string string + :kind (if (constantp x) + 'constant + 'variable))) + +(defmethod make-documentation (x (doc-type (eql 'setf)) string) + (declare (ignore doc-type)) + (make-instance 'documentation + :name (name x) + :kind 'setf-expander + :string string)) + +(defmethod make-documentation (x doc-type string) + (make-instance 'documentation + :name (name x) + :kind doc-type + :string string)) + +(defun maybe-documentation (x doc-type) + "Returns a DOCUMENTATION instance for X and DOC-TYPE, or NIL if +there is no corresponding docstring." + (let ((docstring (docstring x doc-type))) + (when docstring + (make-documentation x doc-type docstring)))) + +(defun lambda-list (doc) + (case (get-kind doc) + ((package constant variable type structure class condition nil) + nil) + (method + (third (get-name doc))) + (t + ;; KLUDGE: Eugh. + ;; + ;; believe it or not, the above comment was written before CSR + ;; came along and obfuscated this. (2005-07-04) + (when (symbolp (get-name doc)) + (labels ((clean (x &key optional key) + (typecase x + (atom x) + ((cons (member &optional)) + (cons (car x) (clean (cdr x) :optional t))) + ((cons (member &key)) + (cons (car x) (clean (cdr x) :key t))) + ((cons cons) + (cons + (cond (key (if (consp (caar x)) + (caaar x) + (caar x))) + (optional (caar x)) + (t (clean (car x)))) + (clean (cdr x) :key key :optional optional))) + (cons + (cons + (cond ((or key optional) (car x)) + (t (clean (car x)))) + (clean (cdr x) :key key :optional optional)))))) + (clean (sb-introspect:function-lambda-list (get-name doc)))))))) + +(defun get-string-name (x) + (let ((name (get-name x))) + (cond ((symbolp name) + (symbol-name name)) + ((and (consp name) (eq 'setf (car name))) + (symbol-name (second name))) + ((stringp name) + name) + (t + (error "Don't know which symbol to use for name ~S" name))))) + +(defun documentation< (x y) + (let ((p1 (position (get-kind x) *ordered-documentation-kinds*)) + (p2 (position (get-kind y) *ordered-documentation-kinds*))) + (if (or (not (and p1 p2)) (= p1 p2)) + (string< (get-string-name x) (get-string-name y)) + (< p1 p2)))) + +;;;; turning text into texinfo + +(defun escape-for-texinfo (string &optional downcasep) + "Return STRING with characters in *TEXINFO-ESCAPED-CHARS* escaped +with #\@. Optionally downcase the result." + (let ((result (with-output-to-string (s) + (loop for char across string + when (find char *texinfo-escaped-chars*) + do (write-char #\@ s) + do (write-char char s))))) + (if downcasep (nstring-downcase result) result))) + +(defun empty-p (line-number lines) + (and (< -1 line-number (length lines)) + (not (indentation (svref lines line-number))))) + +;;; line markups + +(defvar *not-symbols* '("ANSI" "CLHS")) + +(defun locate-symbols (line) + "Return a list of index pairs of symbol-like parts of LINE." + ;; This would be a good application for a regex ... + (let (result) + (flet ((grab (start end) + (unless (member (subseq line start end) '("ANSI" "CLHS")) + (push (list start end) result)))) + (do ((begin nil) + (maybe-begin t) + (i 0 (1+ i))) + ((= i (length line)) + ;; symbol at end of line + (when (and begin (or (> i (1+ begin)) + (not (member (char line begin) '(#\A #\I))))) + (grab begin i)) + (nreverse result)) + (cond + ((and begin (find (char line i) *symbol-delimiters*)) + ;; symbol end; remember it if it's not "A" or "I" + (when (or (> i (1+ begin)) (not (member (char line begin) '(#\A #\I)))) + (grab begin i)) + (setf begin nil + maybe-begin t)) + ((and begin (not (find (char line i) *symbol-characters*))) + ;; Not a symbol: abort + (setf begin nil)) + ((and maybe-begin (not begin) (find (char line i) *symbol-characters*)) + ;; potential symbol begin at this position + (setf begin i + maybe-begin nil)) + ((find (char line i) *symbol-delimiters*) + ;; potential symbol begin after this position + (setf maybe-begin t)) + (t + ;; Not reading a symbol, not at potential start of symbol + (setf maybe-begin nil))))))) + +(defun texinfo-line (line) + "Format symbols in LINE texinfo-style: either as code or as +variables if the symbol in question is contained in symbols +*TEXINFO-VARIABLES*." + (with-output-to-string (result) + (let ((last 0)) + (dolist (symbol/index (locate-symbols line)) + (write-string (subseq line last (first symbol/index)) result) + (let ((symbol-name (apply #'subseq line symbol/index))) + (format result (if (member symbol-name *texinfo-variables* + :test #'string=) + "@var{~A}" + "@code{~A}") + (string-downcase symbol-name))) + (setf last (second symbol/index))) + (write-string (subseq line last) result)))) + +;;; lisp sections + +(defun lisp-section-p (line line-number lines) + "Returns T if the given LINE looks like start of lisp code -- +ie. if it starts with whitespace followed by a paren or +semicolon, and the previous line is empty" + (let ((offset (indentation line))) + (and offset + (plusp offset) + (find (find-if-not #'whitespacep line) "(;") + (empty-p (1- line-number) lines)))) + +(defun collect-lisp-section (lines line-number) + (let ((lisp (loop for index = line-number then (1+ index) + for line = (and (< index (length lines)) (svref lines index)) + while (indentation line) + collect line))) + (values (length lisp) `("@lisp" , at lisp "@end lisp")))) + +;;; itemized sections + +(defun maybe-itemize-offset (line) + "Return NIL or the indentation offset if LINE looks like it starts +an item in an itemization." + (let* ((offset (indentation line)) + (char (when offset (char line offset)))) + (and offset + (member char *itemize-start-characters* :test #'char=) + (char= #\Space (find-if-not (lambda (c) (char= c char)) + line :start offset)) + offset))) + +(defun collect-maybe-itemized-section (lines starting-line) + ;; Return index of next line to be processed outside + (let ((this-offset (maybe-itemize-offset (svref lines starting-line))) + (result nil) + (lines-consumed 0)) + (loop for line-number from starting-line below (length lines) + for line = (svref lines line-number) + for indentation = (indentation line) + for offset = (maybe-itemize-offset line) + do (cond + ((not indentation) + ;; empty line -- inserts paragraph. + (push "" result) + (incf lines-consumed)) + ((and offset (> indentation this-offset)) + ;; nested itemization -- handle recursively + ;; FIXME: tables in itemizations go wrong + (multiple-value-bind (sub-lines-consumed sub-itemization) + (collect-maybe-itemized-section lines line-number) + (when sub-lines-consumed + (incf line-number (1- sub-lines-consumed)) ; +1 on next loop + (incf lines-consumed sub-lines-consumed) + (setf result (nconc (nreverse sub-itemization) result))))) + ((and offset (= indentation this-offset)) + ;; start of new item + (push (format nil "@item ~A" + (texinfo-line (subseq line (1+ offset)))) + result) + (incf lines-consumed)) + ((and (not offset) (> indentation this-offset)) + ;; continued item from previous line + (push (texinfo-line line) result) + (incf lines-consumed)) + (t + ;; end of itemization + (loop-finish)))) + ;; a single-line itemization isn't. + (if (> (count-if (lambda (line) (> (length line) 0)) result) 1) + (values lines-consumed `("@itemize" ,@(reverse result) "@end itemize")) + nil))) + +;;; table sections + +(defun tabulation-body-p (offset line-number lines) + (when (< line-number (length lines)) + (let ((offset2 (indentation (svref lines line-number)))) + (and offset2 (< offset offset2))))) + +(defun tabulation-p (offset line-number lines direction) + (let ((step (ecase direction + (:backwards (1- line-number)) + (:forwards (1+ line-number))))) + (when (and (plusp line-number) (< line-number (length lines))) + (and (eql offset (indentation (svref lines line-number))) + (or (when (eq direction :backwards) + (empty-p step lines)) + (tabulation-p offset step lines direction) + (tabulation-body-p offset step lines)))))) + +(defun maybe-table-offset (line-number lines) + "Return NIL or the indentation offset if LINE looks like it starts +an item in a tabulation. Ie, if it is (1) indented, (2) preceded by an +empty line, another tabulation label, or a tabulation body, (3) and +followed another tabulation label or a tabulation body." + (let* ((line (svref lines line-number)) + (offset (indentation line)) + (prev (1- line-number)) + (next (1+ line-number))) + (when (and offset (plusp offset)) + (and (or (empty-p prev lines) + (tabulation-body-p offset prev lines) + (tabulation-p offset prev lines :backwards)) + (or (tabulation-body-p offset next lines) + (tabulation-p offset next lines :forwards)) + offset)))) + +;;; FIXME: This and itemization are very similar: could they share +;;; some code, mayhap? + +(defun collect-maybe-table-section (lines starting-line) + ;; Return index of next line to be processed outside + (let ((this-offset (maybe-table-offset starting-line lines)) + (result nil) + (lines-consumed 0)) + (loop for line-number from starting-line below (length lines) + for line = (svref lines line-number) + for indentation = (indentation line) + for offset = (maybe-table-offset line-number lines) + do (cond + ((not indentation) + ;; empty line -- inserts paragraph. + (push "" result) + (incf lines-consumed)) + ((and offset (= indentation this-offset)) + ;; start of new item, or continuation of previous item + (if (and result (search "@item" (car result) :test #'char=)) + (push (format nil "@itemx ~A" (texinfo-line line)) + result) + (progn + (push "" result) + (push (format nil "@item ~A" (texinfo-line line)) + result))) + (incf lines-consumed)) + ((> indentation this-offset) + ;; continued item from previous line + (push (texinfo-line line) result) + (incf lines-consumed)) + (t + ;; end of itemization + (loop-finish)))) + ;; a single-line table isn't. + (if (> (count-if (lambda (line) (> (length line) 0)) result) 1) + (values lines-consumed + `("" "@table @emph" ,@(reverse result) "@end table" "")) + nil))) + +;;; section markup + +(defmacro with-maybe-section (index &rest forms) + `(multiple-value-bind (count collected) (progn , at forms) + (when count + (dolist (line collected) + (write-line line *texinfo-output*)) + (incf ,index (1- count))))) + +(defun write-texinfo-string (string &optional lambda-list) + "Try to guess as much formatting for a raw docstring as possible." + (let ((*texinfo-variables* (flatten lambda-list)) + (lines (string-lines (escape-for-texinfo string nil)))) + (loop for line-number from 0 below (length lines) + for line = (svref lines line-number) + do (cond + ((with-maybe-section line-number + (and (lisp-section-p line line-number lines) + (collect-lisp-section lines line-number)))) + ((with-maybe-section line-number + (and (maybe-itemize-offset line) + (collect-maybe-itemized-section lines line-number)))) + ((with-maybe-section line-number + (and (maybe-table-offset line-number lines) + (collect-maybe-table-section lines line-number)))) + (t + (write-line (texinfo-line line) *texinfo-output*)))))) + +;;;; texinfo formatting tools + +(defun hide-superclass-p (class-name super-name) + (let ((super-package (symbol-package super-name))) + (or + ;; KLUDGE: We assume that we don't want to advertise internal + ;; classes in CP-lists, unless the symbol we're documenting is + ;; internal as well. + (and (member super-package #.'(mapcar #'find-package *undocumented-packages*)) + (not (eq super-package (symbol-package class-name)))) + ;; KLUDGE: We don't generally want to advertise SIMPLE-ERROR or + ;; SIMPLE-CONDITION in the CPLs of conditions that inherit them + ;; simply as a matter of convenience. The assumption here is that + ;; the inheritance is incidental unless the name of the condition + ;; begins with SIMPLE-. + (and (member super-name '(simple-error simple-condition)) + (let ((prefix "SIMPLE-")) + (mismatch prefix (string class-name) :end2 (length prefix))) + t ; don't return number from MISMATCH + )))) + +(defun hide-slot-p (symbol slot) + ;; FIXME: There is no pricipal reason to avoid the slot docs fo + ;; structures and conditions, but their DOCUMENTATION T doesn't + ;; currently work with them the way we'd like. + (not (and (typep (find-class symbol nil) 'standard-class) + (docstring slot t)))) + +(defun texinfo-anchor (doc) + (format *texinfo-output* "@anchor{~A}~%" (node-name doc))) + +;;; KLUDGE: &AUX *PRINT-PRETTY* here means "no linebreaks please" +(defun texinfo-begin (doc &aux *print-pretty*) + (let ((kind (get-kind doc))) + (format *texinfo-output* "@~A {~:(~A~)} ~({~A}~@[ ~{~A~^ ~}~]~)~%" + (case kind + ((package constant variable) + "defvr") + ((structure class condition type) + "deftp") + (t + "deffn")) + (map 'string (lambda (char) (if (eql char #\-) #\Space char)) (string kind)) + (title-name doc) + ;; &foo would be amusingly bold in the pdf thanks to TeX/Texinfo + ;; interactions,so we escape the ampersand -- amusingly for TeX. + ;; sbcl.texinfo defines macros that expand @&key and friends to &key. + (mapcar (lambda (name) + (if (member name lambda-list-keywords) + (format nil "@~A" name) + name)) + (lambda-list doc))))) + +(defun texinfo-index (doc) + (let ((title (title-name doc))) + (case (get-kind doc) + ((structure type class condition) + (format *texinfo-output* "@tindex ~A~%" title)) + ((variable constant) + (format *texinfo-output* "@vindex ~A~%" title)) + ((compiler-macro function method-combination macro generic-function) + (format *texinfo-output* "@findex ~A~%" title))))) + +(defun texinfo-inferred-body (doc) + (when (member (get-kind doc) '(class structure condition)) + (let ((name (get-name doc))) + ;; class precedence list + (format *texinfo-output* "Class precedence list: @code{~(~{@lw{~A}~^, ~}~)}~%~%" + (remove-if (lambda (class) (hide-superclass-p name class)) + (mapcar #'class-name (ensure-class-precedence-list (find-class name))))) + ;; slots + (let ((slots (remove-if (lambda (slot) (hide-slot-p name slot)) + (class-direct-slots (find-class name))))) + (when slots + (format *texinfo-output* "Slots:~%@itemize~%") + (dolist (slot slots) + (format *texinfo-output* + "@item ~(@code{~A}~#[~:; --- ~]~ + ~:{~2*~@[~2:*~A~P: ~{@code{@w{~S}}~^, ~}~]~:^; ~}~)~%~%" + (slot-definition-name slot) + (remove + nil + (mapcar + (lambda (name things) + (if things + (list name (length things) things))) + '("initarg" "reader" "writer") + (list + (slot-definition-initargs slot) + (slot-definition-readers slot) + (slot-definition-writers slot))))) + ;; FIXME: Would be neater to handler as children + (write-texinfo-string (docstring slot t))) + (format *texinfo-output* "@end itemize~%~%")))))) + +(defun texinfo-body (doc) + (write-texinfo-string (get-string doc))) + +(defun texinfo-end (doc) + (write-line (case (get-kind doc) + ((package variable constant) "@end defvr") + ((structure type class condition) "@end deftp") + (t "@end deffn")) + *texinfo-output*)) + +(defun write-texinfo (doc) + "Writes TexInfo for a DOCUMENTATION instance to *TEXINFO-OUTPUT*." + (texinfo-anchor doc) + (texinfo-begin doc) + (texinfo-index doc) + (texinfo-inferred-body doc) + (texinfo-body doc) + (texinfo-end doc) + ;; FIXME: Children should be sorted one way or another + (mapc #'write-texinfo (get-children doc))) + +;;;; main logic + +(defun collect-gf-documentation (gf) + "Collects method documentation for the generic function GF" + (loop for method in (generic-function-methods gf) + for doc = (maybe-documentation method t) + when doc + collect doc)) + +(defun collect-name-documentation (name) + (loop for type in *documentation-types* + for doc = (maybe-documentation name type) + when doc + collect doc)) + +(defun collect-symbol-documentation (symbol) + "Collects all docs for a SYMBOL and (SETF SYMBOL), returns a list of +the form DOC instances. See `*documentation-types*' for the possible +values of doc-type." + (nconc (collect-name-documentation symbol) + (collect-name-documentation (list 'setf symbol)))) + +(defun collect-documentation (package) + "Collects all documentation for all external symbols of the given +package, as well as for the package itself." + (let* ((*documentation-package* (find-package package)) + (docs nil)) + (check-type package package) + (do-external-symbols (symbol package) + (setf docs (nconc (collect-symbol-documentation symbol) docs))) + (let ((doc (maybe-documentation *documentation-package* t))) + (when doc + (push doc docs))) + docs)) + +(defmacro with-texinfo-file (pathname &body forms) + `(with-open-file (*texinfo-output* ,pathname + :direction :output + :if-does-not-exist :create + :if-exists :supersede) + , at forms)) + +(defun generate-includes (directory packages &key (base-package :cl-user)) + "Create files in `directory' containing Texinfo markup of all +docstrings of each exported symbol in `packages'. `directory' is +created if necessary. If you supply a namestring that doesn't end in a +slash, you lose. The generated files are of the form +\"__.texinfo\" and can be included +via @include statements. Texinfo syntax-significant characters are +escaped in symbol names, but if a docstring contains invalid Texinfo +markup, you lose." + (handler-bind ((warning #'muffle-warning)) + (let ((directory (merge-pathnames (pathname directory))) + (*base-package* (find-package base-package))) + (ensure-directories-exist directory) + (dolist (package packages) + (dolist (doc (collect-documentation (find-package package))) + (with-texinfo-file (merge-pathnames (include-pathname doc) directory) + (write-texinfo doc)))) + directory))) + +(defun document-package (package &optional filename) + "Create a file containing all available documentation for the +exported symbols of `package' in Texinfo format. If `filename' is not +supplied, a file \".texinfo\" is generated. + +The definitions can be referenced using Texinfo statements like + at ref{__.texinfo}. Texinfo +syntax-significant characters are escaped in symbol names, but if a +docstring contains invalid Texinfo markup, you lose." + (handler-bind ((warning #'muffle-warning)) + (let* ((package (find-package package)) + (filename (or filename (make-pathname + :name (string-downcase (short-package-name package)) + :type "texinfo"))) + (docs (sort (collect-documentation package) #'documentation<))) + (with-texinfo-file filename + (dolist (doc docs) + (write-texinfo doc))) + filename))) diff --git a/functions.lisp b/functions.lisp index 8d2fd38..5a45d70 100644 --- a/functions.lisp +++ b/functions.lisp @@ -15,6 +15,7 @@ it must be a function name and its FDEFINITION is returned." (define-modify-macro ensure-functionf/1 () ensure-function) (defmacro ensure-functionf (&rest places) + "FIXME: UNDOCUMENTED!" `(progn ,@(mapcar (lambda (x) `(ensure-functionf/1 ,x)) places))) (defun disjoin (predicate &rest more-predicates) diff --git a/lists.lisp b/lists.lisp index 69c21f7..ffe418a 100644 --- a/lists.lisp +++ b/lists.lisp @@ -215,7 +215,7 @@ designator of the expected type in a TYPE-ERROR." (def lastcar (list) "Returns the last element of LIST. Signals a type-error if LIST is not a -proper list." +proper list." nil nil (cadr last) @@ -278,8 +278,10 @@ provided plist." ;; FIXME: should not cons (apply 'remove-from-plist plist keys)) -(define-modify-macro remove-from-plistf (&rest keys) remove-from-plist) -(define-modify-macro delete-from-plistf (&rest keys) delete-from-plist) +(define-modify-macro remove-from-plistf (&rest keys) remove-from-plist + "Modify macro for REMOVE-FROM-PLIST.") +(define-modify-macro delete-from-plistf (&rest keys) delete-from-plist + "Modify macro for DELETE-FROM-PLIST.") (declaim (inline sans)) (defun sans (plist &rest keys) @@ -322,8 +324,9 @@ In other words, returns the product of LIST and MORE-LISTS using FUNCTION. Example: - (map-product 'list '(1 2) '(3 4) '(5 6)) => ((1 3 5) (1 3 6) (1 4 5) (1 4 6) - (2 3 5) (2 3 6) (2 4 5) (2 4 6)) + (map-product 'list '(1 2) '(3 4) '(5 6)) + => ((1 3 5) (1 3 6) (1 4 5) (1 4 6) + (2 3 5) (2 3 6) (2 4 5) (2 4 6)) " (labels ((%map-product (f lists) (let ((more (cdr lists)) diff --git a/macros.lisp b/macros.lisp index 031109d..75ff3f4 100644 --- a/macros.lisp +++ b/macros.lisp @@ -28,15 +28,23 @@ unique symbol the named variable will be bound to." `(with-gensyms ,names , at forms)) (defmacro once-only (specs &body forms) - "Each SPEC must be either a NAME, or a (NAME INITFORM), with plain -NAME using the named variable as initform. + "Evaluates FORMS with symbols specified in SPECS rebound to temporary +variables, ensuring that each initform is evaluated only once. -Evaluates FORMS with names rebound to temporary variables, ensuring -that each is evaluated only once. +Each of SPECS must either be a symbol naming the variable to be rebound, or of +the form: + + (symbol initform) + +Bare symbols in SPECS are equivalent to + + (symbol symbol) Example: + (defmacro cons1 (x) (once-only (x) `(cons ,x ,x))) - (let ((y 0)) (cons1 (incf y))) => (1 . 1)" + (let ((y 0)) (cons1 (incf y))) => (1 . 1) +" (let ((gensyms (make-gensym-list (length specs) "ONCE-ONLY")) (names-and-forms (mapcar (lambda (spec) (etypecase spec @@ -84,18 +92,25 @@ arguments when given." (normalize-optional normalize) (normalize-keyword normalize) (normalize-auxilary normalize)) - "Parses an ordinary lambda-list, returning: - -\(values requireds optionals rest keywords allow-other-keys? auxiliaries) - - 1. Required parameters. - 2. Optional parameter specifications, normalized into form (NAME INIT SUPPLIEDP) - where SUPPLIEDP is NIL if not present. - 3. Name of the rest parameter, or NIL. - 4. Keyword parameter specifications, normalized into form ((KEYWORD-NAME NAME) INIT SUPPLIEDP) - where SUPPLIEDP is NIL if not present. - 5. Boolean indicating &ALLOW-OTHER-KEYS presence. - 6. &AUX parameter specifications, normalized into form (NAME INIT). + "Parses an ordinary lambda-list, returning as multiple values: + +1. Required parameters. + +2. Optional parameter specifications, normalized into form: + + (name init suppliedp) + +3. Name of the rest parameter, or NIL. + +4. Keyword parameter specifications, normalized into form: + + ((keyword-name name) init suppliedp) + +5. Boolean indicating &ALLOW-OTHER-KEYS presence. + +6. &AUX parameter specifications, normalized into form + + (name init). Signals a PROGRAM-ERROR is the lambda-list is malformed." (let ((state :required) diff --git a/numbers.lisp b/numbers.lisp index 7252e2a..bf6ef0b 100644 --- a/numbers.lisp +++ b/numbers.lisp @@ -2,7 +2,7 @@ (declaim (inline clamp)) (defun clamp (number min max) - "Clamps the NUMBER into [MIN, MAX] range. Returns MIN if NUMBER lesser then + "Clamps the NUMBER into [min, max] range. Returns MIN if NUMBER is lesser then MIN and MAX if NUMBER is greater then MAX, otherwise returns NUMBER." (if (< number min) min diff --git a/package.lisp b/package.lisp index 81c1e58..c7f9bf1 100644 --- a/package.lisp +++ b/package.lisp @@ -137,7 +137,7 @@ #:negative-float-p #:negative-long-float #:negative-long-float-p - #:negative-rational + #:negative-rational #:negative-rational-p #:negative-real #:negative-single-float-p diff --git a/sequences.lisp b/sequences.lisp index 2c797b9..a4b2a95 100644 --- a/sequences.lisp +++ b/sequences.lisp @@ -64,10 +64,15 @@ SEQUENCE is not a sequence. Returns FALSE for circular lists." SEQUENCE rotated by N: N elements are moved from the end of the sequence to the front if N is positive, and -N elements moved from the front to the end if N is negative. SEQUENCE must be a proper sequence. N must be an integer, -defaulting to 1. If absolute value of N is greater then the length of the -sequence, the results are identical to calling ROTATE with (* (SIGNUM N) (MOD -N (LENGTH SEQUENCE))). The original sequence may be destructively altered, and -result sequence may share structure with it." +defaulting to 1. + +If absolute value of N is greater then the length of the sequence, the results +are identical to calling ROTATE with + + (* (signum n) (mod n (length sequence))). + +Note: the original sequence may be destructively altered, and result sequence may +share structure with it." (if (plusp n) (rotate-tail-to-head sequence n) (if (minusp n) diff --git a/symbols.lisp b/symbols.lisp index 0347548..44c0d71 100644 --- a/symbols.lisp +++ b/symbols.lisp @@ -7,7 +7,10 @@ designated by PACKAGE. If symbol is not already accessible in PACKAGE, it is interned there. Returns a secondary value reflecting the status of the symbol in the package, which matches the secondary return value of INTERN. -Example: (ENSURE-SYMBOL :CONS :CL) => CL:CONS, :EXTERNAL" +Example: + + (ensure-symbol :cons :cl) => cl:cons, :external +" (intern (string name) package)) (defun maybe-intern (name package) -- Alexandria hooks/post-receive From nsiivola at common-lisp.net Tue Mar 23 07:21:16 2010 From: nsiivola at common-lisp.net (Nikodemus Siivola) Date: Tue, 23 Mar 2010 03:21:16 -0400 Subject: [alexandria.git] updated branch master: bb423c6... documentation baby-steps Message-ID: The branch master has been updated: via bb423c64814e13537262cfa799d16ea9447411ed (commit) from 829db7c7cb06d0a1693af9d25292d666be3eb487 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit bb423c64814e13537262cfa799d16ea9447411ed Author: Nikodemus Siivola Date: Tue Mar 23 09:05:29 2010 +0200 documentation baby-steps * Default doc/Makefile command now generates all docs and cleans up temporary files. * Generate info as well, and use makeinfo to generate the html. * Spit out a ifnottex.include for @&key macros, etc for the benefit of makeinfo. * Clean up &WHOLE and &ENVIRONMENT from the lambda-lists. * MAKE-CIRCULAR-LIST was documented twice, oops. ----------------------------------------------------------------------- Summary of changes: doc/Makefile | 21 +++++++++++++++------ doc/alexandria.texinfo | 5 +++-- doc/docstrings.lisp | 17 +++++++++++++++++ 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/doc/Makefile b/doc/Makefile index 0782a87..56e794a 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -1,10 +1,16 @@ -.PHONY: clean html pdf +.PHONY: clean html pdf include clean-include clean-crap info doc -clean: - rm -rf include *.aux *.cp *.fn *.fns *.ky *.log *.pg *.toc *.tp *.tps *.vr *.pdf *.html +doc: pdf html info clean-crap + +clean-include: + rm -rf include + +clean-crap: + rm -f *.aux *.cp *.fn *.fns *.ky *.log *.pg *.toc *.tp *.tps *.vr + +clean: clean-include + rm -f *.pdf *.html *.info -# Hook into the super sekrit texinfo generator in the SBCL tree -- this is just a quick way -# to bootrap documentation for now. include: sbcl --eval '(progn (require :asdf) (require :alexandria))' \ --load docstrings.lisp \ @@ -15,4 +21,7 @@ pdf: include texi2pdf alexandria.texinfo html: include - texi2html alexandria.texinfo + makeinfo --html --no-split alexandria.texinfo + +info: include + makeinfo alexandria.texinfo diff --git a/doc/alexandria.texinfo b/doc/alexandria.texinfo index d9b23ce..0158525 100644 --- a/doc/alexandria.texinfo +++ b/doc/alexandria.texinfo @@ -72,9 +72,11 @@ terms and conditions: @ifnottex + at include include/ifnottex.texinfo + @node Top @comment node-name, next, previous, up - at top sbcl + at top Alexandria @insertcopying @@ -166,7 +168,6 @@ terms and conditions: @include include/fun-alexandria-lastcar.texinfo @include include/fun-alexandria-setf-lastcar.texinfo @include include/fun-alexandria-proper-list-length.texinfo - at include include/fun-alexandria-make-circular-list.texinfo @include include/fun-alexandria-mappend.texinfo @include include/fun-alexandria-map-product.texinfo @include include/fun-alexandria-remove-from-plist.texinfo diff --git a/doc/docstrings.lisp b/doc/docstrings.lisp index 2ff7dff..51dda07 100644 --- a/doc/docstrings.lisp +++ b/doc/docstrings.lisp @@ -383,6 +383,9 @@ there is no corresponding docstring." (cons (car x) (clean (cdr x) :optional t))) ((cons (member &key)) (cons (car x) (clean (cdr x) :key t))) + ((cons (member &whole &environment)) + ;; Skip these + (clean (cdr x) :optional optional :key key)) ((cons cons) (cons (cond (key (if (consp (caar x)) @@ -824,6 +827,18 @@ package, as well as for the package itself." :if-exists :supersede) , at forms)) +(defun write-ifnottex () + ;; We use @&key, etc to escape & from TeX in lambda lists -- so we need to + ;; define them for info as well. + (flet ((macro (name) + (let ((string (string-downcase name))) + (format *texinfo-output* "@macro ~A~%~A~%@end macro~%" string string)))) + (macro '&allow-other-keys) + (macro '&optional) + (macro '&rest) + (macro '&key) + (macro '&body))) + (defun generate-includes (directory packages &key (base-package :cl-user)) "Create files in `directory' containing Texinfo markup of all docstrings of each exported symbol in `packages'. `directory' is @@ -841,6 +856,8 @@ markup, you lose." (dolist (doc (collect-documentation (find-package package))) (with-texinfo-file (merge-pathnames (include-pathname doc) directory) (write-texinfo doc)))) + (with-texinfo-file (merge-pathnames "ifnottex.texinfo" directory) + (write-ifnottex)) directory))) (defun document-package (package &optional filename) -- Alexandria hooks/post-receive