summaryrefslogtreecommitdiffstats
path: root/slib.texi
diff options
context:
space:
mode:
authorSteve Langasek <vorlon@debian.org>2005-01-10 08:53:33 +0000
committerBryan Newbold <bnewbold@robocracy.org>2017-02-20 00:05:30 -0800
commite33f9eb9cf5cc29c36ce2aa7e10cd0f37ae0cc8e (patch)
treeabbf06041619e445f9d0b772b0d58132009d8234 /slib.texi
parentf559c149c83da84d0b1c285f0298c84aec564af9 (diff)
parent8466d8cfa486fb30d1755c4261b781135083787b (diff)
downloadslib-e33f9eb9cf5cc29c36ce2aa7e10cd0f37ae0cc8e.tar.gz
slib-e33f9eb9cf5cc29c36ce2aa7e10cd0f37ae0cc8e.zip
Import Debian changes 3a1-4.2debian/3a1-4.2
slib (3a1-4.2) unstable; urgency=low * Non-maintainer upload. * Add guile.init.local for use within the build dir, since otherwise we have an (earlier unnoticed) circular build-dep due to a difference between scm and guile. slib (3a1-4.1) unstable; urgency=low * Non-maintainer upload. * Build-depend on guile-1.6 instead of scm, since the new version of scm is wedged in unstable (closes: #281809). slib (3a1-4) unstable; urgency=low * Also check for expected creation on slibcat. (Closes: #240096) slib (3a1-3) unstable; urgency=low * Also check for /usr/share/guile/1.6/slib before installing for guile 1.6. (Closes: #239267) slib (3a1-2) unstable; urgency=low * Add format.scm back into slib until gnucash stops using it. * Call guile-1.6 new-catalog (Closes: #238231) slib (3a1-1) unstable; urgency=low * New upstream release * Remove Info section from doc-base file (Closes: #186950) * Remove period from end of description (linda, lintian) * html gen fixed upstream (Closes: #111778) slib (2d4-2) unstable; urgency=low * Fix url for upstream source (Closes: #144981) * Fix typo in slib.texi (enquque->enqueue) (Closes: #147475) * Add build depends. slib (2d4-1) unstable; urgency=low * New upstream. slib (2d3-1) unstable; urgency=low * New upstream. * Remove texi2html call in debian/rules. Now done upstream. Add make html instead. * Changes to rules and doc-base to conform to upstream html gen * Clean up upstream makefile to make sure it cleans up after itself.
Diffstat (limited to 'slib.texi')
-rw-r--r--slib.texi6464
1 files changed, 3685 insertions, 2779 deletions
diff --git a/slib.texi b/slib.texi
index 3acaa14..0453584 100644
--- a/slib.texi
+++ b/slib.texi
@@ -27,7 +27,7 @@
This file documents SLIB, the portable Scheme library.
Copyright (C) 1993 Todd R. Eigenschink@*
-Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000 Aubrey Jaffer
+Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 Aubrey Jaffer
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
@@ -117,6 +117,7 @@ implementation, user, or directory.
@menu
* The Library System:: How to use and customize.
+* Universal SLIB Procedures:: Provided for all implementations.
* Scheme Syntax Extension Packages::
* Textual Conversion Packages::
* Mathematical Packages::
@@ -126,31 +127,32 @@ implementation, user, or directory.
* Index::
@end menu
-@node The Library System, Scheme Syntax Extension Packages, Top, Top
+@node The Library System, Universal SLIB Procedures, Top, Top
@chapter The Library System
@menu
* Feature:: SLIB names.
-* Requesting Features::
+* Require::
* Library Catalogs::
-* Catalog Compilation::
-* Built-in Support::
-* About this manual::
+* Catalog Creation::
+* Catalog Vicinities::
+* Compiling Scheme::
@end menu
-@node Feature, Requesting Features, The Library System, The Library System
+@node Feature, Require, The Library System, The Library System
@section Feature
@noindent
@cindex feature
SLIB denotes @dfn{features} by symbols. SLIB maintains a list of
-features supported by the Scheme @dfn{session}. The set of features
+features supported by a Scheme @dfn{session}. The set of features
@cindex session
-provided by a session may change over time. Some features are
-properties of the Scheme implementation being used. The following
-features detail what sort of numbers are available from an
-implementation.
+provided by a session may change during that session. Some features
+are properties of the Scheme implementation being used. The following
+@cindex intrinsic feature
+@dfn{intrinsic feature}s detail what sort of numbers are available
+from an implementation:
@itemize @bullet
@item
@@ -166,17 +168,46 @@ implementation.
@end itemize
@noindent
-Other features correspond to the presence of sets of Scheme procedures
-or syntax (macros).
+SLIB initialization (in @file{require.scm}) tests and @dfn{provide}s
+any of these numeric features which are appropriate.
+
+@noindent
+Other features correspond to the presence of packages of Scheme
+procedures or syntax (macros).
@defun provided? feature
-Returns @code{#t} if @var{feature} is supported by the current Scheme
-session.
+Returns @code{#t} if @var{feature} is present in the current Scheme
+session; otherwise @code{#f}. More specifically, @code{provided?}
+returns @code{#t} if the symbol @var{feature} is the
+@code{software-type} or if @var{feature} has been provided by a module
+already loaded; and @code{#f} otherwise.
+
+In some implementations @code{provided?} tests whether a module has
+been @code{require}d by any module or in any thread; other
+implementations will have @code{provided?} reflect only the modules
+@code{require}d by that particular session or thread.
+
+To work portably in both scenarios, use @code{provided?} only to test
+whether intrinsic properties (like those above) are present.
+
+The @var{feature} argument can also be an expression calling
+@code{and}, @code{or}, and @code{not} of features. The boolean result
+of the logical question asked by @var{feature} is returned.
+@end defun
+
+@noindent
+The generalization of @code{provided?} for arbitrary features and catalog
+is @code{feature-eval}:
+
+@defun feature-eval expression provided?
+Evaluates @code{and}, @code{or}, and @code{not} forms in
+@var{expression}, using the values returned by calling @var{provided?}
+on the leaf symbols. @code{feature-eval} returns the boolean result
+of the logical combinations.
@end defun
-@deffn Procedure provide feature
-Informs SLIB that @var{feature} is supported. Henceforth
-@code{(provided? @var{feature})} will return @code{#t}.
+@deffn {Procedure} provide feature
+Informs SLIB that @var{feature} is supported in this session.
@end deffn
@example
@@ -185,15 +216,35 @@ Informs SLIB that @var{feature} is supported. Henceforth
(provided? 'foo) @result{} #t
@end example
+@c @defvar *features*
+@c Is a list of symbols denoting features present in this implementation.
+@c @var{*features*} can grow as modules are @code{require}d.
+@c @footnote{The variables @var{*modules*} and @var{*features*} were
+@c originally modeled on variables of the same names in common-lisp. But
+@c the distinction between features native to an implementation versus
+@c those provided by loading files was not useful. The symbols in
+@c @var{*features*} now indicate the presence of a capability regardless
+@c of how it was provided.}
+@c @end defvar
-@node Requesting Features, Library Catalogs, Feature, The Library System
-@section Requesting Features
+
+@node Require, Library Catalogs, Feature, The Library System
+@section Require
@noindent
@cindex catalog
SLIB creates and maintains a @dfn{catalog} mapping features to locations
of files introducing procedures and syntax denoted by those features.
+@defvar *catalog*
+Is an association list of features (symbols) and pathnames which will
+supply those features. The pathname can be either a string or a pair.
+If pathname is a pair then the first element should be a macro feature
+symbol, @code{source}, @code{compiled}, or one of the other cases
+described in @ref{Library Catalogs}. The cdr of the pathname should
+be either a string or a list.
+@end defvar
+
@noindent
At the beginning of each section of this manual, there is a line like
@code{(require '@var{feature})}.
@@ -205,16 +256,16 @@ names map to the corresponding files.
SLIB provides a form, @code{require}, which loads the files providing
the requested feature.
-@deffn Procedure require feature
+@deffn {Procedure} require feature
@itemize @bullet
@item
If @code{(provided? @var{feature})} is true,
-then @code{require} just returns an unspecified value.
+then @code{require} just returns.
@item
Otherwise, if @var{feature} is found in the catalog, then the
-corresponding files will be loaded and an unspecified value returned.
-
-Subsequently @code{(provided? @var{feature})} will return @code{#t}.
+corresponding files will be loaded and @code{(provided?
+@var{feature})} will henceforth return @code{#t}. That @var{feature}
+is thereafter @code{provided}.
@item
Otherwise (@var{feature} not found in the catalog), an error is
signaled.
@@ -222,47 +273,58 @@ signaled.
@end deffn
@noindent
-The catalog can also be queried using @code{require:feature->path}.
+There is a related form @code{require-if}, used primarily for enabling
+compilers to statically include modules which would be dynamically
+loaded by interpreters.
-@defun require:feature->path feature
-@itemize @bullet
-@item
-If @var{feature} is already provided, then returns @code{#t}.
-@item
-Otherwise, if @var{feature} is in the catalog, the path or list of paths
-associated with @var{feature} is returned.
-@item
-Otherwise, returns @code{#f}.
-@end itemize
-@end defun
+@deffn {Procedure} require-if condition feature
+Requires @var{feature} if @var{condition} is true.
+@end deffn
-@node Library Catalogs, Catalog Compilation, Requesting Features, The Library System
-@section Library Catalogs
+@noindent
+The @code{random} module uses @code{require-if} to flag
+@code{object->string} as a (dynamic) required module.
+
+@example
+(require 'byte)
+(require 'logical)
+(require-if 'compiling 'object->string)
+@end example
@noindent
-At the start of a session no catalog is present, but is created with the
-first catalog inquiry (such as @code{(require 'random)}). Several
-sources of catalog information are combined to produce the catalog:
+The @code{batch} module uses @code{require-if} to flag
+@code{posix-time} as a module to load if the implementation supports
+large precision exact integers.
-@itemize @bullet
-@item
-standard SLIB packages.
-@item
-additional packages of interest to this site.
-@item
-packages specifically for the variety of Scheme which this
-session is running.
-@item
-packages this user wants to always have available. This catalog is the
-file @file{homecat} in the user's @dfn{HOME} directory.
-@cindex HOME
-@item
-packages germane to working in this (current working) directory. This
-catalog is the file @file{usercat} in the directory to which it applies.
-One would typically @code{cd} to this directory before starting the
-Scheme session.
-@end itemize
+@example
+(require-if '(and bignum compiling) 'posix-time)
+@end example
+
+@noindent
+The @code{commutative-ring} module uses @code{require-if} to ensure
+that it has an exponentiation routine, regardless of whether the
+implementation supports inexact numbers:
+
+@example
+(require-if '(not inexact) 'logical) ;for integer-expt
+(define number^ (if (provided? 'inexact) expt integer-expt))
+@end example
+
+@noindent
+The catalog can also be queried using @code{slib:in-catalog?}.
+
+@defun slib:in-catalog? feature
+Returns a @code{CDR} of the catalog entry if one was found for the
+symbol @var{feature} in the alist @code{*catalog*} (and transitively
+through any symbol aliases encountered). Otherwise, returns
+@code{#f}. The format of catalog entries is explained in @ref{Library
+Catalogs}.
+@end defun
+
+
+@node Library Catalogs, Catalog Creation, Require, The Library System
+@section Library Catalogs
@noindent
Catalog files consist of one or more @dfn{association list}s.
@@ -277,9 +339,14 @@ Redirects to the feature named @i{<symbol>}.
@item (@var{feature} . "@i{<path>}")
Loads file @i{<path>}.
@item (@var{feature} source "@i{<path>"})
+@cindex source
@code{slib:load}s the Scheme source file @i{<path>}.
@item (@var{feature} compiled "@i{<path>"} @dots{})
+@cindex compiled
@code{slib:load-compiled}s the files @i{<path>} @dots{}.
+@item (@var{feature} aggregate @i{<symbol>} @dots{})
+@cindex aggregate
+@code{slib:require}s the features @i{<symbol>} @dots{}.
@end table
@noindent
@@ -289,40 +356,58 @@ appropriate for the implementation.
@table @code
@item (@var{feature} defmacro "@i{<path>"})
+@cindex defmacro
@code{defmacro:load}s the Scheme source file @i{<path>}.
@item (@var{feature} macro-by-example "@i{<path>"})
+@cindex macro-by-example
@code{defmacro:load}s the Scheme source file @i{<path>}.
@end table
@table @code
@item (@var{feature} macro "@i{<path>"})
+@cindex macro
@code{macro:load}s the Scheme source file @i{<path>}.
@item (@var{feature} macros-that-work "@i{<path>"})
+@cindex macros-that-work
@code{macro:load}s the Scheme source file @i{<path>}.
@item (@var{feature} syntax-case "@i{<path>"})
+@cindex syntax-case
@code{macro:load}s the Scheme source file @i{<path>}.
@item (@var{feature} syntactic-closures "@i{<path>"})
+@cindex syntactic-closures
@code{macro:load}s the Scheme source file @i{<path>}.
@end table
-@noindent
-Here is an example of a @file{usercat} catalog. A Program in this
-directory can invoke the @samp{run} feature with @code{(require 'run)}.
-
-@example
-;;; "usercat": SLIB catalog additions for SIMSYNCH. -*-scheme-*-
-(
- (simsynch . "../synch/simsynch.scm")
- (run . "../synch/run.scm")
- (schlep . "schlep.scm")
-)
-@end example
+@node Catalog Creation, Catalog Vicinities, Library Catalogs, The Library System
+@section Catalog Creation
+@noindent
+At the start of an interactive session no catalog is present, but is
+created with the first catalog inquiry (such as @code{(require
+'random)}). Several sources of catalog information are combined to
+produce the catalog:
-@node Catalog Compilation, Built-in Support, Library Catalogs, The Library System
-@section Catalog Compilation
-
+@itemize @bullet
+@item
+standard SLIB packages.
+@item
+additional packages of interest to this site.
+@item
+packages specifically for the variety of Scheme which this
+session is running.
+@item
+packages this user wants to always have available. This catalog is the
+file @file{homecat} in the user's @dfn{HOME} directory.
+@cindex HOME
+@item
+packages germane to working in this (current working) directory. This
+catalog is the file @file{usercat} in the directory to which it applies.
+One would typically @code{cd} to this directory before starting the
+Scheme session.
+@item
+packages which are part of an application program.
+@end itemize
@noindent
SLIB combines the catalog information which doesn't vary per user into
@@ -333,34 +418,39 @@ installation to installation, SLIB builds a separate catalog for each
implementation it is used with.
@noindent
-The definition of @code{*SLIB-VERSION*} in SLIB file @file{require.scm}
-is checked against the catalog association of @code{*SLIB-VERSION*} to
-ascertain when versions have changed. I recommend that the definition
-of @code{*SLIB-VERSION*} be changed whenever the library is changed. If
-multiple implementations of Scheme use SLIB, remember that recompiling
-one @file{slibcat} will fix only that implementation's catalog.
+The definition of @code{*SLIB-VERSION*} in SLIB file
+@file{require.scm} is checked against the catalog association of
+@code{*SLIB-VERSION*} to ascertain when versions have changed. It is
+a reasonable practice to change the definition of
+@code{*SLIB-VERSION*} whenever the library is changed. If multiple
+implementations of Scheme use SLIB, remember that recompiling one
+@file{slibcat} will update only that implementation's catalog.
@noindent
The compilation scripts of Scheme implementations which work with SLIB
can automatically trigger catalog compilation by deleting
-@file{slibcat} or by invoking a special form of @code{require}:
+@file{slibcat} or by invoking @code{require} of a special feature:
-@deffn Procedure require @r{'new-catalog}
+@deffn {Procedure} require @r{'new-catalog}
@cindex new-catalog
This will load @file{mklibcat}, which compiles and writes a new
@file{slibcat}.
@end deffn
@noindent
-Another special form of @code{require} erases SLIB's catalog, forcing it
-to be reloaded the next time the catalog is queried.
+Another special feature of @code{require} erases SLIB's catalog,
+forcing it to be reloaded the next time the catalog is queried.
-@deffn Procedure require @r{#f}
+@deffn {Procedure} require @r{#f}
Removes SLIB's catalog information. This should be done before saving
an executable image so that, when restored, its catalog will be loaded
afresh.
@end deffn
+
+@node Catalog Vicinities, Compiling Scheme, Catalog Creation, The Library System
+@section Catalog Vicinities
+
@noindent
Each file in the table below is descibed in terms of its
file-system independent @dfn{vicinity} (@pxref{Vicinity}). The entries
@@ -404,113 +494,213 @@ This file contains the associations specific to an SLIB user.
@item @code{user-vicinity} @file{usercat}
@cindex usercat
-This file contains associations effecting only those sessions whose
+This file contains associations affecting only those sessions whose
@dfn{working directory} is @code{user-vicinity}.
@end table
-@node Built-in Support, About this manual, Catalog Compilation, The Library System
-@section Built-in Support
+@noindent
+Here is an example of a @file{usercat} catalog. A program in this
+directory can invoke the @samp{run} feature with @code{(require 'run)}.
+
+@example
+;;; "usercat": SLIB catalog additions for SIMSYNCH. -*-scheme-*-
+(
+ (simsynch . "../synch/simsynch.scm")
+ (run . "../synch/run.scm")
+ (schlep . "schlep.scm")
+)
+@end example
@noindent
-The procedures described in these sections are supported by all
-implementations as part of the @samp{*.init} files or by
-@file{require.scm}.
+Copying @file{usercat} to many directories is inconvenient.
+Application programs which aren't always run in specially prepared
+directories can nonetheless register their features during
+initialization.
-@menu
-* Require:: Module Management
-* Vicinity:: Pathname Management
-* Configuration:: Characteristics of Scheme Implementation
-* Input/Output:: Things not provided by the Scheme specs.
-* Legacy::
-* System:: LOADing, EVALing, ERRORing, and EXITing
-@end menu
+@deffn {Procedure} catalog:read vicinity catalog
+Reads file named by string @var{catalog} in @var{vicinity}, resolving
+all paths relative to @var{vicinity}, and adds those feature
+associations to @var{*catalog*}.
+@code{catalog:read} would typically be used by an application program
+having dynamically loadable modules. For instance, to register
+factoring and other modules in @var{*catalog*}, JACAL does:
-@node Require, Vicinity, Built-in Support, Built-in Support
-@subsection Require
+@example
+(catalog:read (program-vicinity) "jacalcat")
+@end example
-@defvar *features*
-Is a list of symbols denoting features supported in this implementation.
-@var{*features*} can grow as modules are @code{require}d.
-@var{*features*} must be defined by all implementations
-(@pxref{Porting}).
+@end deffn
-Here are features which SLIB (@file{require.scm}) adds to
-@var{*features*} when appropriate.
+@noindent
+For an application program there are three appropriate venues for
+registering its catalog associations:
@itemize @bullet
@item
-'inexact
+in a @file{usercat} file in the directory where the program runs; or
@item
-'rational
+in an @file{implcat} file in the @code{implementation-vicinity}; or
@item
-'real
+in an application program directory; loaded by calling
+@code{catalog:read}.
+@end itemize
+
+
+@node Compiling Scheme, , Catalog Vicinities, The Library System
+@section Compiling Scheme
+
+To use Scheme compilers effectively with SLIB the compiler needs to
+know which SLIB modules are to be compiled and which symbols are
+exported from those modules.
+
+The procedures in this section automate the extraction of this
+information from SLIB modules. They are guaranteed to work on SLIB
+modules; to use them on other sources, those sources should follow
+SLIB conventions.
+
+@menu
+* Module Conventions::
+* Module Manifests::
+* Module Semantics::
+* Top-level Variable References::
+* Module Analysis::
+@end menu
+
+@node Module Conventions, Module Manifests, Compiling Scheme, Compiling Scheme
+@subsection Module Conventions
+
+@itemize @bullet
@item
-'complex
+All the top-level @code{require} commands have one quoted argument and
+are positioned before other Scheme definitions and expressions in the
+file.
@item
-'bignum
+Any conditionally @code{require}d SLIB modules
+@footnote{There are some functions with internal @code{require} calls
+to delay loading modules until they are needed. While this reduces
+startup latency for interpreters, it can produce headaches for
+compilers.}
+also appear at the beginning of their files conditioned on the feature
+@cindex compiling
+@code{compiling} using @code{require-if}
+(@pxref{Require, require-if}).
+
+@example
+(require 'logical)
+(require 'multiarg/and-)
+(require-if 'compiling 'sort)
+(require-if 'compiling 'ciexyz)
+@end example
+
+@item
+Schmooz-style comments preceding a definition, identify that
+definition as an exported identifier (@pxref{Schmooz}). For
+non-schmooz files, putting @samp{;@@} at the beginning of the line
+immediately preceding the definition (@code{define},
+@code{define-syntax}, or @code{defmacro}) suffices.
+
+@example
+;@@
+(define (make-vicinity <pathname>) <pathname>)
+@end example
+
+@item
+Syntax (macro) definitions are grouped at the end of a module file.
+
+@item
+Modules defining macros do not invoke those macros. SLIB macro
+implementations are exempt from this rule.
+
+An example of how to expand macro invocations is:
+
+@example
+(require 'macros-that-work)
+(require 'yasos)
+(require 'pprint-file)
+(pprint-filter-file "collect.scm" macwork:expand)
+@end example
+
@end itemize
-For each item, @code{(provided? '@var{feature})} will return @code{#t}
-if that feature is available, and @code{#f} if not.
-@end defvar
-@defvar *modules*
-Is a list of pathnames denoting files which have been loaded.
-@end defvar
+@node Module Manifests, Module Semantics, Module Conventions, Compiling Scheme
+@subsection Module Manifests
-@defvar *catalog*
-Is an association list of features (symbols) and pathnames which will
-supply those features. The pathname can be either a string or a pair.
-If pathname is a pair then the first element should be a macro feature
-symbol, @code{source}, or @code{compiled}. The cdr of the pathname
-should be either a string or a list.
-@end defvar
+@include manifest.txi
-@noindent
-In the following functions if the argument @var{feature} is not a symbol
-it is assumed to be a pathname.
-@defun provided? feature
-Returns @code{#t} if @var{feature} is a member of @code{*features*} or
-@code{*modules*} or if @var{feature} is supported by a file already
-loaded and @code{#f} otherwise.
-@end defun
-
-@deffn Procedure require feature
-@var{feature} is a symbol. If @code{(provided? @var{feature})} is true
-@code{require} returns. Otherwise, if @code{(assq @var{feature}
-*catalog*)} is not @code{#f}, the associated files will be loaded and
-@code{(provided? @var{feature})} will henceforth return @code{#t}. An
-unspecified value is returned. If @var{feature} is not found in
-@code{*catalog*}, then an error is signaled.
-
-@deffnx Procedure require pathname
-@var{pathname} is a string. If @var{pathname} has not already been
-given as an argument to @code{require}, @var{pathname} is loaded. An
-unspecified value is returned.
-@end deffn
+@node Module Semantics, Top-level Variable References, Module Manifests, Compiling Scheme
+@subsection Module Semantics
-@deffn Procedure provide feature
-Assures that @var{feature} is contained in @code{*features*} if
-@var{feature} is a symbol and @code{*modules*} otherwise.
-@end deffn
+For the purpose of compiling Scheme code, each top-level
+@code{require} makes the identifiers exported by its feature's module
+@code{defined} (or defmacroed or defined-syntaxed) within the file
+(being compiled) headed with those requires.
-@defun require:feature->path feature
-Returns @code{#t} if @var{feature} is a member of @code{*features*} or
-@code{*modules*} or if @var{feature} is supported by a file already
-loaded. Returns a path if one was found in @code{*catalog*} under the
-feature name, and @code{#f} otherwise. The path can either be a string
-suitable as an argument to load or a pair as described above for
-*catalog*.
-@end defun
+Top-level occurrences of @code{require-if} make defined the exports
+from the module named by the second argument @emph{if} the
+@var{feature-expression} first argument is true in the target
+environment. The target feature @code{compiling} should be provided
+during this phase of compilation.
+Non-top-level SLIB occurences of @code{require} and @code{require-if}
+of quoted features can be ignored by compilers. The SLIB modules will
+all have top-level constructs for those features.
+@cindex aggregate
+Note that aggregate catalog entries import more than one module.
+Implementations of @code{require} may or may @emph{not} be transitive;
+code which uses module exports without requiring the providing module
+is in error.
+In the SLIB modules @code{modular}, @code{batch}, @code{hash},
+@code{common-lisp-time}, @code{commutative-ring}, @code{charplot},
+@code{logical}, @code{common-list-functions}, @code{coerce} and
+@code{break} there is code conditional on features being
+@code{provided?}. Most are testing for the presence of features which
+are intrinsic to implementations (inexacts, bignums, ...).
-@node Vicinity, Configuration, Require, Built-in Support
-@subsection Vicinity
+In all cases these @code{provided?} tests can be evaluated at
+compile-time using @code{feature-eval}
+(@pxref{Feature, feature-eval}). The simplest way to compile these
+constructs may be to treat @code{provided?} as a macro.
+
+
+@node Top-level Variable References, Module Analysis, Module Semantics, Compiling Scheme
+@subsection Top-level Variable References
+
+@include top-refs.txi
+
+
+
+@node Module Analysis, , Top-level Variable References, Compiling Scheme
+@subsection Module Analysis
+
+@include vet.txi
+
+
+
+@node Universal SLIB Procedures, Scheme Syntax Extension Packages, The Library System, Top
+@chapter Universal SLIB Procedures
+
+@noindent
+The procedures described in these sections are supported by all
+implementations as part of the @samp{*.init} files or by
+@file{require.scm}.
+
+@menu
+* Vicinity:: Pathname Management
+* Configuration:: Characteristics of Scheme Implementation
+* Input/Output:: Things not provided by the Scheme specs.
+* System:: LOADing, EVALing, ERRORing, and EXITing
+* Miscellany::
+@end menu
+
+
+@node Vicinity, Configuration, Universal SLIB Procedures, Universal SLIB Procedures
+@section Vicinity
@noindent
A vicinity is a descriptor for a place in the file system. Vicinities
@@ -525,8 +715,17 @@ these procedures are file system dependent.
@noindent
These procedures are provided by all implementations.
-@defun make-vicinity path
-Returns the vicinity of @var{path} for use by @code{in-vicinity}.
+@defun make-vicinity dirpath
+Returns @var{dirpath} as a vicinity for use as first argument to
+@code{in-vicinity}.
+@end defun
+
+@defun pathname->vicinity path
+Returns the vicinity containing @var{path}.
+@example
+(pathname->vicinity "/usr/local/lib/scm/Link.scm")
+ @result{} "/usr/local/lib/scm/"
+@end example
@end defun
@defun program-vicinity
@@ -567,6 +766,12 @@ returns @code{#f}.
@c systems this is @samp{.scm}.
@c @end defun
+@defun vicinity:suffix? chr
+Returns the @samp{#t} if @var{chr} is a vicinity suffix character; and
+@code{#f} otherwise. Typical vicinity suffixes are @samp{/},
+@samp{:}, and @samp{\},
+@end defun
+
@defun in-vicinity vicinity filename
Returns a filename suitable for use by @code{slib:load},
@code{slib:load-source}, @code{slib:load-compiled},
@@ -590,8 +795,8 @@ return a pathname of the subdirectory @var{name} of
-@node Configuration, Input/Output, Vicinity, Built-in Support
-@subsection Configuration
+@node Configuration, Input/Output, Vicinity, Universal SLIB Procedures
+@section Configuration
@noindent
These constants and procedures describe characteristics of the Scheme
@@ -652,8 +857,8 @@ Writes the report to file @file{filename}.
(slib:report)
@result{}
slib "@value{SLIBVERSION}" on scm "5b1" on unix
-(implementation-vicinity) is "/home/jaffer/scm/"
-(library-vicinity) is "/home/jaffer/slib/"
+(implementation-vicinity) is "/usr/local/lib/scm/"
+(library-vicinity) is "/usr/local/lib/slib/"
(scheme-file-suffix) is ".scm"
loaded *features* :
trace alist qp sort
@@ -663,7 +868,7 @@ implementation *features* :
bignum complex real rational
inexact vicinity ed getenv
tmpnam abort transcript with-file
- ieee-p1178 rev4-report rev4-optional-procedures hash
+ ieee-p1178 r4rs rev4-optional-procedures hash
object-hash delay eval dynamic-wind
multiarg-apply multiarg/and- logical defmacro
string-port source current-time record
@@ -671,127 +876,134 @@ implementation *features* :
array dump char-ready? full-continuation
system
implementation *catalog* :
- (i/o-extensions compiled "/home/jaffer/scm/ioext.so")
+ (i/o-extensions compiled "/usr/local/lib/scm/ioext.so")
...
@end example
@end defun
-@node Input/Output, Legacy, Configuration, Built-in Support
-@subsection Input/Output
+@node Input/Output, System, Configuration, Universal SLIB Procedures
+@section Input/Output
@noindent
These procedures are provided by all implementations.
-@deffn Procedure file-exists? filename
+@defun file-exists? filename
Returns @code{#t} if the specified file exists. Otherwise, returns
@code{#f}. If the underlying implementation does not support this
feature then @code{#f} is always returned.
-@end deffn
+@end defun
-@deffn Procedure delete-file filename
+@defun delete-file filename
Deletes the file specified by @var{filename}. If @var{filename} can not
be deleted, @code{#f} is returned. Otherwise, @code{#t} is
returned.
+@end defun
+
+@defun open-file filename modes
+@var{filename} should be a string naming a file. @code{open-file}
+returns a port depending on the symbol @var{modes}:
+
+@table @r
+@item r
+an input port capable of delivering characters from the file.
+@item rb
+a @emph{binary} input port capable of delivering characters from the file.
+@item w
+an output port capable of writing characters to a new file by that name.
+@item wb
+a @emph{binary} output port capable of writing characters to a new file
+by that name.
+@end table
+
+If an implementation does not distinguish between binary and non-binary
+files, then it must treat @r{rb} as @r{r} and @r{wb} as @r{w}.
+
+If the file cannot be opened, either #f is returned or an error is
+signalled. For output, if a file with the given name already exists,
+the effect is unspecified.
+@end defun
+
+@defun port? obj
+Returns @t{#t} if @var{obj} is an input or output port, otherwise
+returns @t{#f}.
+@end defun
+
+@deffn {Procedure} close-port port
+Closes the file associated with @var{port}, rendering the @var{port}
+incapable of delivering or accepting characters.
+
+@code{close-file} has no effect if the file has already been closed.
+The value returned is unspecified.
@end deffn
-@deffn Procedure tmpnam
+@defun call-with-open-ports proc ports @dots{}
+@defunx call-with-open-ports ports @dots{} proc
+@var{Proc} should be a procedure that accepts as many arguments as there
+are @var{ports} passed to @code{call-with-open-ports}.
+@code{call-with-open-ports} calls @var{proc} with @var{ports} @dots{}.
+If @var{proc} returns, then the ports are closed automatically and the
+value yielded by the @var{proc} is returned. If @var{proc} does not
+return, then the ports will not be closed automatically unless it is
+possible to prove that the ports will never again be used for a read or
+write operation.
+@end defun
+
+@defun tmpnam
Returns a pathname for a file which will likely not be used by any other
process. Successive calls to @code{(tmpnam)} will return different
pathnames.
-@end deffn
+@end defun
-@deffn Procedure current-error-port
+@defun current-error-port
Returns the current port to which diagnostic and error output is
directed.
-@end deffn
+@end defun
-@deffn Procedure force-output
-@deffnx Procedure force-output port
+@deffn {Procedure} force-output
+@deffnx {Procedure} force-output port
Forces any pending output on @var{port} to be delivered to the output
device and returns an unspecified value. The @var{port} argument may be
omitted, in which case it defaults to the value returned by
@code{(current-output-port)}.
@end deffn
-@deffn Procedure output-port-width
-@deffnx Procedure output-port-width port
+@defun output-port-width
+@defunx output-port-width port
Returns the width of @var{port}, which defaults to
@code{(current-output-port)} if absent. If the width cannot be
determined 79 is returned.
-@end deffn
+@end defun
-@deffn Procedure output-port-height
-@deffnx Procedure output-port-height port
+@defun output-port-height
+@defunx output-port-height port
Returns the height of @var{port}, which defaults to
@code{(current-output-port)} if absent. If the height cannot be
determined 24 is returned.
-@end deffn
-
-@node Legacy, System, Input/Output, Built-in Support
-@subsection Legacy
-
-These procedures are provided by all implementations.
-
-@defun identity x
-@var{identity} returns its argument.
-
-Example:
-@lisp
-(identity 3)
- @result{} 3
-(identity '(foo bar))
- @result{} (foo bar)
-(map identity @var{lst})
- @equiv{} (copy-list @var{lst})
-@end lisp
@end defun
-@noindent
-The following procedures were present in Scheme until R4RS
-(@pxref{Notes, , Language changes ,r4rs, Revised(4) Scheme}).
-They are provided by all SLIB implementations.
-
-@defvr Constant t
-Derfined as @code{#t}.
-@end defvr
-
-@defvr Constant nil
-Defined as @code{#f}.
-@end defvr
-
-@defun last-pair l
-Returns the last pair in the list @var{l}. Example:
-@lisp
-(last-pair (cons 1 2))
- @result{} (1 . 2)
-(last-pair '(1 2))
- @result{} (2)
- @equiv{} (cons 2 '())
-@end lisp
-@end defun
-@node System, , Legacy, Built-in Support
-@subsection System
+@node System, Miscellany, Input/Output, Universal SLIB Procedures
+@section System
@noindent
These procedures are provided by all implementations.
-@deffn Procedure slib:load-source name
+@deffn {Procedure} slib:load-source name
Loads a file of Scheme source code from @var{name} with the default
filename extension used in SLIB. For instance if the filename extension
used in SLIB is @file{.scm} then @code{(slib:load-source "foo")} will
load from file @file{foo.scm}.
@end deffn
-@deffn Procedure slib:load-compiled name
+@deffn {Procedure} slib:load-compiled name
On implementations which support separtely loadable compiled modules,
loads a file of compiled code from @var{name} with the implementation's
filename extension for compiled code appended.
@end deffn
-@deffn Procedure slib:load name
+@deffn {Procedure} slib:load name
Loads a file of Scheme source or compiled code from @var{name} with the
appropriate suffixes appended. If both source and compiled code are
present with the appropriate names then the implementation will load
@@ -802,13 +1014,13 @@ If an implementation does not support compiled code then
@code{slib:load} will be identical to @code{slib:load-source}.
@end deffn
-@deffn Procedure slib:eval obj
+@deffn {Procedure} slib:eval obj
@code{eval} returns the value of @var{obj} evaluated in the current top
level environment. @ref{Eval} provides a more general evaluation
facility.
@end deffn
-@deffn Procedure slib:eval-load filename eval
+@deffn {Procedure} slib:eval-load filename eval
@var{filename} should be a string. If filename names an existing file,
the Scheme source code expressions and definitions are read from the
file and @var{eval} called with them sequentially. The
@@ -816,19 +1028,19 @@ file and @var{eval} called with them sequentially. The
@code{current-input-port} and @code{current-output-port}.
@end deffn
-@deffn Procedure slib:warn arg1 arg2 @dots{}
+@deffn {Procedure} slib:warn arg1 arg2 @dots{}
Outputs a warning message containing the arguments.
@end deffn
-@deffn Procedure slib:error arg1 arg2 @dots{}
+@deffn {Procedure} slib:error arg1 arg2 @dots{}
Outputs an error message containing the arguments, aborts evaluation of
the current form and responds in a system dependent way to the error.
Typical responses are to abort the program or to enter a read-eval-print
loop.
@end deffn
-@deffn Procedure slib:exit n
-@deffnx Procedure slib:exit
+@deffn {Procedure} slib:exit n
+@deffnx {Procedure} slib:exit
Exits from the Scheme session returning status @var{n} to the system.
If @var{n} is omitted or @code{#t}, a success status is returned to the
system (if possible). If @var{n} is @code{#f} a failure is returned to
@@ -837,29 +1049,108 @@ returned to the system (if possible). If the Scheme session cannot exit
an unspecified value is returned from @code{slib:exit}.
@end deffn
+@defun browse-url url
+Web browsers have become so ubiquitous that programming languagues
+should support a uniform interface to them.
-@node About this manual, , Built-in Support, The Library System
-@section About this manual
+If a @samp{netscape} browser is running, @code{browse-url} causes the
+browser to display the page specified by string @var{url} and returns
+#t.
-@itemize @bullet
-@item
-Entries that are labeled as Functions are called for their return
-values. Entries that are labeled as Procedures are called primarily for
-their side effects.
+If the browser is not running, @code{browse-url} starts a browser
+displaying the argument @var{url}. If the browser starts as a
+background job, @code{browse-url} returns #t immediately; if the
+browser starts as a foreground job, then @code{browse-url} returns #t
+when the browser exits; otherwise it returns #f.
+@end defun
-@item
-Examples in this text were produced using the @code{scm} Scheme
-implementation.
-@item
-At the beginning of each section, there is a line that looks like
-@ftindex feature
-@code{(require 'feature)}. Include this line in your code prior to
-using the package.
-@end itemize
+@node Miscellany, , System, Universal SLIB Procedures
+@section Miscellany
+
+These procedures are provided by all implementations.
+
+@defun identity x
+@var{identity} returns its argument.
+
+Example:
+@lisp
+(identity 3)
+ @result{} 3
+(identity '(foo bar))
+ @result{} (foo bar)
+(map identity @var{lst})
+ @equiv{} (copy-list @var{lst})
+@end lisp
+@end defun
+
+@subsection Mutual Exclusion
+
+@noindent
+An @dfn{exchanger} is a procedure of one argument regulating mutually
+@cindex exchanger
+exclusive access to a resource. When a exchanger is called, its current
+content is returned, while being replaced by its argument in an atomic
+operation.
+@defun make-exchanger obj
-@node Scheme Syntax Extension Packages, Textual Conversion Packages, The Library System, Top
+Returns a new exchanger with the argument @var{obj} as its initial
+content.
+
+@example
+(define queue (make-exchanger (list a)))
+@end example
+
+A queue implemented as an exchanger holding a list can be protected from
+reentrant execution thus:
+
+@example
+(define (pop queue)
+ (let ((lst #f))
+ (dynamic-wind
+ (lambda () (set! lst (queue #f)))
+ (lambda () (and lst (not (null? lst))
+ (let ((ret (car lst)))
+ (set! lst (cdr lst))
+ ret)))
+ (lambda () (and lst (queue lst))))))
+
+(pop queue) @result{} a
+
+(pop queue) @result{} #f
+@end example
+@end defun
+
+
+@subsection Legacy
+
+@noindent
+The following procedures were present in Scheme until R4RS
+(@pxref{Notes, , Language changes ,r4rs, Revised(4) Scheme}).
+They are provided by all SLIB implementations.
+
+@defvr Constant t
+Derfined as @code{#t}.
+@end defvr
+
+@defvr Constant nil
+Defined as @code{#f}.
+@end defvr
+
+@defun last-pair l
+Returns the last pair in the list @var{l}. Example:
+@lisp
+(last-pair (cons 1 2))
+ @result{} (1 . 2)
+(last-pair '(1 2))
+ @result{} (2)
+ @equiv{} (cons 2 '())
+@end lisp
+@end defun
+
+
+@node Scheme Syntax Extension Packages, Textual Conversion Packages, Universal SLIB Procedures, Top
@chapter Scheme Syntax Extension Packages
@menu
@@ -962,7 +1253,7 @@ Takes an R4RS expression, macro-expands it, evals the result of the
macro expansion, and returns the result of the evaluation.
@end defun
-@deffn Procedure macro:load filename
+@deffn {Procedure} macro:load filename
@var{filename} should be a string. If filename names an existing file,
the @code{macro:load} procedure reads Scheme source code expressions and
definitions from the file and evaluates them sequentially. These source
@@ -1076,8 +1367,8 @@ Side effects of @var{expression} will affect the top level
environment.
@end defun
-@deffn Procedure macro:load filename
-@deffnx Procedure macwork:load filename
+@deffn {Procedure} macro:load filename
+@deffnx {Procedure} macwork:load filename
@var{filename} should be a string. If filename names an existing file,
the @code{macro:load} procedure reads Scheme source code expressions and
definitions from the file and evaluates them sequentially. These source
@@ -1266,8 +1557,8 @@ Side effects of @var{expression} will affect the top level
environment.
@end defun
-@deffn Procedure macro:load filename
-@deffnx Procedure synclo:load filename
+@deffn {Procedure} macro:load filename
+@deffnx {Procedure} synclo:load filename
@var{filename} should be a string. If filename names an existing file,
the @code{macro:load} procedure reads Scheme source code expressions and
definitions from the file and evaluates them sequentially. These
@@ -1290,7 +1581,8 @@ report.
The syntactic closures facility extends the BNF rule for
@var{transformer spec} to allow a new keyword that introduces a
-low-level macro transformer:@refill
+low-level macro transformer:
+
@example
@var{transformer spec} := (transformer @var{expression})
@end example
@@ -1320,7 +1612,8 @@ closures facility.
recursively constructed. A form is any expression, any definition, any
syntactic keyword, or any syntactic closure. The variable name that
appears in a @code{set!} special form is also a form. Examples of
-forms:@refill
+forms:
+
@lisp
17
#t
@@ -1387,7 +1680,8 @@ the transformer, the @dfn{output form}, is automatically closed in the
which the @code{transformer} expression occurred.
For example, here is a definition of a push macro using
-@code{syntax-rules}:@refill
+@code{syntax-rules}:
+
@lisp
(define-syntax push
(syntax-rules ()
@@ -1416,7 +1710,8 @@ Some macros may be non-hygienic by design. For example, the following
defines a loop macro that implicitly binds @code{exit} to an escape
procedure. The binding of @code{exit} is intended to capture free
references to @code{exit} in the body of the loop, so @code{exit} must
-be left free when the body is closed:@refill
+be left free when the body is closed:
+
@lisp
(define-syntax loop
(transformer
@@ -1483,7 +1778,8 @@ transformed, call @var{procedure} on the current syntactic environment.
in that same syntactic environment, in place of the form.
An example will make this clear. Suppose we wanted to define a simple
-@code{loop-until} keyword equivalent to@refill
+@code{loop-until} keyword equivalent to
+
@lisp
(define-syntax loop-until
(syntax-rules ()
@@ -1530,7 +1826,8 @@ exposed to is the one just outside the @code{lambda} expression: before
the user's identifier is added to the syntactic environment, but after
the identifier loop has been added.
@code{capture-syntactic-environment} captures exactly that environment
-as follows:@refill
+as follows:
+
@lisp
(define-syntax loop-until
(transformer
@@ -1562,7 +1859,8 @@ and the @code{loop} and use them in the body of the
@code{lambda}.
A common use of @code{capture-syntactic-environment} is to get the
-transformer environment of a macro transformer:@refill
+transformer environment of a macro transformer:
+
@lisp
(transformer
(lambda (exp env)
@@ -1582,7 +1880,8 @@ high-level @code{syntax-rules} facility.
As discussed earlier, an identifier is either a symbol or an
@dfn{alias}. An alias is implemented as a syntactic closure whose
-@dfn{form} is an identifier:@refill
+@dfn{form} is an identifier:
+
@lisp
(make-syntactic-closure env '() 'a)
@result{} an @dfn{alias}
@@ -1607,7 +1906,8 @@ know the syntactic roles of the substituted input subforms.
@defun identifier? object
Returns @code{#t} if @var{object} is an identifier, otherwise returns
-@code{#f}. Examples:@refill
+@code{#f}. Examples:
+
@lisp
(identifier? 'a)
@result{} #t
@@ -1647,7 +1947,7 @@ environments, and @var{identifier1} and @var{identifier2} must be
identifiers. @code{identifier=?} returns @code{#t} if the meaning of
@var{identifier1} in @var{environment1} is the same as that of
@var{identifier2} in @var{environment2}, otherwise it returns @code{#f}.
-Examples:@refill
+Examples:
@lisp
(let-syntax
@@ -1711,8 +2011,8 @@ Side effects of @var{expression} will affect the top level
environment.
@end defun
-@deffn Procedure macro:load filename
-@deffnx Procedure syncase:load filename
+@deffn {Procedure} macro:load filename
+@deffnx {Procedure} syncase:load filename
@var{filename} should be a string. If filename names an existing file,
the @code{macro:load} procedure reads Scheme source code expressions and
definitions from the file and evaluates them sequentially. These
@@ -1773,6 +2073,7 @@ To check operation of syntax-case get
@lisp
(require 'syntax-case)
@ftindex syntax-case
+@findex syncase:sanity-check
(syncase:sanity-check)
@end lisp
@@ -1810,11 +2111,16 @@ know if there is some incompatibility that is not flagged as such.
Send bug reports, comments, suggestions, and questions to Kent Dybvig
(dyb @@ iuvax.cs.indiana.edu).
-@subsection Note from maintainer
+@subsection Note from SLIB maintainer
+
+@code{(require 'structure)}
+@findex define-structure
Included with the @code{syntax-case} files was @file{structure.scm}
-which defines a macro @code{define-structure}. There is no
-documentation for this macro and it is not used by any code in SLIB.
+which defines a macro @code{define-structure}. I have no
+documentation for this macro; it is not used by any other code in
+SLIB.
+
@node Fluid-Let, Yasos, Syntax-Case Macros, Scheme Syntax Extension Packages
@section Fluid-Let
@@ -1952,7 +2258,7 @@ Used in an operation definition (of @var{self}) to invoke the
identity. Also known as ``send-to-super''.
@end deffn
-@deffn Procedure print obj port
+@deffn {Procedure} print obj port
A default @code{print} operation is provided which is just @code{(format
@var{port} @var{obj})} (@pxref{Format}) for non-instances and prints
@var{obj} preceded by @samp{#<INSTANCE>} for instances.
@@ -2014,14 +2320,14 @@ foo @result{} "foo"
@end example
@end deffn
-@deffn Procedure add-setter getter setter
+@deffn {Procedure} add-setter getter setter
Add procedures @var{getter} and @var{setter} to the (inaccessible) list
of valid setter/getter pairs. @var{setter} implements the store
operation corresponding to the @var{getter} access operation for the
relevant state. The return value is unspecified.
@end deffn
-@deffn Procedure remove-setter-for getter
+@deffn {Procedure} remove-setter-for getter
Removes the setter corresponding to the specified @var{getter} from the
list of valid setters. The return value is unspecified.
@end deffn
@@ -2058,7 +2364,7 @@ value is unspecified.
((string? obj) (string-length obj))
((char? obj) 1)
(else
- (error "Operation not supported: size" obj))))
+ (slib:error "Operation not supported: size" obj))))
(define-predicate cell?)
(define-operation (fetch obj))
@@ -2144,13 +2450,14 @@ value is unspecified.
* Format:: Common-Lisp Format
* Standard Formatted I/O:: Posix printf and scanf
* Programs and Arguments::
-* HTML::
+* HTML:: Generating
* HTML Tables:: Databases meet HTML
* HTTP and CGI:: Serve WWW sites
+* Parsing HTML:: 'html-for-each
* URI:: Uniform Resource Identifier
* Printing Scheme:: Nicely
* Time and Date::
-* Vector Graphics::
+* NCBI-DNA:: DNA and protein sequences
* Schmooz:: Documentation markup for Scheme programs
@end menu
@@ -2179,13 +2486,14 @@ procedures for higher level specification of rulesets.
@menu
* Precedence Parsing Overview::
+* Rule Types::
* Ruleset Definition and Use::
* Token definition::
* Nud and Led Definition::
* Grammar Rule Definition::
@end menu
-@node Precedence Parsing Overview, Ruleset Definition and Use, Precedence Parsing, Precedence Parsing
+@node Precedence Parsing Overview, Rule Types, Precedence Parsing, Precedence Parsing
@subsection Precedence Parsing Overview
@noindent
@@ -2210,6 +2518,35 @@ missing input.
@end itemize
@noindent
+@cindex binding power
+The notion of @dfn{binding power} may be unfamiliar to those
+accustomed to BNF grammars.
+
+@noindent
+When two consecutive objects are parsed, the first might be the prefix
+to the second, or the second might be a suffix of the first.
+Comparing the left and right binding powers of the two objects decides
+which way to interpret them.
+
+@noindent
+Objects at each level of syntactic grouping have binding powers.
+
+@noindent
+@cindex syntax tree
+A syntax tree is not built unless the rules explicitly do so. The
+call graph of grammar rules effectively instantiate the sytnax tree.
+
+@noindent
+The JACAL symbolic math system
+(@url{http://swissnet.ai.mit.edu/~jaffer/JACAL.html}) uses
+@t{precedence-parse}. Its grammar definitions in the file
+@file{jacal/English.scm} can serve as examples of use.
+
+
+@node Rule Types, Ruleset Definition and Use, Precedence Parsing Overview, Precedence Parsing
+@subsection Rule Types
+
+@noindent
Here are the higher-level syntax types and an example of each.
Precedence considerations are omitted for clarity. See @ref{Grammar
Rule Definition} for full details.
@@ -2279,7 +2616,7 @@ delimits the extent of the restfix operator @code{set}.
@end deftp
-@node Ruleset Definition and Use, Token definition, Precedence Parsing Overview, Precedence Parsing
+@node Ruleset Definition and Use, Token definition, Rule Types, Precedence Parsing
@subsection Ruleset Definition and Use
@defvar *syn-defs*
@@ -2405,6 +2742,16 @@ Is the string consisting of all characters between 0 and 255 for which
@code{char-whitespace?} returns true.
@end defvr
+@noindent
+For the purpose of reporting problems in error messages, this package
+keeps track of the @dfn{current column}. When the column does not
+simply track input characters, @code{tok:bump-column} can be used to
+adjust the current-column.
+
+@defun tok:bump-column pos port
+Adds @var{pos} to the current-column for input-port @var{port}.
+@end defun
+
@node Nud and Led Definition, Grammar Rule Definition, Token definition, Precedence Parsing
@subsection Nud and Led Definition
@@ -2689,10 +3036,17 @@ The ruleset in effect before @var{tk} was parsed is restored;
@node Format, Standard Formatted I/O, Precedence Parsing, Textual Conversion Packages
@section Format (version 3.0)
-@code{(require 'format)}
+@ifset html
+<A NAME="format"></A>
+@end ifset
+@c @code{(require 'format)}
@ftindex format
-@include fmtdoc.txi
+@c @include fmtdoc.txi
+The @file{format.scm} package was removed because it was not
+reentrant. @url{http://swissnet.ai.mit.edu/~jaffer/SLIB.FAQ} explains
+more about FORMAT's woes.
+
@node Standard Formatted I/O, Programs and Arguments, Format, Textual Conversion Packages
@section Standard Formatted I/O
@@ -2724,14 +3078,17 @@ Defined to be @code{(current-error-port)}.
@node Standard Formatted Output, Standard Formatted Input, Standard Formatted I/O, Standard Formatted I/O
@subsection Standard Formatted Output
+@ifset html
+<A NAME="printf"></A>
+@end ifset
@code{(require 'printf)}
@ftindex printf
-@deffn Procedure printf format arg1 @dots{}
-@deffnx Procedure fprintf port format arg1 @dots{}
-@deffnx Procedure sprintf str format arg1 @dots{}
-@deffnx Procedure sprintf #f format arg1 @dots{}
-@deffnx Procedure sprintf k format arg1 @dots{}
+@deffn {Procedure} printf format arg1 @dots{}
+@deffnx {Procedure} fprintf port format arg1 @dots{}
+@deffnx {Procedure} sprintf str format arg1 @dots{}
+@deffnx {Procedure} sprintf #f format arg1 @dots{}
+@deffnx {Procedure} sprintf k format arg1 @dots{}
Each function converts, formats, and outputs its @var{arg1} @dots{}
arguments according to the control string @var{format} argument and
@@ -3148,32 +3505,51 @@ This routine implements Posix command line argument parsing. Notice
that returning values through global variables means that @code{getopt}
is @emph{not} reentrant.
+Obedience to Posix format for the @code{getopt} calls sows confusion.
+Passing @var{argc} and @var{argv} as arguments while referencing
+@var{optind} as a global variable leads to strange behavior,
+especially when the calls to @code{getopt} are buried in other
+procedures.
+
+Even in C, @var{argc} can be derived from @var{argv}; what purpose
+does it serve beyond providing an opportunity for
+@var{argv}/@var{argc} mismatch? Just such a mismatch existed for
+years in a SLIB @code{getopt--} example.
+
+I have removed the @var{argc} and @var{argv} arguments to getopt
+procedures; and replaced them with a global variable:
+
+@defvar *argv*
+Define @var{*argv*} with a list of arguments before calling getopt
+procedures. If you don't want the first (0th) element to be ignored,
+set @var{*optind*} to 0 (after requiring getopt).
+@end defvar
+
@defvar *optind*
Is the index of the current element of the command line. It is
initially one. In order to parse a new command line or reparse an old
-one, @var{*opting*} must be reset.
+one, @var{*optind*} must be reset.
@end defvar
@defvar *optarg*
Is set by getopt to the (string) option-argument of the current option.
@end defvar
-@deffn Procedure getopt argc argv optstring
-Returns the next option letter in @var{argv} (starting from
+@defun getopt optstring
+Returns the next option letter in @var{*argv*} (starting from
@code{(vector-ref argv *optind*)}) that matches a letter in
-@var{optstring}. @var{argv} is a vector or list of strings, the 0th of
-which getopt usually ignores. @var{argc} is the argument count, usually
-the length of @var{argv}. @var{optstring} is a string of recognized
-option characters; if a character is followed by a colon, the option
-takes an argument which may be immediately following it in the string or
-in the next element of @var{argv}.
-
-@var{*optind*} is the index of the next element of the @var{argv} vector
+@var{optstring}. @var{*argv*} is a vector or list of strings, the 0th
+of which getopt usually ignores. @var{optstring} is a string of
+recognized option characters; if a character is followed by a colon,
+the option takes an argument which may be immediately following it in
+the string or in the next element of @var{*argv*}.
+
+@var{*optind*} is the index of the next element of the @var{*argv*} vector
to be processed. It is initialized to 1 by @file{getopt.scm}, and
@code{getopt} updates it when it finishes with each element of
-@var{argv}.
+@var{*argv*}.
-@code{getopt} returns the next option character from @var{argv} that
+@code{getopt} returns the next option character from @var{*argv*} that
matches a character in @var{optstring}, if there is one that matches.
If the option takes an argument, @code{getopt} sets the variable
@var{*optarg*} to the option-argument as follows:
@@ -3181,15 +3557,15 @@ If the option takes an argument, @code{getopt} sets the variable
@itemize @bullet
@item
If the option was the last character in the string pointed to by an
-element of @var{argv}, then @var{*optarg*} contains the next element of
-@var{argv}, and @var{*optind*} is incremented by 2. If the resulting
-value of @var{*optind*} is greater than or equal to @var{argc}, this
-indicates a missing option argument, and @code{getopt} returns an error
-indication.
+element of @var{*argv*}, then @var{*optarg*} contains the next element
+of @var{*argv*}, and @var{*optind*} is incremented by 2. If the
+resulting value of @var{*optind*} is greater than or equal to
+@code{(length @var{*argv*})}, this indicates a missing option
+argument, and @code{getopt} returns an error indication.
@item
Otherwise, @var{*optarg*} is set to the string following the option
-character in that element of @var{argv}, and @var{*optind*} is
+character in that element of @var{*argv*}, and @var{*optind*} is
incremented by 1.
@end itemize
@@ -3251,11 +3627,11 @@ Example:
(slib:exit)
@end lisp
-@end deffn
+@end defun
-@subsection Getopt--
+@subsection Getopt---
-@defun getopt-- argc argv optstring
+@defun @code{getopt--} optstring
The procedure @code{getopt--} is an extended version of @code{getopt}
which parses @dfn{long option names} of the form
@samp{--hold-the-onions} and @samp{--verbosity-level=extreme}.
@@ -3269,22 +3645,21 @@ not returned as part of the option string.
No information is passed to @code{getopt--} concerning which long
options should be accepted or whether such options can take arguments.
-If a long option did not have an argument, @code{*optarg} will be set to
-@code{#f}. The caller is responsible for detecting and reporting
+If a long option did not have an argument, @code{*optarg*} will be set
+to @code{#f}. The caller is responsible for detecting and reporting
errors.
@example
(define opts ":-:b:")
-(define argc 5)
-(define argv '("foo" "-b9" "--f1" "--2=" "--g3=35234.342" "--"))
+(define *argv* '("foo" "-b9" "--f1" "--2=" "--g3=35234.342" "--"))
(define *optind* 1)
(define *optarg* #f)
(require 'qp)
@ftindex qp
(do ((i 5 (+ -1 i)))
((zero? i))
- (define opt (getopt-- argc argv opts))
- (print *optind* opt *optarg*)))
+ (let ((opt (getopt-- opts)))
+ (print *optind* opt *optarg*)))
@print{}
2 #\b "9"
3 "f1" #f
@@ -3297,81 +3672,7 @@ errors.
@node Command Line, Parameter lists, Getopt, Programs and Arguments
@subsection Command Line
-@code{(require 'read-command)}
-@ftindex read-command
-
-@defun read-command port
-@defunx read-command
-@code{read-command} converts a @dfn{command line} into a list of strings
-@cindex command line
-suitable for parsing by @code{getopt}. The syntax of command lines
-supported resembles that of popular @dfn{shell}s. @code{read-command}
-updates @var{port} to point to the first character past the command
-delimiter.
-
-If an end of file is encountered in the input before any characters are
-found that can begin an object or comment, then an end of file object is
-returned.
-
-The @var{port} argument may be omitted, in which case it defaults to the
-value returned by @code{current-input-port}.
-
-The fields into which the command line is split are delimited by
-whitespace as defined by @code{char-whitespace?}. The end of a command
-is delimited by end-of-file or unescaped semicolon (@key{;}) or
-@key{newline}. Any character can be literally included in a field by
-escaping it with a backslach (@key{\}).
-
-The initial character and types of fields recognized are:
-@table @asis
-@item @samp{\}
-The next character has is taken literally and not interpreted as a field
-delimiter. If @key{\} is the last character before a @key{newline},
-that @key{newline} is just ignored. Processing continues from the
-characters after the @key{newline} as though the backslash and
-@key{newline} were not there.
-@item @samp{"}
-The characters up to the next unescaped @key{"} are taken literally,
-according to [R4RS] rules for literal strings (@pxref{Strings, , ,r4rs,
-Revised(4) Scheme}).
-@item @samp{(}, @samp{%'}
-One scheme expression is @code{read} starting with this character. The
-@code{read} expression is evaluated, converted to a string
-(using @code{display}), and replaces the expression in the returned
-field.
-@item @samp{;}
-Semicolon delimits a command. Using semicolons more than one command
-can appear on a line. Escaped semicolons and semicolons inside strings
-do not delimit commands.
-@end table
-
-@noindent
-The comment field differs from the previous fields in that it must be
-the first character of a command or appear after whitespace in order to
-be recognized. @key{#} can be part of fields if these conditions are
-not met. For instance, @code{ab#c} is just the field ab#c.
-
-@table @samp
-@item #
-Introduces a comment. The comment continues to the end of the line on
-which the semicolon appears. Comments are treated as whitespace by
-@code{read-dommand-line} and backslashes before @key{newline}s in
-comments are also ignored.
-@end table
-@end defun
-
-@defun read-options-file filename
-@code{read-options-file} converts an @dfn{options file} into a list of
-@cindex options file
-strings suitable for parsing by @code{getopt}. The syntax of options
-files is the same as the syntax for command
-lines, except that @key{newline}s do not terminate reading (only @key{;}
-or end of file).
-
-If an end of file is encountered before any characters are found that
-can begin an object or comment, then an end of file object is returned.
-@end defun
-
+@include comparse.txi
@node Parameter lists, Getopt Parameter lists, Command Line, Programs and Arguments
@@ -3418,11 +3719,11 @@ If there are more than one @var{parameter-name} parameters, an error is
signaled.
@end deffn
-@deffn Procedure adjoin-parameters! parameter-list parameter1 @dots{}
+@deffn {Procedure} adjoin-parameters! parameter-list parameter1 @dots{}
Returns @var{parameter-list} with @var{parameter1} @dots{} merged in.
@end deffn
-@deffn Procedure parameter-list-expand expanders parameter-list
+@deffn {Procedure} parameter-list-expand expanders parameter-list
@var{expanders} is a list of procedures whose order matches the order of
the @var{parameter-name}s in the call to @code{make-parameter-list}
which created @var{parameter-list}. For each non-false element of
@@ -3487,171 +3788,13 @@ should appear.
@node Getopt Parameter lists, Filenames, Parameter lists, Programs and Arguments
@subsection Getopt Parameter lists
-@code{(require 'getopt-parameters)}
-
-@deffn Function getopt->parameter-list argc argv optnames arities types aliases desc @dots{}
-Returns @var{argv} converted to a parameter-list. @var{optnames} are
-the parameter-names. @var{arities} and @var{types} are lists of symbols
-corresponding to @var{optnames}.
-
-@var{aliases} is a list of lists of strings or integers paired with
-elements of @var{optnames}. Each one-character string will be treated
-as a single @samp{-} option by @code{getopt}. Longer strings will be
-treated as long-named options (@pxref{Getopt, getopt--}).
-
-If the @var{aliases} association list has only strings as its
-@code{car}s, then all the option-arguments after an option (and before
-the next option) are adjoined to that option.
-
-If the @var{aliases} association list has integers, then each (string)
-option will take at most one option-argument. Unoptioned arguments are
-collected in a list. A @samp{-1} alias will take the last argument in
-this list; @samp{+1} will take the first argument in the list. The
-aliases -2 then +2; -3 then +3; @dots{} are tried so long as a positive
-or negative consecutive alias is found and arguments remain in the list.
-Finally a @samp{0} alias, if found, absorbs any remaining arguments.
-
-In all cases, if unclaimed arguments remain after processing, a warning
-is signaled and #f is returned.
-@end deffn
-
-@deffn Function getopt->arglist argc argv optnames positions arities types defaulters checks aliases desc @dots{}
-Like @code{getopt->parameter-list}, but converts @var{argv} to an
-argument-list as specified by @var{optnames}, @var{positions},
-@var{arities}, @var{types}, @var{defaulters}, @var{checks}, and
-@var{aliases}. If the options supplied violate the @var{arities} or
-@var{checks} constraints, then a warning is signaled and #f is returned.
-@end deffn
-
-@noindent
-These @code{getopt} functions can be used with SLIB relational
-databases. For an example, @xref{Database Utilities,
-make-command-server}.
-
-@noindent
-If errors are encountered while processing options, directions for using
-the options (and argument strings @var{desc} @dots{}) are printed to
-@code{current-error-port}.
-
-@example
-(begin
- (set! *optind* 1)
- (getopt->parameter-list
- 2
- '("cmd" "-?")
- '(flag number symbols symbols string flag2 flag3 num2 num3)
- '(boolean optional nary1 nary single boolean boolean nary nary)
- '(boolean integer symbol symbol string boolean boolean integer integer)
- '(("flag" flag)
- ("f" flag)
- ("Flag" flag2)
- ("B" flag3)
- ("optional" number)
- ("o" number)
- ("nary1" symbols)
- ("N" symbols)
- ("nary" symbols)
- ("n" symbols)
- ("single" string)
- ("s" string)
- ("a" num2)
- ("Abs" num3))))
-@print{}
-Usage: cmd [OPTION ARGUMENT ...] ...
-
- -f, --flag
- -o, --optional=<number>
- -n, --nary=<symbols> ...
- -N, --nary1=<symbols> ...
- -s, --single=<string>
- --Flag
- -B
- -a <num2> ...
- --Abs=<num3> ...
-
-ERROR: getopt->parameter-list "unrecognized option" "-?"
-@end example
+@include getparam.txi
@node Filenames, Batch, Getopt Parameter lists, Programs and Arguments
@subsection Filenames
-@code{(require 'filename)} or @code{(require 'glob)}
-
-@defun filename:match?? pattern
-@defunx filename:match-ci?? pattern
-Returns a predicate which returns a non-false value if its string argument
-matches (the string) @var{pattern}, false otherwise. Filename matching
-is like
-@cindex glob
-@dfn{glob} expansion described the bash manpage, except that names
-beginning with @samp{.} are matched and @samp{/} characters are not
-treated specially.
-
-These functions interpret the following characters specially in
-@var{pattern} strings:
-@table @samp
-@item *
-Matches any string, including the null string.
-@item ?
-Matches any single character.
-@item [@dots{}]
-Matches any one of the enclosed characters. A pair of characters
-separated by a minus sign (-) denotes a range; any character lexically
-between those two characters, inclusive, is matched. If the first
-character following the @samp{[} is a @samp{!} or a @samp{^} then any
-character not enclosed is matched. A @samp{-} or @samp{]} may be
-matched by including it as the first or last character in the set.
-@end table
-
-@example
-@end example
-@end defun
-
-@defun filename:substitute?? pattern template
-@defunx filename:substitute-ci?? pattern template
-Returns a function transforming a single string argument according to
-glob patterns @var{pattern} and @var{template}. @var{pattern} and
-@var{template} must have the same number of wildcard specifications,
-which need not be identical. @var{pattern} and @var{template} may have
-a different number of literal sections. If an argument to the function
-matches @var{pattern} in the sense of @code{filename:match??} then it
-returns a copy of @var{template} in which each wildcard specification is
-replaced by the part of the argument matched by the corresponding
-wildcard specification in @var{pattern}. A @code{*} wildcard matches
-the longest leftmost string possible. If the argument does not match
-@var{pattern} then false is returned.
-
-@var{template} may be a function accepting the same number of string
-arguments as there are wildcard specifications in @var{pattern}. In
-the case of a match the result of applying @var{template} to a list
-of the substrings matched by wildcard specifications will be returned,
-otherwise @var{template} will not be called and @code{#f} will be returned.
-
-@example
-((filename:substitute?? "scm_[0-9]*.html" "scm5c4_??.htm")
- "scm_10.html")
-@result{} "scm5c4_10.htm"
-((filename:substitute?? "??" "beg?mid?end") "AZ")
-@result{} "begAmidZend"
-((filename:substitute?? "*na*" "?NA?") "banana")
-@result{} "banaNA"
-((filename:substitute?? "?*?" (lambda (s1 s2 s3) (string-append s3 s1))) "ABZ")
-@result{} "ZA"
-@end example
-@end defun
-
-@defun replace-suffix str old new
-@var{str} can be a string or a list of strings. Returns a new string
-(or strings) similar to @code{str} but with the suffix string @var{old}
-removed and the suffix string @var{new} appended. If the end of
-@var{str} does not match @var{old}, an error is signaled.
-
-@example
-(replace-suffix "/usr/local/lib/slib/batch.scm" ".scm" ".c")
-@result{} "/usr/local/lib/slib/batch.c"
-@end example
-@end defun
+@include glob.txi
@node Batch, , Filenames, Programs and Arguments
@@ -3680,7 +3823,7 @@ dos
@item
vms
@item
-amigados
+amigaos
@item
system
@item
@@ -3689,8 +3832,8 @@ system
@end table
@noindent
-@file{batch.scm} uses 2 enhanced relational tables (@pxref{Database
-Utilities}) to store information linking the names of
+@file{batch.scm} uses 2 enhanced relational tables
+(@pxref{Using Databases}) to store information linking the names of
@code{operating-system}s to @code{batch-dialect}es.
@defun batch:initialize! database
@@ -3699,9 +3842,9 @@ the domain @code{operating-system} to the enhanced relational database
@var{database}.
@end defun
-@defvar batch:platform
+@defvar *operating-system*
Is batch's best guess as to which operating-system it is running under.
-@code{batch:platform} is set to @code{(software-type)}
+@code{*operating-system*} is set to @code{(software-type)}
(@pxref{Configuration}) unless @code{(software-type)} is @code{unix},
in which case finer distinctions are made.
@end defvar
@@ -3835,8 +3978,8 @@ tables added to @var{database} by @code{batch:initialize!}.
Here is an example of the use of most of batch's procedures:
@example
-(require 'database-utilities)
-@ftindex database-utilities
+(require 'databases)
+@ftindex databases
(require 'parameters)
@ftindex parameters
(require 'batch)
@@ -3848,8 +3991,8 @@ Here is an example of the use of most of batch's procedures:
(batch:initialize! batch)
(define my-parameters
- (list (list 'batch-dialect (os->batch-dialect batch:platform))
- (list 'platform batch:platform)
+ (list (list 'batch-dialect (os->batch-dialect *operating-system*))
+ (list 'operating-system *operating-system*)
(list 'batch-port (current-output-port)))) ;gets filled in later
(batch:call-with-output-script
@@ -3883,7 +4026,7 @@ Here is an example of the use of most of batch's procedures:
Produces the file @file{my-batch}:
@example
-#!/bin/sh
+#! /bin/sh
# "my-batch" script created by SLIB/batch Sun Oct 31 18:24:10 1999
# ================ Write file with C program.
mv -f hello.c hello.c~
@@ -3925,13 +4068,19 @@ hello world
@include db2html.txi
-@node HTTP and CGI, URI, HTML Tables, Textual Conversion Packages
+@node HTTP and CGI, Parsing HTML, HTML Tables, Textual Conversion Packages
@section HTTP and CGI
@include http-cgi.txi
-@node URI, Printing Scheme, HTTP and CGI, Textual Conversion Packages
+@node Parsing HTML, URI, HTTP and CGI, Textual Conversion Packages
+@section Parsing HTML
+
+@include html4each.txi
+
+
+@node URI, Printing Scheme, Parsing HTML, Textual Conversion Packages
@section URI
@include uri.txi
@@ -3960,7 +4109,7 @@ prints it. The interface to the procedure is sufficiently general to
easily implement other useful formatting procedures such as pretty
printing, output to a string and truncated output.
-@deffn Procedure generic-write obj display? width output
+@deffn {Procedure} generic-write obj display? width output
@table @var
@item obj
Scheme data value to transform.
@@ -4012,8 +4161,8 @@ where
@code{(require 'pretty-print)}
@ftindex pretty-print
-@deffn Procedure pretty-print obj
-@deffnx Procedure pretty-print obj port
+@deffn {Procedure} pretty-print obj
+@deffnx {Procedure} pretty-print obj port
@code{pretty-print}s @var{obj} on @var{port}. If @var{port} is not
specified, @code{current-output-port} is used.
@@ -4032,8 +4181,8 @@ Example:
@end example
@end deffn
-@deffn Procedure pretty-print->string obj
-@deffnx Procedure pretty-print->string obj width
+@deffn {Procedure} pretty-print->string obj
+@deffnx {Procedure} pretty-print->string obj width
Returns the string of @var{obj} @code{pretty-print}ed in @var{width}
columns. If @var{width} is not specified, @code{(output-port-width)} is
@@ -4083,8 +4232,8 @@ Example:
@code{(require 'pprint-file)}
@ftindex pprint-file
-@deffn Procedure pprint-file infile
-@deffnx Procedure pprint-file infile outfile
+@deffn {Procedure} pprint-file infile
+@deffnx {Procedure} pprint-file infile outfile
Pretty-prints all the code in @var{infile}. If @var{outfile} is
specified, the output goes to @var{outfile}, otherwise it goes to
@code{(current-output-port)}.
@@ -4119,7 +4268,7 @@ thus can reduce loading time. The following will write into
(pprint-filter-file "code.scm" defmacro:expand* "exp-code.scm")
@end lisp
-@node Time and Date, Vector Graphics, Printing Scheme, Textual Conversion Packages
+@node Time and Date, NCBI-DNA, Printing Scheme, Textual Conversion Packages
@section Time and Date
@menu
@@ -4244,6 +4393,12 @@ made of any timezone at any calendar time.
@end defun
+@defun tz:std-offset tz
+@var{tz} is a time-zone object. @code{tz:std-offset} returns the
+number of seconds west of the Prime Meridian timezone @var{tz} is.
+
+@end defun
+
@noindent
The rest of these procedures and variables are provided for POSIX
compatability. Because of shared state they are not thread-safe.
@@ -4422,87 +4577,19 @@ match the arguments to @code{encode-universal-time}.
@end defun
-@node Vector Graphics, Schmooz, Time and Date, Textual Conversion Packages
-@section Vector Graphics
-
-@menu
-* Tektronix Graphics Support::
-@end menu
-
-@node Tektronix Graphics Support, , Vector Graphics, Vector Graphics
-@subsection Tektronix Graphics Support
-
-@emph{Note:} The Tektronix graphics support files need more work, and
-are not complete.
-
-@subsubsection Tektronix 4000 Series Graphics
-
-The Tektronix 4000 series graphics protocol gives the user a 1024 by
-1024 square drawing area. The origin is in the lower left corner of the
-screen. Increasing y is up and increasing x is to the right.
-
-The graphics control codes are sent over the current-output-port and can
-be mixed with regular text and ANSI or other terminal control sequences.
-
-@deffn Procedure tek40:init
-@end deffn
-
-@deffn Procedure tek40:graphics
-@end deffn
-
-@deffn Procedure tek40:text
-@end deffn
-
-@deffn Procedure tek40:linetype linetype
-@end deffn
-
-@deffn Procedure tek40:move x y
-@end deffn
-
-@deffn Procedure tek40:draw x y
-@end deffn
-
-@deffn Procedure tek40:put-text x y str
-@end deffn
-
-@deffn Procedure tek40:reset
-@end deffn
-
-
-@subsubsection Tektronix 4100 Series Graphics
-
-The graphics control codes are sent over the current-output-port and can
-be mixed with regular text and ANSI or other terminal control sequences.
-
-@deffn Procedure tek41:init
-@end deffn
-
-@deffn Procedure tek41:reset
-@end deffn
+@node NCBI-DNA, Schmooz, Time and Date, Textual Conversion Packages
+@section NCBI-DNA
-@deffn Procedure tek41:graphics
-@end deffn
-
-@deffn Procedure tek41:move x y
-@end deffn
+@include ncbi-dna.txi
-@deffn Procedure tek41:draw x y
-@end deffn
-
-@deffn Procedure tek41:point x y number
-@end deffn
-
-@deffn Procedure tek41:encode-x-y x y
-@end deffn
-@deffn Procedure tek41:encode-int number
-@end deffn
-
-@node Schmooz, , Vector Graphics, Textual Conversion Packages
+@node Schmooz, , NCBI-DNA, Textual Conversion Packages
@section Schmooz
@include schmooz.texi
+
+
@node Mathematical Packages, Database Packages, Textual Conversion Packages, Top
@chapter Mathematical Packages
@@ -4512,12 +4599,14 @@ be mixed with regular text and ANSI or other terminal control sequences.
* Prime Numbers:: 'factor
* Random Numbers:: 'random
* Fast Fourier Transform:: 'fft
-* Cyclic Checksum:: 'make-crc
-* Plotting:: 'charplot
+* Cyclic Checksum:: 'crc
+* Graphing::
+* Solid Modeling:: VRML97
+* Color::
* Root Finding:: 'root
* Minimizing:: 'minimize
* Commutative Rings:: 'commutative-ring
-* Determinant:: 'determinant
+* Matrix Algebra:: 'determinant
@end menu
@@ -4527,6 +4616,7 @@ be mixed with regular text and ANSI or other terminal control sequences.
@code{(require 'logical)}
@ftindex logical
+@noindent
The bit-twiddling functions are made available through the use of the
@code{logical} package. @code{logical} is loaded by inserting
@code{(require 'logical)} before the code that uses these
@@ -4534,7 +4624,7 @@ The bit-twiddling functions are made available through the use of the
functions. These functions behave as though operating on integers
in two's-complement representation.
-@subheading Bitwise Operations
+@subsection Bitwise Operations
@defun logand n1 n1
Returns the integer which is the bit-wise AND of the two integer
@@ -4615,7 +4705,7 @@ Example:
@end defun
-@subheading Bit Within Word
+@subsection Bit Within Word
@defun logbit? index j
@example
@@ -4641,17 +4731,17 @@ Example:
@end example
@end defun
-@subheading Fields of Bits
+@subsection Fields of Bits
+
+@defun logical:ones n
+Returns the smallest non-negative integer having @var{n} binary ones.
+@end defun
@defun bit-field n start end
-@findex bit-extract
Returns the integer composed of the @var{start} (inclusive) through
@var{end} (exclusive) bits of @var{n}. The @var{start}th bit becomes
the 0-th bit in the result.
-This function was called @code{bit-extract} in previous versions of SLIB.
-@refill
-
Example:
@lisp
(number->string (bit-field #b1101101010 0 4) 2)
@@ -4676,9 +4766,9 @@ Example:
@end example
@end defun
-@defun ash int count
+@defun ash n count
Returns an integer equivalent to
-@code{(inexact->exact (floor (* @var{int} (expt 2 @var{count}))))}.
+@code{(inexact->exact (floor (* @var{n} (expt 2 @var{count}))))}.
Example:
@lisp
@@ -4715,89 +4805,121 @@ Example:
@end lisp
@end defun
-@node Modular Arithmetic, Prime Numbers, Bit-Twiddling, Mathematical Packages
-@section Modular Arithmetic
+@subsection Bit order and Lamination
-@code{(require 'modular)}
-@ftindex modular
+@defun logical:rotate k count len
+Returns the low-order @var{len} bits of @var{k} cyclically permuted
+@var{count} bits towards high-order.
-@defun extended-euclid n1 n2
-Returns a list of 3 integers @code{(d x y)} such that d = gcd(@var{n1},
-@var{n2}) = @var{n1} * x + @var{n2} * y.
+Example:
+@lisp
+(number->string (logical:rotate #b0100 3 4) 2)
+@result{} "10"
+(number->string (logical:rotate #b0100 -1 4) 2)
+@result{} "10"
+@end lisp
@end defun
-@defun symmetric:modulus n
-Returns @code{(quotient (+ -1 n) -2)} for positive odd integer @var{n}.
+@defun bit-reverse k n
+Returns the low-order @var{k} bits of @var{n} with the bit order
+reversed. The low-order bit of @var{n} is the high order bit of the
+returned value.
+
+@example
+(number->string (bit-reverse 8 #xa7) 16)
+ @result{} "e5"
+@end example
@end defun
-@defun modulus->integer modulus
-Returns the non-negative integer characteristic of the ring formed when
-@var{modulus} is used with @code{modular:} procedures.
+@defun integer->list k len
+@defunx integer->list k
+@code{integer->list} returns a list of @var{len} booleans corresponding
+to each bit of the given integer. #t is coded for each 1; #f for 0.
+The @var{len} argument defaults to @code{(integer-length @var{k})}.
+
+@defunx list->integer list
+@code{list->integer} returns an integer formed from the booleans in the
+list @var{list}, which must be a list of booleans. A 1 bit is coded for
+each #t; a 0 bit for #f.
+
+@code{integer->list} and @code{list->integer} are inverses so far as
+@code{equal?} is concerned.
@end defun
-@defun modular:normalize modulus n
-Returns the integer @code{(modulo @var{n} (modulus->integer
-@var{modulus}))} in the representation specified by @var{modulus}.
+@defun booleans->integer bool1 @dots{}
+Returns the integer coded by the @var{bool1} @dots{} arguments.
@end defun
-@noindent
-The rest of these functions assume normalized arguments; That is, the
-arguments are constrained by the following table:
+@defun bitwise:laminate k1 @dots{}
+Returns an integer composed of the bits of @var{k1} @dots{} interlaced
+in argument order. Given @var{k1}, @dots{} @var{kn}, the n low-order
+bits of the returned value will be the lowest-order bit of each
+argument.
-@noindent
-For all of these functions, if the first argument (@var{modulus}) is:
-@table @code
-@item positive?
-Work as before. The result is between 0 and @var{modulus}.
+@defunx bitwise:delaminate count k
+Returns a list of @var{count} integers comprised of every @var{count}h
+bit of the integer @var{k}.
-@item zero?
-The arguments are treated as integers. An integer is returned.
+For any non-negative integers @var{k} and @var{count}:
+@example
+(eqv? k (bitwise:laminate (bitwise:delaminate count k)))
+@end example
+@end defun
-@item negative?
-The arguments and result are treated as members of the integers modulo
-@code{(+ 1 (* -2 @var{modulus}))}, but with @dfn{symmetric}
-representation; i.e. @code{(<= (- @var{modulus}) @var{n}
-@var{modulus})}.
-@end table
+@subsection Gray code
+
+@cindex Gray code
@noindent
-If all the arguments are fixnums the computation will use only fixnums.
+A @dfn{Gray code} is an ordering of non-negative integers in which
+exactly one bit differs between each pair of successive elements. There
+are multiple Gray codings. An n-bit Gray code corresponds to a
+Hamiltonian cycle on an n-dimensional hypercube.
-@defun modular:invertable? modulus k
-Returns @code{#t} if there exists an integer n such that @var{k} * n
-@equiv{} 1 mod @var{modulus}, and @code{#f} otherwise.
-@end defun
+@noindent
+Gray codes find use communicating incrementally changing values between
+asynchronous agents. De-laminated Gray codes comprise the coordinates
+of Peano-Hilbert space-filling curves.
-@defun modular:invert modulus k2
-Returns an integer n such that 1 = (n * @var{k2}) mod @var{modulus}. If
-@var{k2} has no inverse mod @var{modulus} an error is signaled.
-@end defun
-@defun modular:negate modulus k2
-Returns (@minus{}@var{k2}) mod @var{modulus}.
-@end defun
+@defun integer->gray-code k
+Converts @var{k} to a Gray code of the same @code{integer-length} as
+@var{k}.
-@defun modular:+ modulus k2 k3
-Returns (@var{k2} + @var{k3}) mod @var{modulus}.
-@end defun
+@defunx gray-code->integer k
+Converts the Gray code @var{k} to an integer of the same
+@code{integer-length} as @var{k}.
-@defun modular:@minus{} modulus k2 k3
-Returns (@var{k2} @minus{} @var{k3}) mod @var{modulus}.
+For any non-negative integer @var{k},
+@example
+(eqv? k (gray-code->integer (integer->gray-code k)))
+@end example
@end defun
-@defun modular:* modulus k2 k3
-Returns (@var{k2} * @var{k3}) mod @var{modulus}.
+@defun = k1 k2
+@defunx gray-code<? k1 k2
+@defunx gray-code>? k1 k2
+@defunx gray-code<=? k1 k2
+@defunx gray-code>=? k1 k2
+These procedures return #t if their Gray code arguments are
+(respectively): equal, monotonically increasing, monotonically
+decreasing, monotonically nondecreasing, or monotonically nonincreasing.
-The Scheme code for @code{modular:*} with negative @var{modulus} is not
-completed for fixnum-only implementations.
+For any non-negative integers @var{k1} and @var{k2}, the Gray code
+predicate of @code{(integer->gray-code k1)} and
+@code{(integer->gray-code k2)} will return the same value as the
+corresponding predicate of @var{k1} and @var{k2}.
@end defun
-@defun modular:expt modulus k2 k3
-Returns (@var{k2} ^ @var{k3}) mod @var{modulus}.
-@end defun
+@node Modular Arithmetic, Prime Numbers, Bit-Twiddling, Mathematical Packages
+@section Modular Arithmetic
+
+@include modular.txi
+
+
@node Prime Numbers, Random Numbers, Modular Arithmetic, Mathematical Packages
@section Prime Numbers
@@ -4811,9 +4933,6 @@ Returns (@var{k2} ^ @var{k3}) mod @var{modulus}.
@node Random Numbers, Fast Fourier Transform, Prime Numbers, Mathematical Packages
@section Random Numbers
-@code{(require 'random)}
-@ftindex random
-
@cindex RNG
@cindex PRNG
A pseudo-random number generator is only as good as the tests it passes.
@@ -4822,18 +4941,25 @@ tests named @dfn{DIEHARD} (@url{http://stat.fsu.edu/~geo/diehard.html}).
@file{diehard.c} has a bug which the patch
@url{http://swissnet.ai.mit.edu/ftpdir/users/jaffer/diehard.c.pat} corrects.
-SLIB's new PRNG generates 8 bits at a time. With the degenerate seed
-@samp{0}, the numbers generated pass DIEHARD; but when bits are combined
-from sequential bytes, tests fail. With the seed
-@samp{http://swissnet.ai.mit.edu/~jaffer/SLIB.html}, all of those tests
-pass.
+SLIB's PRNG generates 8 bits at a time. With the degenerate seed
+@samp{0}, the numbers generated pass DIEHARD; but when bits are
+combined from sequential bytes, tests fail. With the seed
+@samp{http://swissnet.ai.mit.edu/~jaffer/SLIB.html}, all of those
+tests pass.
+
+@menu
+* Exact Random Numbers:: 'random
+* Inexact Random Numbers:: 'random-inexact
+@end menu
+
+@node Exact Random Numbers, Inexact Random Numbers, Random Numbers, Random Numbers
+@subsection Exact Random Numbers
@include random.txi
-If inexact numbers are supported by the Scheme implementation,
-@file{randinex.scm} will be loaded as well. @file{randinex.scm}
-contains procedures for generating inexact distributions.
+@node Inexact Random Numbers, , Exact Random Numbers, Random Numbers
+@subsection Inexact Random Numbers
@include randinex.txi
@@ -4841,172 +4967,1076 @@ contains procedures for generating inexact distributions.
@node Fast Fourier Transform, Cyclic Checksum, Random Numbers, Mathematical Packages
@section Fast Fourier Transform
-@code{(require 'fft)}
-@ftindex fft
+@include fft.txi
-@defun fft array
-@var{array} is an array of @code{(expt 2 n)} numbers. @code{fft}
-returns an array of complex numbers comprising the @dfn{Discrete Fourier
-Transform} of @var{array}.
-@defunx fft-1 array
-@code{fft-1} returns an array of complex numbers comprising the inverse
-Discrete Fourier Transform of @var{array}.
-@end defun
+@node Cyclic Checksum, Graphing, Fast Fourier Transform, Mathematical Packages
+@section Cyclic Checksum
-@code{(fft-1 (fft @var{array}))} will return an array of values close to
-@var{array}.
+@code{(require 'crc)}
+@ftindex crc
+@noindent
+Cyclic Redundancy Checks using Galois field GF(2) polynomial
+arithmetic are used for error detection in many data transmission
+and storage applications.
-@example
-(fft '#(1 0+i -1 0-i 1 0+i -1 0-i)) @result{}
+@noindent
+The generator polynomials for various CRC protocols are availble
+from many sources. But the polynomial is just one of many
+parameters which must match in order for a CRC implementation to
+interoperate with existing systems:
+
+@itemize @bullet
-#(0.0 0.0 0.0+628.0783185208527e-18i 0.0
- 0.0 0.0 8.0-628.0783185208527e-18i 0.0)
+@item
+the byte-order and bit-order of the data stream;
-(fft-1 '#(0 0 0 0 0 0 8 0)) @result{}
+@item
+whether the CRC or its inverse is being calculated;
-#(1.0 -61.23031769111886e-18+1.0i -1.0 61.23031769111886e-18-1.0i
- 1.0 -61.23031769111886e-18+1.0i -1.0 61.23031769111886e-18-1.0i)
-@end example
+@item
+the initial CRC value; and
+@item
+whether and where the CRC value is appended (inverted
+or non-inverted) to the data stream.
-@node Cyclic Checksum, Plotting, Fast Fourier Transform, Mathematical Packages
-@section Cyclic Checksum
+@end itemize
+
+@noindent
+There is even some controversy over the polynomials themselves.
+
+@defvr Constant crc-32-polynomial
+For CRC-32, http://www2.sis.pitt.edu/~jkabara/tele-2100/lect08.html
+gives x^32+x^26+x^23+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x^1+1.
+
+But
+http://www.cs.ncl.ac.uk/people/harry.whitfield/home.formal/CRCs.html,
+http://duchon.umuc.edu/Web_Pages/duchon/99_f_cm435/ShiftRegister.htm,
+http://spinroot.com/spin/Doc/Book91_PDF/ch3.pdf,
+http://www.erg.abdn.ac.uk/users/gorry/course/dl-pages/crc.html,
+http://www.rad.com/networks/1994/err_con/crc_most.htm, and
+http://www.gpfn.sk.ca/~rhg/csc8550s02/crc.html,
+http://www.nobugconsulting.ro/crc.php give
+x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
+
+SLIB @code{crc-32-polynomial} uses the latter definition.
+@end defvr
+
+@defvr Constant crc-ccitt-polynomial
+
+http://www.math.grin.edu/~rebelsky/Courses/CS364/2000S/Outlines/outline.12.html,
+http://duchon.umuc.edu/Web_Pages/duchon/99_f_cm435/ShiftRegister.htm,
+http://www.cs.ncl.ac.uk/people/harry.whitfield/home.formal/CRCs.html,
+http://www2.sis.pitt.edu/~jkabara/tele-2100/lect08.html, and
+http://www.gpfn.sk.ca/~rhg/csc8550s02/crc.html give
+CRC-CCITT: x^16+x^12+x^5+1.
+@end defvr
+
+@defvr Constant crc-16-polynomial
+
+http://www.math.grin.edu/~rebelsky/Courses/CS364/2000S/Outlines/outline.12.html,
+http://duchon.umuc.edu/Web_Pages/duchon/99_f_cm435/ShiftRegister.htm,
+http://www.cs.ncl.ac.uk/people/harry.whitfield/home.formal/CRCs.html,
+http://www.gpfn.sk.ca/~rhg/csc8550s02/crc.html, and
+http://www.usb.org/developers/data/crcdes.pdf give
+CRC-16: x^16+x^15+x^2+1.
+@end defvr
+
+@defvr Constant crc-12-polynomial
+
+http://www.math.grin.edu/~rebelsky/Courses/CS364/2000S/Outlines/outline.12.html,
+http://www.cs.ncl.ac.uk/people/harry.whitfield/home.formal/CRCs.html,
+http://www.it.iitb.ac.in/it605/lectures/link/node4.html, and
+http://spinroot.com/spin/Doc/Book91_PDF/ch3.pdf give
+CRC-12: x^12+x^11+x^3+x^2+1.
+
+But
+http://www.ffldusoe.edu/Faculty/Denenberg/Topics/Networks/Error_Detection_Correction/crc.html,
+http://duchon.umuc.edu/Web_Pages/duchon/99_f_cm435/ShiftRegister.htm,
+http://www.eng.uwi.tt/depts/elec/staff/kimal/errorcc.html,
+http://www.ee.uwa.edu.au/~roberto/teach/itc314/java/CRC/,
+http://www.gpfn.sk.ca/~rhg/csc8550s02/crc.html, and
+http://www.efg2.com/Lab/Mathematics/CRC.htm give
+CRC-12: x^12+x^11+x^3+x^2+x+1.
+
+These differ in bit 1 and calculations using them return different
+values. With citations near evenly split, it is hard to know which is
+correct.
+@end defvr
-@code{(require 'make-crc)}
-@ftindex make-crc
+@defvr Constant crc-10-polynomial
+
+http://www.math.grin.edu/~rebelsky/Courses/CS364/2000S/Outlines/outline.12.html gives
+CRC-10: x^10+x^9+x^5+x^4+1;
+but
+http://cell-relay.indiana.edu/cell-relay/publications/software/CRC/crc10.html,
+http://www.it.iitb.ac.in/it605/lectures/link/node4.html,
+http://www.gpfn.sk.ca/~rhg/csc8550s02/crc.html,
+http://www.techfest.com/networking/atm/atm.htm,
+http://www.protocols.com/pbook/atmcell2.htm, and
+http://www.nobugconsulting.ro/crc.php give
+CRC-10: x^10+x^9+x^5+x^4+x+1.
+@end defvr
+
+@defvr Constant crc-08-polynomial
+
+http://www.math.grin.edu/~rebelsky/Courses/CS364/2000S/Outlines/outline.12.html,
+http://www.cs.ncl.ac.uk/people/harry.whitfield/home.formal/CRCs.html,
+http://www.it.iitb.ac.in/it605/lectures/link/node4.html, and
+http://www.nobugconsulting.ro/crc.php give
+CRC-8: x^8+x^2+x^1+1
+@end defvr
-@defun make-port-crc
-@defunx make-port-crc degree
-Returns an expression for a procedure of one argument, a port. This
-procedure reads characters from the port until the end of file and
-returns the integer checksum of the bytes read.
+@defvr Constant atm-hec-polynomial
-The integer @var{degree}, if given, specifies the degree of the
-polynomial being computed -- which is also the number of bits computed
-in the checksums. The default value is 32.
+http://cell-relay.indiana.edu/cell-relay/publications/software/CRC/32bitCRC.tutorial.html and
+http://www.gpfn.sk.ca/~rhg/csc8550s02/crc.html give
+ATM HEC: x^8+x^2+x+1.
+@end defvr
-@defunx make-port-crc generator
+@defvr Constant dowcrc-polynomial
-The integer @var{generator} specifies the polynomial being computed.
-The power of 2 generating each 1 bit is the exponent of a term of the
-polynomial. The value of @var{generator} must be larger than 127.
+http://www.cs.ncl.ac.uk/people/harry.whitfield/home.formal/CRCs.html gives
+DOWCRC: x^8+x^5+x^4+1.
+@end defvr
+
+@defvr Constant usb-token-polynomial
+
+http://www.usb.org/developers/data/crcdes.pdf and
+http://www.nobugconsulting.ro/crc.php give
+USB-token: x^5+x^2+1.
+@end defvr
+
+@noindent
+Each of these polynomial constants is a string of @samp{1}s and
+@samp{0}s, the exponent of each power of @var{x} in descending order.
-@defunx make-port-crc degree generator
+@defun crc:make-table poly
-The integer @var{generator} specifies the polynomial being computed.
-The power of 2 generating each 1 bit is the exponent of a term of the
-polynomial. The bit at position @var{degree} is implicit and should not
-be part of @var{generator}. This allows systems with numbers limited to
-32 bits to calculate 32 bit checksums. The default value of
-@var{generator} when @var{degree} is 32 (its default) is:
+@var{poly} must be string of @samp{1}s and @samp{0}s beginning with
+@samp{1} and having length greater than 8. @code{crc:make-table}
+returns a vector of 256 integers, such that:
@example
-(make-port-crc 32 #b00000100110000010001110110110111)
+(set! @var{crc}
+ (logxor (ash (logand (+ -1 (ash 1 (- @var{deg} 8))) @var{crc}) 8)
+ (vector-ref @var{crc-table}
+ (logxor (ash @var{crc} (- 8 @var{deg})) @var{byte}))))
@end example
-Creates a procedure to calculate the P1003.2/D11.2 (POSIX.2) 32-bit
-checksum from the polynomial:
+will compute the @var{crc} with the 8 additional bits in @var{byte};
+where @var{crc} is the previous accumulated CRC value, @var{deg} is
+the degree of @var{poly}, and @var{crc-table} is the vector returned
+by @code{crc:make-table}.
-@example
- 32 26 23 22 16 12 11
- ( x + x + x + x + x + x + x +
+If the implementation does not support @var{deg}-bit integers, then
+@code{crc:make-table} returns #f.
- 10 8 7 5 4 2 1
- x + x + x + x + x + x + x + 1 ) mod 2
-@end example
@end defun
-@example
-(require 'make-crc)
-@ftindex make-crc
-(define crc32 (slib:eval (make-port-crc)))
-(define (file-check-sum file) (call-with-input-file file crc32))
-(file-check-sum (in-vicinity (library-vicinity) "ratize.scm"))
+@defun cksum file
+
+Computes the P1003.2/D11.2 (POSIX.2) 32-bit checksum of @var{file}.
+
+@example
+(require 'crc)
+@ftindex crc
+(cksum (in-vicinity (library-vicinity) "ratize.scm"))
@result{} 157103930
@end example
-@node Plotting, Root Finding, Cyclic Checksum, Mathematical Packages
-@section Plotting on Character Devices
+@defunx cksum port
+Computes the checksum of the bytes read from @var{port} until the
+end-of-file.
-@code{(require 'charplot)}
-@ftindex charplot
+@end defun
+
+@noindent
+@cindex cksum-string
+@code{cksum-string}, which returns the P1003.2/D11.2 (POSIX.2) 32-bit
+checksum of the bytes in @var{str}, can be defined as follows:
+
+@example
+(require 'string-port)
+(define (cksum-string str) (call-with-input-string str cksum))
+@end example
+
+@defun crc16 file
+
+Computes the USB data-packet (16-bit) CRC of @var{file}.
+
+@defunx crc16 port
+Computes the USB data-packet (16-bit) CRC of the bytes read from
+@var{port} until the end-of-file.
+
+@code{crc16} calculates the same values as the crc16.pl program given
+in http://www.usb.org/developers/data/crcdes.pdf.
+
+@end defun
+
+@defun crc5 file
+
+Computes the USB token (5-bit) CRC of @var{file}.
+
+@defunx crc5 port
+Computes the USB token (5-bit) CRC of the bytes read from
+@var{port} until the end-of-file.
+
+@code{crc5} calculates the same values as the crc5.pl program given
+in http://www.usb.org/developers/data/crcdes.pdf.
+
+@end defun
+
+@node Graphing, Solid Modeling, Cyclic Checksum, Mathematical Packages
+@section Graphing
+
+@menu
+* Character Plotting::
+* PostScript Graphing::
+@end menu
+
+@node Character Plotting, PostScript Graphing, Graphing, Graphing
+@subsection Character Plotting
-The plotting procedure is made available through the use of the
-@code{charplot} package. @code{charplot} is loaded by inserting
-@code{(require 'charplot)} before the code that uses this procedure.
+@code{(require 'charplot)}
@ftindex charplot
-@defvar charplot:height
-The number of rows to make the plot vertically.
-@end defvar
+@defvar charplot:dimensions
+A list of the maximum height (number of lines) and maximum width (number
+of columns) for the graph, its scales, and labels.
-@defvar charplot:width
-The number of columns to make the plot horizontally.
+The default value for @var{charplot:dimensions} is the
+@code{output-port-height} and @code{output-port-width} of
+@code{current-output-port}.
@end defvar
-@deffn Procedure plot! coords x-label y-label
-@var{coords} is a list of pairs of x and y coordinates. @var{x-label}
-and @var{y-label} are strings with which to label the x and y
-axes.
+@deffn {Procedure} plot coords x-label y-label
+@var{coords} is a list or vector of coordinates, lists of x and y
+coordinates. @var{x-label} and @var{y-label} are strings with which to
+label the x and y axes.
Example:
@example
(require 'charplot)
@ftindex charplot
-(set! charplot:height 19)
-(set! charplot:width 45)
+(set! charplot:dimensions '(20 55))
(define (make-points n)
(if (zero? n)
'()
- (cons (cons (/ n 6) (sin (/ n 6))) (make-points (1- n)))))
+ (cons (list (/ n 6) (sin (/ n 6))) (make-points (1- n)))))
-(plot! (make-points 37) "x" "Sin(x)")
+(plot (make-points 40) "x" "Sin(x)")
@print{}
@group
- Sin(x) ______________________________________________
- 1.25|- |
- | |
- 1|- **** |
- | ** ** |
- 0.75|- * * |
- | * * |
- 0.5|- * * |
- | * |
- 0.25|- * |
- | * * |
- 0|-------------------*--------------------------|
- | * |
- -0.25|- * * |
- | * * |
- -0.5|- * |
- | * * |
- -0.75|- * * |
- | ** ** |
- -1|- **** |
- |____________:_____._____:_____._____:_________|
- x 2 4 6
+ Sin(x) _________________________________________
+ 1|- **** |
+ | ** ** |
+ 0.75|- * * |
+ | * * |
+ 0.5|- * * |
+ | * *|
+ 0.25|- * * |
+ | * * |
+ 0|-------------------*------------------*--|
+ | * |
+ -0.25|- * * |
+ | * * |
+ -0.5|- * |
+ | * * |
+ -0.75|- * * |
+ | ** ** |
+ -1|- **** |
+ |:_____._____:_____._____:_____._____:____|
+ x 2 4 6
@end group
@end example
@end deffn
-@deffn Procedure plot-function! func x1 x2
-@deffnx Procedure plot-function! func x1 x2 npts
+@deffn {Procedure} plot func x1 x2
+@deffnx {Procedure} plot func x1 x2 npts
Plots the function of one argument @var{func} over the range @var{x1} to
@var{x2}. If the optional integer argument @var{npts} is supplied, it
specifies the number of points to evaluate @var{func} at.
+
+@example
+(plot sin 0 (* 2 pi))
+@print{}
+@group
+ _________________________________________
+ 1|-: **** |
+ | : ** ** |
+ 0.75|-: * * |
+ | : * * |
+ 0.5|-: ** ** |
+ | : * * |
+ 0.25|-:** ** |
+ | :* * |
+ 0|-*------------------*--------------------|
+ | : * * |
+ -0.25|-: ** ** |
+ | : * * |
+ -0.5|-: * ** |
+ | : * * |
+ -0.75|-: * ** |
+ | : ** ** |
+ -1|-: **** |
+ |_:_____._____:_____._____:_____._____:___|
+ 0 2 4 6
+@end group
+@end example
@end deffn
+@deffn {Procedure} histograph data label
+Creates and displays a histogram of the numerical values contained in
+vector or list @var{data}
+
+@example
+(require 'random-inexact)
+(histograph (do ((idx 99 (+ -1 idx))
+ (lst '() (cons (* .02 (random:normal)) lst)))
+ ((negative? idx) lst))
+ "normal")
+@print{}
+@group
+ _________________________________________
+ 8|- : I |
+ | : I |
+ 7|- I I : I |
+ | I I : I |
+ 6|- III I :I I |
+ | III I :I I |
+ 5|- IIIIIIIIII I |
+ | IIIIIIIIII I |
+ 4|- IIIIIIIIIIII |
+ | IIIIIIIIIIII |
+ 3|-I I I IIIIIIIIIIII II I |
+ | I I I IIIIIIIIIIII II I |
+ 2|-I I I IIIIIIIIIIIIIIIII I |
+ | I I I IIIIIIIIIIIIIIIII I |
+ 1|-II I I IIIIIIIIIIIIIIIIIIIII I I I |
+ | II I I IIIIIIIIIIIIIIIIIIIII I I I |
+ 0|-IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII----|
+ |__.____:____.____:____.____:____.____:___|
+ normal -0.025 0 0.025 0.05
+@end group
+@end example
+@end deffn
+
+
+@node PostScript Graphing, , Character Plotting, Graphing
+@subsection PostScript Graphing
+
+@include grapheps.txi
+
+
+@node Solid Modeling, Color, Graphing, Mathematical Packages
+@section Solid Modeling
+
+@include solid.txi
+
+
+@node Color, Root Finding, Solid Modeling, Mathematical Packages
+@section Color
+
+@ifset html
+<A NAME="Color"></A>
+@end ifset
+
+@uref{http://swissnet.ai.mit.edu/~jaffer/Color}
+
+@noindent
+The goals of this package are to provide methods to specify, compute,
+and transform colors in a core set of additive color spaces. The color
+spaces supported should be sufficient for working with the color data
+encountered in practice and the literature.
+
+@menu
+* Color Data-Type:: 'color
+* Color Spaces:: XYZ, L*a*b*, L*u*v*, L*C*h, RGB709, sRGB
+* Spectra:: Color Temperatures and CIEXYZ(1931)
+* Color Difference Metrics:: Society of Dyers and Colorists
+* Color Conversions:: Low-level
+* Color Names:: in relational databases
+* Daylight:: Sunlight and sky colors
+@end menu
+
+@node Color Data-Type, Color Spaces, Color, Color
+@subsection Color Data-Type
+
+@ifset html
+<A NAME="Color_Data-Type"></A>
+@end ifset
+@code{(require 'color)}
+
+@defun color? obj
+Returns #t if @var{obj} is a color.
+
+@defunx color? obj typ
+Returns #t if @var{obj} is a color of color-space @var{typ}. The symbol
+@var{typ} must be one of:
+
+@itemize @bullet
+@item
+CIEXYZ
+@item
+RGB709
+@item
+L*a*b*
+@item
+L*u*v*
+@item
+sRGB
+@item
+e-sRGB
+@item
+L*C*h
+@end itemize
+@end defun
+
+@defun make-color space arg @dots{}
+Returns a color of type @var{space}.
+@end defun
+
+@defun color-space color
+Returns the symbol for the color-space in which @var{color} is embedded.
+@end defun
+
+@defun color-precision color
+For colors in digital color-spaces, @code{color-precision} returns the
+number of bits used for each of the R, G, and B channels of the
+encoding. Otherwise, @code{color-precision} returns #f
+@end defun
+
+@defun color-white-point color
+Returns the white-point of @var{color} in all color-spaces except CIEXYZ.
+@end defun
+
+@defun convert-color color space white-point
+@defunx convert-color color space
+@defunx convert-color color e-sRGB precision
+Converts @var{color} into @var{space} at optional @var{white-point}.
+@end defun
+
+@subsubsection External Representation
+
+@noindent
+Each color encoding has an external, case-insensitive representation.
+To ensure portability, the white-point for all color strings is D65.
+@footnote{Readers may recognize these color string formats from Xlib.
+X11's color management system was doomed by its fiction that CRT
+monitors' (and X11 default) color-spaces were linear RGBi. Unable to
+shed this legacy, the only practical way to view pictures on X is to
+ignore its color management system and use an sRGB monitor. In this
+implementation the device-independent RGB709 and sRGB spaces replace the
+device-dependent RGBi and RGB spaces of Xlib.}
+
+@multitable @columnfractions .33 .66
+@item Color Space
+@tab External Representation
+@item CIEXYZ
+@tab CIEXYZ:@i{<X>}/@i{<Y>}/@i{<Z>}
+@item RGB709
+@tab RGBi:@i{<R>}/@i{<G>}/@i{<B>}
+@item L*a*b*
+@tab CIELAB:@i{<L>}/@i{<a>}/@i{<b>}
+@item L*u*v*
+@tab CIELuv:@i{<L>}/@i{<u>}/@i{<v>}
+@item L*C*h
+@tab CIELCh:@i{<L>}/@i{<C>}/@i{<h>}
+@end multitable
+
+@noindent
+The @var{X}, @var{Y}, @var{Z}, @var{L}, @var{a}, @var{b}, @var{u},
+@var{v}, @var{C}, @var{h}, @var{R}, @var{G}, and @var{B} fields are
+(Scheme) real numbers within the appropriate ranges.
+
+@multitable @columnfractions .33 .66
+@item Color Space
+@tab External Representation
+@item sRGB
+@tab sRGB:@i{<R>}/@i{<G>}/@i{<B>}
+@item e-sRGB10
+@tab e-sRGB10:@i{<R>}/@i{<G>}/@i{<B>}
+@item e-sRGB12
+@tab e-sRGB12:@i{<R>}/@i{<G>}/@i{<B>}
+@item e-sRGB16
+@tab e-sRGB16:@i{<R>}/@i{<G>}/@i{<B>}
+@end multitable
+
+@noindent
+The @var{R}, @var{G}, and @var{B}, fields are non-negative exact decimal
+integers within the appropriate ranges.
+
+@noindent
+Several additional syntaxes are supported by @code{string->color}:
+
+@multitable @columnfractions .33 .66
+@item Color Space
+@tab External Representation
+@item sRGB
+@tab sRGB:@i{<RRGGBB>}
+@item sRGB
+@tab #@i{<RRGGBB>}
+@item sRGB
+@tab 0x@i{<RRGGBB>}
+@item sRGB
+@tab #x@i{<RRGGBB>}
+@end multitable
+
+Where @var{RRGGBB} is a non-negative six-digit hexadecimal number.
+
+@defun color->string color
+Returns a string representation of @var{color}.
+@end defun
+
+@defun string->color string
+Returns the color represented by @var{string}. If @var{string} is not a
+syntactically valid notation for a color, then @code{string->color}
+returns #f.
+@end defun
+
+@subsubsection White
+
+@noindent
+We experience color relative to the illumination around us.
+CIEXYZ coordinates, although subject to uniform scaling, are
+objective. Thus other color spaces are specified relative to a
+@cindex white point
+@dfn{white point} in CIEXYZ coordinates.
+@cindex white point
+
+@noindent
+The white point for digital color spaces is set to D65. For the other
+spaces a @var{white-point} argument can be specified. The default if
+none is specified is the white-point with which the color was created
+or last converted; and D65 if none has been specified.
+
+@defvr Constant D65
+Is the color of 6500.K (blackbody) illumination. D65 is close
+to the average color of daylight.
+@end defvr
+
+@defvr Constant D50
+Is the color of 5000.K (blackbody) illumination. D50 is the color of
+indoor lighting by incandescent bulbs, whose filaments have
+temperatures around 5000.K.
+@end defvr
+
+
+@node Color Spaces, Spectra, Color Data-Type, Color
+@subsection Color Spaces
+
+@ifset html
+<A NAME="Color_Spaces"></A>
+@end ifset
+@include color.txi
+
+
+
+@node Spectra, Color Difference Metrics, Color Spaces, Color
+@subsection Spectra
+
+@ifset html
+<A NAME="Spectra"></A>
+@end ifset
+@noindent
+The following functions compute colors from spectra, scale color
+luminance, and extract chromaticity. XYZ is used in the names of
+procedures for unnormalized colors; the coordinates of CIEXYZ colors are
+constrained as described in @ref{Color Spaces}.
+
+@code{(require 'color-space)}
+
+@noindent
+A spectrum may be represented as:
+
+@itemize @bullet
+@item
+A procedure of one argument accepting real numbers from 380e-9 to
+780e-9, the wavelength in meters; or
+@item
+A vector of real numbers representing intensity samples evenly spaced
+over some range of wavelengths overlapping the range 380e-9 to 780e-9.
+@end itemize
+
+@noindent
+CIEXYZ values are calculated as dot-product with the X, Y (Luminance),
+and Z @dfn{Spectral Tristimulus Values}. The files @file{cie1931.xyz}
+and @file{cie1964.xyz} in the distribution contain these CIE-defined
+values.
+@cindex Spectral Tristimulus Values
+
+@deftp {Feature} cie1964
+@ftindex cie1964
+Loads the Spectral Tristimulus Values defining @cite{CIE 1964
+Supplementary Standard Colorimetric Observer}.
+@deftpx {Feature} cie1931
+@ftindex cie1931
+Loads the Spectral Tristimulus Values defining @cite{CIE 1931
+Supplementary Standard Colorimetric Observer}.
+@deftpx {Feature} ciexyz
+@ftindex ciexyz
+Requires Spectral Tristimulus Values, defaulting to cie1931.
+@end deftp
+
+@noindent
+@code{(require 'cie1964)} or @code{(require 'cie1931)} will
+@findex load-ciexyz
+@code{load-ciexyz} specific values used by the following spectrum
+conversion procedures. The spectrum conversion procedures
+@code{(require 'ciexyz)} to assure that a set is loaded.
+
+@defun spectrum->XYZ proc
+@var{proc} must be a function of one argument. @code{spectrum->XYZ}
+computes the CIEXYZ(1931) values for the spectrum returned by @var{proc}
+when called with arguments from 380e-9 to 780e-9, the wavelength in
+meters.
+
+@defunx spectrum->XYZ spectrum x1 x2
+@var{x1} and @var{x2} must be positive real numbers specifying the
+wavelengths (in meters) corresponding to the zeroth and last elements of
+vector or list @var{spectrum}. @code{spectrum->XYZ} returns the
+CIEXYZ(1931) values for a light source with spectral values proportional
+to the elements of @var{spectrum} at evenly spaced wavelengths between
+@var{x1} and @var{x2}.
+
+Compute the colors of 6500.K and 5000.K blackbody radiation:
+
+@example
+(require 'color-space)
+(define xyz (spectrum->XYZ (blackbody-spectrum 6500)))
+(define y_n (cadr xyz))
+(map (lambda (x) (/ x y_n)) xyz)
+ @result{} (0.9687111145512467 1.0 1.1210875945303613)
+
+(define xyz (spectrum->XYZ (blackbody-spectrum 5000)))
+(map (lambda (x) (/ x y_n)) xyz)
+ @result{} (0.2933441826889158 0.2988931825387761 0.25783646831201573)
+@end example
+
+@defunx spectrum->CIEXYZ proc
+@defunx spectrum->CIEXYZ spectrum x1 x2
+@code{spectrum->CIEXYZ} computes the CIEXYZ(1931) values for the
+spectrum, scaled so their sum is 1.
+@end defun
+
+@defun spectrum->chromaticity proc
+@defunx spectrum->chromaticity spectrum x1 x2
+Computes the chromaticity for the given spectrum.
+@end defun
+
+@defun wavelength->XYZ w
+@defunx wavelength->chromaticity w
+@defunx wavelength->CIEXYZ w
+@var{w} must be a number between 380e-9 to 780e-9.
+@code{wavelength->XYZ} returns (unnormalized) XYZ values for a
+monochromatic light source with wavelength @var{w}.
+@code{wavelength->chromaticity} returns the chromaticity for a
+monochromatic light source with wavelength @var{w}.
+@code{wavelength->CIEXYZ} returns XYZ values for the saturated color
+having chromaticity of a monochromatic light source with wavelength
+@var{w}.
+@end defun
+
+@defun blackbody-spectrum temp
+@defunx blackbody-spectrum temp span
+Returns a procedure of one argument (wavelength in meters), which
+returns the radiance of a black body at @var{temp}.
+
+The optional argument @var{span} is the wavelength analog of bandwidth.
+With the default @var{span} of 1.nm (1e-9.m), the values returned by the
+procedure correspond to the power of the photons with wavelengths
+@var{w} to @var{w}+1e-9.
+@end defun
+
+@defun temperature->XYZ x
+The positive number @var{x} is a temperature in degrees kelvin.
+@code{temperature->XYZ} computes the CIEXYZ(1931) values for the
+spectrum of a black body at temperature @var{x}.
+
+Compute the chromaticities of 6500.K and 5000.K blackbody radiation:
+
+@example
+(require 'color-space)
+(XYZ->chromaticity (temperature->XYZ 6500))
+ @result{} (0.3135191660557008 0.3236456786200268)
+
+(XYZ->chromaticity (temperature->XYZ 5000))
+ @result{} (0.34508082841161052 0.3516084965163377)
+@end example
+@end defun
+
+@defun temperature->CIEXYZ x
+The positive number @var{x} is a temperature in degrees kelvin.
+@code{temperature->CIEXYZ} computes the CIEXYZ(1931) values for the
+spectrum of a black body at temperature @var{x}, scaled to be just
+inside the RGB709 gamut.
+@end defun
+
+@defun temperature->chromaticity x
+@end defun
+
+@defun XYZ:normalize xyz
+@var{xyz} is a list of three non-negative real numbers.
+@code{XYZ:normalize} returns a list of numbers proportional to
+@var{xyz}; scaled so their sum is 1.
+@end defun
+
+@defun XYZ:normalize-colors colors @dots{}
+@var{colors} is a list of XYZ triples. @code{XYZ:normalize-colors}
+scales all the triples by a common factor such that the maximum sum of
+numbers in a scaled triple is 1.
+@end defun
+
+@defun XYZ->chromaticity xyz
+Returns a two element list: the x and y components of @var{xyz}
+normalized to 1 (= @var{x} + @var{y} + @var{z}).
+@end defun
+
+@defun chromaticity->CIEXYZ x y
+Returns the list of @var{x}, and @var{y}, 1 - @var{y} - @var{x}.
+@end defun
+
+@defun chromaticity->whitepoint x y
+Returns the CIEXYZ(1931) values having luminosity 1 and chromaticity
+@var{x} and @var{y}.
+@end defun
+
+@cindex xyY
+@noindent
+Many color datasets are expressed in @dfn{xyY} format; chromaticity with
+CIE luminance (Y). But xyY is not a CIE standard like CIEXYZ, CIELAB,
+and CIELUV. Although chrominance is well defined, the luminance
+component is sometimes scaled to 1, sometimes to 100, but usually has no
+obvious range. With no given whitepoint, the only reasonable course is
+to ascertain the luminance range of a dataset and normalize the values
+to lie from 0 to 1.
+
+@defun XYZ->xyY xyz
+Returns a three element list: the @var{x} and @var{y} components of
+@var{XYZ} normalized to 1, and CIE luminance @var{Y}.
+@end defun
+
+@defun xyY->XYZ xyY
+@end defun
+
+@defun xyY:normalize-colors colors
+@var{colors} is a list of xyY triples. @code{xyY:normalize-colors}
+scales each chromaticity so it sums to 1 or less; and divides the
+@var{Y} values by the maximum @var{Y} in the dataset, so all lie between
+0 and 1.
+
+@defunx xyY:normalize-colors colors n
+If @var{n} is positive real, then @code{xyY:normalize-colors} divides
+the @var{Y} values by @var{n} times the maximum @var{Y} in the dataset.
+
+If @var{n} is an exact non-positive integer, then
+@code{xyY:normalize-colors} divides the @var{Y} values by the maximum of
+the @var{Y}s in the dataset excepting the -@var{n} largest @var{Y}
+values.
+
+In all cases, returned @var{Y} values are limited to lie from 0 to 1.
+@end defun
+
+@noindent
+Why would one want to normalize to other than 1? If the sun or its
+reflection is the brightest object in a scene, then normalizing to its
+luminance will tend to make the rest of the scene very dark. As with
+photographs, limiting the specular highlights looks better than
+darkening everything else.
+
+@noindent
+The results of measurements being what they are,
+@code{xyY:normalize-colors} is extremely tolerant. Negative numbers are
+replaced with zero, and chromaticities with sums greater than one are
+scaled to sum to one.
+
+
+@node Color Difference Metrics, Color Conversions, Spectra, Color
+@subsection Color Difference Metrics
+
+@ifset html
+<A NAME="Color_Difference_Metrics"></A>
+@end ifset
+
+@code{(require 'color-space)}
+
+The low-level metric functions operate on lists of 3 numbers, lab1,
+lab2, lch1, or lch2.
+
+@code{(require 'color)}
+
+The wrapped functions operate on objects of type color, color1 and
+color2 in the function entries.
+
+@defun L*a*b*:DE* lab1 lab2
+Returns the Euclidean distance between @var{lab1} and @var{lab2}.
+
+@defunx CIE:DE* color1 color2 white-point
+@defunx CIE:DE* color1 color2
+Returns the Euclidean distance in L*a*b* space between @var{color1} and
+@var{color2}.
+@end defun
+
+
+@defun L*C*h:DE*94 lch1 lch2 parametric-factors
+@defunx L*C*h:DE*94 lch1 lch2
+
+@defunx CIE:DE*94 color1 color2 parametric-factors
+@defunx CIE:DE*94 color1 color2
+
+Measures distance in the L*C*h cylindrical color-space.
+The three axes are individually scaled (depending on C*) in their
+contributions to the total distance.
+
+The CIE has defined reference conditions under which the metric with
+default parameters can be expected to perform well. These are:
+
+@itemize @bullet
+@item
+The specimens are homogeneous in colour.
+@item
+The colour difference (CIELAB) is <= 5 units.
+@item
+They are placed in direct edge contact.
+@item
+Each specimen subtends an angle of >4 degrees to the assessor, whose
+colour vision is normal.
+@item
+They are illuminated at 1000 lux, and viewed against a background of
+uniform grey, with L* of 50, under illumination simulating D65.
+@end itemize
+
+The @var{parametric-factors} argument is a list of 3 quantities kL, kC
+and kH. @var{parametric-factors} independently adjust each
+colour-difference term to account for any deviations from the reference
+viewing conditions. Under the reference conditions explained above, the
+default is kL = kC = kH = 1.
+@end defun
+
+
+@noindent
+The Color Measurement Committee of The Society of Dyers and Colorists in
+Great Britain created a more sophisticated color-distance function for
+use in judging the consistency of dye lots. With CMC:DE* it is possible
+to use a single value pass/fail tolerance for all shades.
+
+@defun CMC-DE lch1 lch2 parametric-factors
+@defunx CMC-DE lch1 lch2 l c
+@defunx CMC-DE lch1 lch2 l
+@defunx CMC-DE lch1 lch2
+
+@defunx CMC:DE* color1 color2 l c
+@defunx CMC:DE* color1 color2
+
+@code{CMC:DE} is a L*C*h metric. The @var{parametric-factors}
+argument is a list of 2 numbers @var{l} and @var{c}. @var{l} and
+@var{c} parameterize this metric. 1 and 1 are recommended for
+perceptibility; the default, 2 and 1, for acceptability.
+@end defun
+
+
+
+@node Color Conversions, Color Names, Color Difference Metrics, Color
+@subsection Color Conversions
+
+@ifset html
+<A NAME="Color_Conversions"></A>
+@end ifset
+
+@noindent
+This package contains the low-level color conversion and color metric
+routines operating on lists of 3 numbers. There is no type or range
+checking.
+
+@code{(require 'color-space)}
+
+@defvr Constant CIEXYZ:D65
+Is the color of 6500.K (blackbody) illumination. D65 is close to the
+average color of daylight.
+@end defvr
+
+@defvr Constant CIEXYZ:D50
+Is the color of 5000.K (blackbody) illumination. D50 is the color of
+indoor lighting by incandescent bulbs.
+@end defvr
+
+@defvr Constant CIEXYZ:A
+@defvrx Constant CIEXYZ:B
+@defvrx Constant CIEXYZ:C
+@defvrx Constant CIEXYZ:E
+CIE 1931 illuminants normalized to 1 = y.
+@end defvr
+
+@defun color:linear-transform matrix row
+@end defun
+
+@defun CIEXYZ->RGB709 xyz
+@defunx RGB709->CIEXYZ srgb
+@end defun
+
+@defun CIEXYZ->L*u*v* xyz white-point
+@defunx CIEXYZ->L*u*v* xyz
+@defunx L*u*v*->CIEXYZ L*u*v* white-point
+@defunx L*u*v*->CIEXYZ L*u*v*
+The @var{white-point} defaults to CIEXYZ:D65.
+@end defun
+
+@defun CIEXYZ->L*a*b* xyz white-point
+@defunx CIEXYZ->L*a*b* xyz
+@defunx L*a*b*->CIEXYZ L*a*b* white-point
+@defunx L*a*b*->CIEXYZ L*a*b*
+The XYZ @var{white-point} defaults to CIEXYZ:D65.
+@end defun
+
+@defun L*a*b*->L*C*h L*a*b*
+@defunx L*C*h->L*a*b* L*C*h
+@end defun
+
+@defun CIEXYZ->sRGB xyz
+@defunx sRGB->CIEXYZ srgb
+@end defun
+
+@defun CIEXYZ->xRGB xyz
+@defunx xRGB->CIEXYZ srgb
+@end defun
+
+@defun sRGB->xRGB xyz
+@defunx xRGB->sRGB srgb
+@end defun
+
+@defun CIEXYZ->e-sRGB n xyz
+@defunx e-sRGB->CIEXYZ n srgb
+@end defun
+
+@defun sRGB->e-sRGB n srgb
+@defunx e-sRGB->sRGB n srgb
+The integer @var{n} must be 10, 12, or 16. Because sRGB and e-sRGB use
+the same RGB709 chromaticities, conversion between them is simpler than
+conversion through CIEXYZ.
+@end defun
+
+@noindent
+Do not convert e-sRGB precision through @code{e-sRGB->sRGB} then
+@code{sRGB->e-sRGB} -- values would be truncated to 8-bits!
+
+@defun e-sRGB->e-sRGB n1 srgb n2
+The integers @var{n1} and @var{n2} must be 10, 12, or 16.
+@code{e-sRGB->e-sRGB} converts @var{srgb} to e-sRGB of precision
+@var{n2}.
+@end defun
+
+
+
+@node Color Names, Daylight, Color Conversions, Color
+@subsection Color Names
+
+@ifset html
+<A NAME="Color_Names"></A>
+@end ifset
+@include colornam.txi
+
+@include mkclrnam.txi
+
+@subsubheading The Short List
+
+@code{(require 'saturate)}
+@ftindex saturate
+
+@defun saturate name
+Looks for @var{name} among the 19 saturated colors from
+@cite{Approximate Colors on CIE Chromaticity Diagram}:
+
+@multitable @columnfractions .25 .25 .25 .25
+@item reddish orange @tab orange @tab yellowish orange @tab yellow
+@item greenish yellow @tab yellow green @tab yellowish green @tab green
+@item bluish green @tab blue green @tab greenish blue @tab blue
+@item purplish blue @tab bluish purple @tab purple @tab reddish purple
+@item red purple @tab purplish red @tab red
+@end multitable
+
+(@url{http://swissnet.ai.mit.edu/~jaffer/Color/saturate.pdf}). If
+@var{name} is found, the corresponding color is returned. Otherwise #f
+is returned. Use saturate only for light source colors.
+@end defun
+
+
+@noindent
+Resene Paints Limited, New Zealand's largest privately-owned and
+operated paint manufacturing company, has generously made their
+@cite{Resene RGB Values List} available.
+
+@code{(require 'resene)}
+@ftindex resene
+
+@defun resene name
+Looks for @var{name} among the 1300 entries in the Resene color-name
+dictionary (@url{http://swissnet.ai.mit.edu/~jaffer/Color/resene.pdf}).
+If @var{name} is found, the corresponding color is returned. Otherwise
+#f is returned. The @cite{Resene RGB Values List} is an excellent
+source for surface colors.
+@end defun
+
+@noindent
+If you include the @dfn{Resene RGB Values List} in binary form in a
+program, then you must include its license with your program:
+
+@quotation
+Resene RGB Values List@*
+For further information refer to http://www.resene.co.nz@*
+Copyright Resene Paints Ltd 2001
+
+Permission to copy this dictionary, to modify it, to redistribute it,
+to distribute modified versions, and to use it for any purpose is
+granted, subject to the following restrictions and understandings.
+
+@enumerate
+@item
+Any text copy made of this dictionary must include this copyright
+notice in full.
+
+@item
+Any redistribution in binary form must reproduce this copyright
+notice in the documentation or other materials provided with the
+distribution.
+
+@item
+Resene Paints Ltd makes no warranty or representation that this
+dictionary is error-free, and is under no obligation to provide any
+services, by way of maintenance, update, or otherwise.
+
+@item
+There shall be no use of the name of Resene or Resene Paints Ltd
+in any advertising, promotional, or sales literature without prior
+written consent in each case.
+
+@item
+These RGB colour formulations may not be used to the detriment of
+Resene Paints Ltd.
+@end enumerate
+@end quotation
+
+
+@node Daylight, , Color Names, Color
+@subsection Daylight
-@node Root Finding, Minimizing, Plotting, Mathematical Packages
+@ifset html
+<A NAME="Daylight"></A>
+@end ifset
+@include daylight.txi
+
+
+
+@node Root Finding, Minimizing, Color, Mathematical Packages
@section Root Finding
@code{(require 'root)}
@ftindex root
-@defun newtown:find-integer-root f df/dx x0
+@defun newton:find-integer-root f df/dx x0
Given integer valued procedure @var{f}, its derivative (with respect to
its argument) @var{df/dx}, and initial integer value @var{x0} for which
@var{df/dx}(@var{x0}) is non-zero, returns an integer @var{x} for which
@@ -5119,7 +6149,7 @@ if the iteration should be stopped.
@include minimize.txi
-@node Commutative Rings, Determinant, Minimizing, Mathematical Packages
+@node Commutative Rings, Matrix Algebra, Minimizing, Mathematical Packages
@section Commutative Rings
Scheme provides a consistent and capable set of numeric functions.
@@ -5200,7 +6230,7 @@ the more restrictive Euclidean (Unique Factorization) Domain.
@cindex Unique Factorization
@cindex Euclidean Domain
-@heading Rules and Rulesets
+@section Rules and Rulesets
The @dfn{commutative-ring} package allows control of ring properties
through the use of @dfn{rulesets}.
@@ -5234,10 +6264,12 @@ ruleset.
Two rulesets are defined by this package.
@defvr Constant distribute*
-Contain the ruleset to distribute multiplication over addition and
+Contains the ruleset to distribute multiplication over addition and
subtraction.
-@defvrx Constant distribute/
-Contain the ruleset to distribute division over addition and
+@end defvr
+
+@defvr Constant distribute/
+Contains the ruleset to distribute division over addition and
subtraction.
Take care when using both @var{distribute*} and @var{distribute/}
@@ -5281,7 +6313,7 @@ The following rule is the definition for distributing @code{*} over
@end example
@end defun
-@heading How to Create a Commutative Ring
+@section How to Create a Commutative Ring
The first step in creating your commutative ring is to write procedures
to create elements of the ring. A non-numeric element of the ring must
@@ -5357,14 +6389,14 @@ Test the procedures to see if they work.
(define (splice list1 list2)
(cond ((eq? (last1 list1) (first list2))
(append list1 (cdr list2)))
- (else (error 'splice list1 list2))))
+ (else (slib:error 'splice list1 list2))))
;;; where cyclicsplice is the result of leaving off the last element of
;;; splice(list1,list2).
(define (cyclicsplice list1 list2)
(cond ((and (eq? (last1 list1) (first list2))
(eq? (first list1) (last1 list2)))
(butlast (splice list1 list2) 1))
- (else (error 'cyclicsplice list1 list2))))
+ (else (slib:error 'cyclicsplice list1 list2))))
(N*N (S a b) (S a b)) @result{} (m a b)
@end example
@@ -5425,296 +6457,23 @@ Now we are ready to compute!
(* (m a c e b g) (m d f)))
@end example
-@node Determinant, , Commutative Rings, Mathematical Packages
-@section Determinant
-@defun determinant square-matrix
-Returns the determinant of @var{square-matrix}.
+@node Matrix Algebra, , Commutative Rings, Mathematical Packages
+@section Matrix Algebra
-@example
-(require 'determinant)
-(determinant '((1 2) (3 4))) @result{} -2
-(determinant '((1 2 3) (4 5 6) (7 8 9))) @result{} 0
-(determinant '((1 2 3 4) (5 6 7 8) (9 10 11 12))) @result{} 0
-@end example
-@end defun
+@include determ.txi
@node Database Packages, Other Packages, Mathematical Packages, Top
@chapter Database Packages
@menu
-* Base Table::
* Relational Database:: 'relational-database
+* Relational Infrastructure::
* Weight-Balanced Trees:: 'wt-tree
@end menu
-@node Base Table, Relational Database, Database Packages, Database Packages
-@section Base Table
-
-A base table implementation using Scheme association lists is available
-as the value of the identifier @code{alist-table} after doing:
-
-@code{(require 'alist-table)}
-@ftindex alist-table
-
-
-Association list base tables are suitable for small databases and
-support all Scheme types when temporary and readable/writeable Scheme
-types when saved. I hope support for other base table implementations
-will be added in the future.
-
-This rest of this section documents the interface for a base table
-implementation from which the @ref{Relational Database} package
-constructs a Relational system. It will be of interest primarily to
-those wishing to port or write new base-table implementations.
-
-All of these functions are accessed through a single procedure by
-calling that procedure with the symbol name of the operation. A
-procedure will be returned if that operation is supported and @code{#f}
-otherwise. For example:
-
-@example
-@group
-(require 'alist-table)
-@ftindex alist-table
-(define open-base (alist-table 'make-base))
-make-base @result{} *a procedure*
-(define foo (alist-table 'foo))
-foo @result{} #f
-@end group
-@end example
-
-@defun make-base filename key-dimension column-types
-Returns a new, open, low-level database (collection of tables)
-associated with @var{filename}. This returned database has an empty
-table associated with @var{catalog-id}. The positive integer
-@var{key-dimension} is the number of keys composed to make a
-@var{primary-key} for the catalog table. The list of symbols
-@var{column-types} describes the types of each column for that table.
-If the database cannot be created as specified, @code{#f} is returned.
-
-Calling the @code{close-base} method on this database and possibly other
-operations will cause @var{filename} to be written to. If
-@var{filename} is @code{#f} a temporary, non-disk based database will be
-created if such can be supported by the base table implelentation.
-@end defun
-
-@defun open-base filename mutable
-Returns an open low-level database associated with @var{filename}. If
-@var{mutable?} is @code{#t}, this database will have methods capable of
-effecting change to the database. If @var{mutable?} is @code{#f}, only
-methods for inquiring the database will be available. If the database
-cannot be opened as specified @code{#f} is returned.
-
-Calling the @code{close-base} (and possibly other) method on a
-@var{mutable?} database will cause @var{filename} to be written to.
-@end defun
-
-@defun write-base lldb filename
-Causes the low-level database @var{lldb} to be written to
-@var{filename}. If the write is successful, also causes @var{lldb} to
-henceforth be associated with @var{filename}. Calling the
-@code{close-database} (and possibly other) method on @var{lldb} may
-cause @var{filename} to be written to. If @var{filename} is @code{#f}
-this database will be changed to a temporary, non-disk based database if
-such can be supported by the underlying base table implelentation. If
-the operations completed successfully, @code{#t} is returned.
-Otherwise, @code{#f} is returned.
-@end defun
-
-@defun sync-base lldb
-Causes the file associated with the low-level database @var{lldb} to be
-updated to reflect its current state. If the associated filename is
-@code{#f}, no action is taken and @code{#f} is returned. If this
-operation completes successfully, @code{#t} is returned. Otherwise,
-@code{#f} is returned.
-@end defun
-
-@defun close-base lldb
-Causes the low-level database @var{lldb} to be written to its associated
-file (if any). If the write is successful, subsequent operations to
-@var{lldb} will signal an error. If the operations complete
-successfully, @code{#t} is returned. Otherwise, @code{#f} is returned.
-@end defun
-
-@defun make-table lldb key-dimension column-types
-Returns the @var{base-id} for a new base table, otherwise returns
-@code{#f}. The base table can then be opened using @code{(open-table
-@var{lldb} @var{base-id})}. The positive integer @var{key-dimension} is
-the number of keys composed to make a @var{primary-key} for this table.
-The list of symbols @var{column-types} describes the types of each
-column.
-@end defun
-
-@defvr Constant catalog-id
-A constant @var{base-id} suitable for passing as a parameter to
-@code{open-table}. @var{catalog-id} will be used as the base table for
-the system catalog.
-@end defvr
-
-@defun open-table lldb base-id key-dimension column-types
-Returns a @var{handle} for an existing base table in the low-level
-database @var{lldb} if that table exists and can be opened in the mode
-indicated by @var{mutable?}, otherwise returns @code{#f}.
-
-As with @code{make-table}, the positive integer @var{key-dimension} is
-the number of keys composed to make a @var{primary-key} for this table.
-The list of symbols @var{column-types} describes the types of each
-column.
-@end defun
-
-@defun kill-table lldb base-id key-dimension column-types
-Returns @code{#t} if the base table associated with @var{base-id} was
-removed from the low level database @var{lldb}, and @code{#f} otherwise.
-@end defun
-
-@defun make-keyifier-1 type
-Returns a procedure which accepts a single argument which must be of
-type @var{type}. This returned procedure returns an object suitable for
-being a @var{key} argument in the functions whose descriptions follow.
-
-Any 2 arguments of the supported type passed to the returned function
-which are not @code{equal?} must result in returned values which are not
-@code{equal?}.
-@end defun
-
-@defun make-list-keyifier key-dimension types
-The list of symbols @var{types} must have at least @var{key-dimension}
-elements. Returns a procedure which accepts a list of length
-@var{key-dimension} and whose types must corresopond to the types named
-by @var{types}. This returned procedure combines the elements of its
-list argument into an object suitable for being a @var{key} argument in
-the functions whose descriptions follow.
-
-Any 2 lists of supported types (which must at least include symbols and
-non-negative integers) passed to the returned function which are not
-@code{equal?} must result in returned values which are not
-@code{equal?}.
-@end defun
-
-@defun make-key-extractor key-dimension types column-number
-Returns a procedure which accepts objects produced by application of the
-result of @code{(make-list-keyifier @var{key-dimension} @var{types})}.
-This procedure returns a @var{key} which is @code{equal?} to the
-@var{column-number}th element of the list which was passed to create
-@var{combined-key}. The list @var{types} must have at least
-@var{key-dimension} elements.
-@end defun
-
-@defun make-key->list key-dimension types
-Returns a procedure which accepts objects produced by application of the
-result of @code{(make-list-keyifier @var{key-dimension} @var{types})}.
-This procedure returns a list of @var{key}s which are elementwise
-@code{equal?} to the list which was passed to create @var{combined-key}.
-@end defun
-
-@noindent
-In the following functions, the @var{key} argument can always be assumed
-to be the value returned by a call to a @emph{keyify} routine.
-
-@noindent
-@cindex match-keys
-@cindex match
-@cindex wild-card
-In contrast, a @var{match-keys} argument is a list of length equal to
-the number of primary keys. The @var{match-keys} restrict the actions
-of the table command to those records whose primary keys all satisfy the
-corresponding element of the @var{match-keys} list. The elements and
-their actions are:
-
-@quotation
-@table @asis
-@item @code{#f}
-The false value matches any key in the corresponding position.
-@item an object of type procedure
-This procedure must take a single argument, the key in the corresponding
-position. Any key for which the procedure returns a non-false value is
-a match; Any key for which the procedure returns a @code{#f} is not.
-@item other values
-Any other value matches only those keys @code{equal?} to it.
-@end table
-@end quotation
-
-@noindent
-The @var{key-dimension} and @var{column-types} arguments are needed to
-decode the combined-keys for matching with @var{match-keys}.
-
-@defun for-each-key handle procedure key-dimension column-types match-keys
-Calls @var{procedure} once with each @var{key} in the table opened in
-@var{handle} which satisfy @var{match-keys} in an unspecified order.
-An unspecified value is returned.
-@end defun
-
-@defun map-key handle procedure key-dimension column-types match-keys
-Returns a list of the values returned by calling @var{procedure} once
-with each @var{key} in the table opened in @var{handle} which satisfy
-@var{match-keys} in an unspecified order.
-@end defun
-
-@defun ordered-for-each-key handle procedure key-dimension column-types match-keys
-Calls @var{procedure} once with each @var{key} in the table opened in
-@var{handle} which satisfy @var{match-keys} in the natural order for
-the types of the primary key fields of that table. An unspecified value
-is returned.
-@end defun
-
-@defun delete* handle key-dimension column-types match-keys
-Removes all rows which satisfy @var{match-keys} from the table opened in
-@var{handle}. An unspecified value is returned.
-@end defun
-
-@defun present? handle key
-Returns a non-@code{#f} value if there is a row associated with
-@var{key} in the table opened in @var{handle} and @code{#f} otherwise.
-@end defun
-
-@defun delete handle key
-Removes the row associated with @var{key} from the table opened in
-@var{handle}. An unspecified value is returned.
-@end defun
-
-@defun make-getter key-dimension types
-Returns a procedure which takes arguments @var{handle} and @var{key}.
-This procedure returns a list of the non-primary values of the relation
-(in the base table opened in @var{handle}) whose primary key is
-@var{key} if it exists, and @code{#f} otherwise.
-@end defun
-
-@defun make-putter key-dimension types
-Returns a procedure which takes arguments @var{handle} and @var{key} and
-@var{value-list}. This procedure associates the primary key @var{key}
-with the values in @var{value-list} (in the base table opened in
-@var{handle}) and returns an unspecified value.
-@end defun
-
-@defun supported-type? symbol
-Returns @code{#t} if @var{symbol} names a type allowed as a column value
-by the implementation, and @code{#f} otherwise. At a minimum, an
-implementation must support the types @code{integer}, @code{symbol},
-@code{string}, @code{boolean}, and @code{base-id}.
-@end defun
-
-@defun supported-key-type? symbol
-Returns @code{#t} if @var{symbol} names a type allowed as a key value by
-the implementation, and @code{#f} otherwise. At a minimum, an
-implementation must support the types @code{integer}, and @code{symbol}.
-@end defun
-
-@table @code
-@item integer
-Scheme exact integer.
-@item symbol
-Scheme symbol.
-@item boolean
-@code{#t} or @code{#f}.
-@item base-id
-Objects suitable for passing as the @var{base-id} parameter to
-@code{open-table}. The value of @var{catalog-id} must be an acceptable
-@code{base-id}.
-@end table
-
-@node Relational Database, Weight-Balanced Trees, Base Table, Database Packages
+@node Relational Database, Relational Infrastructure, Database Packages, Database Packages
@section Relational Database
@code{(require 'relational-database)}
@@ -5725,271 +6484,84 @@ Model (@cite{E. F. Codd, A Relational Model of Data for Large Shared
Data Banks}). An SLIB relational database implementation can be created
from any @ref{Base Table} implementation.
+Why relational database? For motivations and design issues see@*
+@uref{http://swissnet.ai.mit.edu/~jaffer/DBManifesto.html}.
+
@menu
-* Motivations:: Database Manifesto
-* Creating and Opening Relational Databases::
-* Relational Database Operations::
+* Using Databases:: 'databases
* Table Operations::
-* Catalog Representation::
-* Unresolved Issues::
-* Database Utilities:: 'database-utilities
-* Database Reports::
+* Database Interpolation:: 'database-interpolate
+* Embedded Commands:: 'database-commands
+* Database Macros:: 'within-database
* Database Browser:: 'database-browse
@end menu
-@node Motivations, Creating and Opening Relational Databases, Relational Database, Relational Database
-@subsection Motivations
-
-Most nontrivial programs contain databases: Makefiles, configure
-scripts, file backup, calendars, editors, source revision control, CAD
-systems, display managers, menu GUIs, games, parsers, debuggers,
-profilers, and even error reporting are all rife with databases. Coding
-databases is such a common activity in programming that many may not be
-aware of how often they do it.
-
-A database often starts as a dispatch in a program. The author, perhaps
-because of the need to make the dispatch configurable, the need for
-correlating dispatch in other routines, or because of changes or growth,
-devises a data structure to contain the information, a routine for
-interpreting that data structure, and perhaps routines for augmenting
-and modifying the stored data. The dispatch must be converted into this
-form and tested.
-
-The programmer may need to devise an interactive program for enabling
-easy examination and modification of the information contained in this
-database. Often, in an attempt to foster modularity and avoid delays in
-release, intermediate file formats for the database information are
-devised. It often turns out that users prefer modifying these
-intermediate files with a text editor to using the interactive program
-in order to do operations (such as global changes) not forseen by the
-program's author.
-
-In order to address this need, the conscientious software engineer may
-even provide a scripting language to allow users to make repetitive
-database changes. Users will grumble that they need to read a large
-manual and learn yet another programming language (even if it
-@emph{almost} has language "xyz" syntax) in order to do simple
-configuration.
-
-All of these facilities need to be designed, coded, debugged,
-documented, and supported; often causing what was very simple in concept
-to become a major developement project.
-
-This view of databases just outlined is somewhat the reverse of the view
-of the originators of the @dfn{Relational Model} of database
-abstraction. The relational model was devised to unify and allow
-interoperation of large multi-user databases running on diverse
-platforms. A fairly general purpose "Comprehensive Language" for
-database manipulations is mandated (but not specified) as part of the
-relational model for databases.
-
-One aspect of the Relational Model of some importance is that the
-"Comprehensive Language" must be expressible in some form which can be
-stored in the database. This frees the programmer from having to make
-programs data-driven in order to use a database.
-
-This package includes as one of its basic supported types Scheme
-@dfn{expression}s. This type allows expressions as defined by the
-Scheme standards to be stored in the database. Using @code{slib:eval}
-retrieved expressions can be evaluated (in the top-level environment).
-Scheme's @code{lambda} facilitates closure of environments, modularity,
-etc. so that procedures (which could not be stored directly most
-databases) can still be effectively retrieved. Since @code{slib:eval}
-evaluates expressions in the top-level environment, built-in and user
-defined procedures can be easily accessed by name.
-
-This package's purpose is to standardize (through a common interface)
-database creation and usage in Scheme programs. The relational model's
-provision for inclusion of language expressions as data as well as the
-description (in tables, of course) of all of its tables assures that
-relational databases are powerful enough to assume the roles currently
-played by thousands of ad-hoc routines and data formats.
-
-@noindent
-Such standardization to a relational-like model brings many benefits:
+@node Using Databases, Table Operations, Relational Database, Relational Database
+@subsection Using Databases
-@itemize @bullet
-@item
-Tables, fields, domains, and types can be dealt with by name in
-programs.
-@item
-The underlying database implementation can be changed (for
-performance or other reasons) by changing a single line of code.
-@item
-The formats of tables can be easily extended or changed without
-altering code.
-@item
-Consistency checks are specified as part of the table descriptions.
-Changes in checks need only occur in one place.
-@item
-All the configuration information which the developer wishes to group
-together is easily grouped, without needing to change programs aware of
-only some of these tables.
-@item
-Generalized report generators, interactive entry programs, and other
-database utilities can be part of a shared library. The burden of
-adding configurability to a program is greatly reduced.
-@item
-Scheme is the "comprehensive language" for these databases. Scripting
-for configuration no longer needs to be in a separate language with
-additional documentation.
-@item
-Scheme's latent types mesh well with the strict typing and logical
-requirements of the relational model.
-@item
-Portable formats allow easy interchange of data. The included table
-descriptions help prevent misinterpretation of format.
-@end itemize
+@include dbutil.txi
-@node Creating and Opening Relational Databases, Relational Database Operations, Motivations, Relational Database
-@subsection Creating and Opening Relational Databases
-@defun make-relational-system base-table-implementation
-Returns a procedure implementing a relational database using the
-@var{base-table-implementation}.
+@node Table Operations, Database Interpolation, Using Databases, Relational Database
+@subsection Table Operations
-All of the operations of a base table implementation are accessed
-through a procedure defined by @code{require}ing that implementation.
-Similarly, all of the operations of the relational database
-implementation are accessed through the procedure returned by
-@code{make-relational-system}. For instance, a new relational database
-could be created from the procedure returned by
-@code{make-relational-system} by:
+@noindent
+These are the descriptions of the methods available from an open
+relational table. A method is retrieved from a table by calling
+the table with the symbol name of the operation. For example:
@example
-(require 'alist-table)
-@ftindex alist-table
-(define relational-alist-system
- (make-relational-system alist-table))
-(define create-alist-database
- (relational-alist-system 'create-database))
-(define my-database
- (create-alist-database "mydata.db"))
+((plat 'get 'processor) 'djgpp) @result{} i386
@end example
-@end defun
@noindent
-What follows are the descriptions of the methods available from
-relational system returned by a call to @code{make-relational-system}.
-
-@defun create-database filename
-
-Returns an open, nearly empty relational database associated with
-@var{filename}. The only tables defined are the system catalog and
-domain table. Calling the @code{close-database} method on this database
-and possibly other operations will cause @var{filename} to be written
-to. If @var{filename} is @code{#f} a temporary, non-disk based database
-will be created if such can be supported by the underlying base table
-implelentation. If the database cannot be created as specified
-@code{#f} is returned. For the fields and layout of descriptor tables,
-@ref{Catalog Representation}
-@end defun
-
-@defun open-database filename mutable?
-
-Returns an open relational database associated with @var{filename}. If
-@var{mutable?} is @code{#t}, this database will have methods capable of
-effecting change to the database. If @var{mutable?} is @code{#f}, only
-methods for inquiring the database will be available. Calling the
-@code{close-database} (and possibly other) method on a @var{mutable?}
-database will cause @var{filename} to be written to. If the database
-cannot be opened as specified @code{#f} is returned.
-@end defun
-
-@node Relational Database Operations, Table Operations, Creating and Opening Relational Databases, Relational Database
-@subsection Relational Database Operations
+Some operations described below require primary key arguments. Primary
+keys arguments are denoted @var{key1} @var{key2} @dots{}. It is an
+error to call an operation for a table which takes primary key arguments
+with the wrong number of primary keys for that table.
-@noindent
-These are the descriptions of the methods available from an open
-relational database. A method is retrieved from a database by calling
-the database with the symbol name of the operation. For example:
+@defop {Operation} {relational-table} get column-name
+Returns a procedure of arguments @var{key1} @var{key2} @dots{} which
+returns the value for the @var{column-name} column of the row associated
+with primary keys @var{key1}, @var{key2} @dots{} if that row exists in
+the table, or @code{#f} otherwise.
@example
-(define my-database
- (create-alist-database "mydata.db"))
-(define telephone-table-desc
- ((my-database 'create-table) 'telephone-table-desc))
+((plat 'get 'processor) 'djgpp) @result{} i386
+((plat 'get 'processor) 'be-os) @result{} #f
@end example
+@end defop
-@defun close-database
-Causes the relational database to be written to its associated file (if
-any). If the write is successful, subsequent operations to this
-database will signal an error. If the operations completed
-successfully, @code{#t} is returned. Otherwise, @code{#f} is returned.
-@end defun
-
-@defun write-database filename
-Causes the relational database to be written to @var{filename}. If the
-write is successful, also causes the database to henceforth be
-associated with @var{filename}. Calling the @code{close-database} (and
-possibly other) method on this database will cause @var{filename} to be
-written to. If @var{filename} is @code{#f} this database will be
-changed to a temporary, non-disk based database if such can be supported
-by the underlying base table implelentation. If the operations
-completed successfully, @code{#t} is returned. Otherwise, @code{#f} is
-returned.
-@end defun
-
-@defun sync-database
-Causes any pending updates to the database file to be written out. If
-the operations completed successfully, @code{#t} is returned.
-Otherwise, @code{#f} is returned.
-@end defun
+@menu
+* Single Row Operations::
+* Match-Keys::
+* Multi-Row Operations::
+* Indexed Sequential Access Methods::
+* Sequential Index Operations::
+* Table Administration::
+@end menu
-@defun table-exists? table-name
-Returns @code{#t} if @var{table-name} exists in the system catalog,
-otherwise returns @code{#f}.
-@end defun
-@defun open-table table-name mutable?
-Returns a @dfn{methods} procedure for an existing relational table in
-this database if it exists and can be opened in the mode indicated by
-@var{mutable?}, otherwise returns @code{#f}.
-@end defun
+@node Single Row Operations, Match-Keys, Table Operations, Table Operations
+@subsubsection Single Row Operations
@noindent
-These methods will be present only in databases which are
-@var{mutable?}.
-
-@defun delete-table table-name
-Removes and returns the @var{table-name} row from the system catalog if
-the table or view associated with @var{table-name} gets removed from the
-database, and @code{#f} otherwise.
-@end defun
-
-@defun create-table table-desc-name
-Returns a methods procedure for a new (open) relational table for
-describing the columns of a new base table in this database, otherwise
-returns @code{#f}. For the fields and layout of descriptor tables,
-@xref{Catalog Representation}.
-
-@defunx create-table table-name table-desc-name
-Returns a methods procedure for a new (open) relational table with
-columns as described by @var{table-desc-name}, otherwise returns
-@code{#f}.
-@end defun
-
-@defun create-view ??
-@defunx project-table ??
-@defunx restrict-table ??
-@defunx cart-prod-tables ??
-Not yet implemented.
-@end defun
-
-@node Table Operations, Catalog Representation, Relational Database Operations, Relational Database
-@subsection Table Operations
+The term @dfn{row} used below refers to a Scheme list of values (one for
+each column) in the order specified in the descriptor (table) for this
+table. Missing values appear as @code{#f}. Primary keys must not
+be missing.
-@noindent
-These are the descriptions of the methods available from an open
-relational table. A method is retrieved from a table by calling
-the table with the symbol name of the operation. For example:
+@defop {Operation} {relational-table} row:insert
+Adds the row @var{row} to this table. If a row for the primary key(s)
+specified by @var{row} already exists in this table an error is
+signaled. The value returned is unspecified.
+@end defop
@example
@group
(define telephone-table-desc
((my-database 'create-table) 'telephone-table-desc))
-(require 'common-list-functions)
(define ndrp (telephone-table-desc 'row:insert))
(ndrp '(1 #t name #f string))
(ndrp '(2 #f telephone
@@ -6004,43 +6576,80 @@ the table with the symbol name of the operation. For example:
@end group
@end example
-@noindent
-Some operations described below require primary key arguments. Primary
-keys arguments are denoted @var{key1} @var{key2} @dots{}. It is an
-error to call an operation for a table which takes primary key arguments
-with the wrong number of primary keys for that table.
-
-@noindent
-The term @dfn{row} used below refers to a Scheme list of values (one for
-each column) in the order specified in the descriptor (table) for this
-table. Missing values appear as @code{#f}. Primary keys must not
-be missing.
+@defop {Operation} {relational-table} row:update
+Returns a procedure of one argument, @var{row}, which adds the row,
+@var{row}, to this table. If a row for the primary key(s) specified by
+@var{row} already exists in this table, it will be overwritten. The
+value returned is unspecified.
+@end defop
-@defun get column-name
+@defop {Operation} {relational-table} row:retrieve
Returns a procedure of arguments @var{key1} @var{key2} @dots{} which
-returns the value for the @var{column-name} column of the row associated
-with primary keys @var{key1}, @var{key2} @dots{} if that row exists in
-the table, or @code{#f} otherwise.
+returns the row associated with primary keys @var{key1}, @var{key2}
+@dots{} if it exists, or @code{#f} otherwise.
+@end defop
@example
-((plat 'get 'processor) 'djgpp) @result{} i386
-((plat 'get 'processor) 'be-os) @result{} #f
+((plat 'row:retrieve) 'linux) @result{} (linux i386 linux gcc)
+((plat 'row:retrieve) 'multics) @result{} #f
@end example
-@defunx get* column-name
+@defop {Operation} {relational-table} row:remove
+Returns a procedure of arguments @var{key1} @var{key2} @dots{} which
+removes and returns the row associated with primary keys @var{key1},
+@var{key2} @dots{} if it exists, or @code{#f} otherwise.
+@end defop
+
+@defop {Operation} {relational-table} row:delete
+Returns a procedure of arguments @var{key1} @var{key2} @dots{} which
+deletes the row associated with primary keys @var{key1}, @var{key2}
+@dots{} if it exists. The value returned is unspecified.
+@end defop
+
+
+@node Match-Keys, Multi-Row Operations, Single Row Operations, Table Operations
+@subsubsection Match-Keys
+
+@noindent
+@cindex match-keys
+The (optional) @var{match-key1} @dots{} arguments are used to restrict
+actions of a whole-table operation to a subset of that table. Those
+procedures (returned by methods) which accept match-key arguments will
+accept any number of match-key arguments between zero and the number of
+primary keys in the table. Any unspecified @var{match-key} arguments
+default to @code{#f}.
+
+@noindent
+The @var{match-key1} @dots{} restrict the actions of the table command
+to those records whose primary keys each satisfy the corresponding
+@var{match-key} argument. The arguments and their actions are:
+
+@quotation
+@table @asis
+@item @code{#f}
+The false value matches any key in the corresponding position.
+@item an object of type procedure
+This procedure must take a single argument, the key in the corresponding
+position. Any key for which the procedure returns a non-false value is
+a match; Any key for which the procedure returns a @code{#f} is not.
+@item other values
+Any other value matches only those keys @code{equal?} to it.
+@end table
+@end quotation
+
+@defop {Operation} {relational-table} get* column-name
Returns a procedure of optional arguments @var{match-key1} @dots{} which
returns a list of the values for the specified column for all rows in
this table. The optional @var{match-key1} @dots{} arguments restrict
-actions to a subset of the table. See the match-key description below
-for details.
+actions to a subset of the table.
@example
((plat 'get* 'processor)) @result{}
-(i386 8086 i386 8086 i386 i386 8086 m68000
+(i386 i8086 i386 i8086 i386 i386 i8086 m68000
m68000 m68000 m68000 m68000 powerpc)
((plat 'get* 'processor) #f) @result{}
-(i386 8086 i386 8086 i386 i386 8086 m68000
+(i386 i8086 i386 i8086 i386 i386 i8086 m68000
m68000 m68000 m68000 m68000 powerpc)
(define (a-key? key)
@@ -6053,24 +6662,18 @@ for details.
(atari-st-turbo-c atari-st-gcc amiga-sas/c-5.10
amiga-aztec amiga-dice-c aix)
@end example
-@end defun
+@end defop
-@defun row:retrieve
-Returns a procedure of arguments @var{key1} @var{key2} @dots{} which
-returns the row associated with primary keys @var{key1}, @var{key2}
-@dots{} if it exists, or @code{#f} otherwise.
-@example
-((plat 'row:retrieve) 'linux) @result{} (linux i386 linux gcc)
-((plat 'row:retrieve) 'multics) @result{} #f
-@end example
+@node Multi-Row Operations, Indexed Sequential Access Methods, Match-Keys, Table Operations
+@subsubsection Multi-Row Operations
-@defunx row:retrieve*
-Returns a procedure of optional arguments @var{match-key1} @dots{} which
-returns a list of all rows in this table. The optional @var{match-key1}
-@dots{} arguments restrict actions to a subset of the table. See the
-match-key description below for details.
-@end defun
+@defop {Operation} {relational-table} row:retrieve*
+Returns a procedure of optional arguments @var{match-key1} @dots{}
+which returns a list of all rows in this table. The optional
+@var{match-key1} @dots{} arguments restrict actions to a subset of the
+table. For details see @xref{Match-Keys}.
+@end defop
@example
((plat 'row:retrieve*) a-key?) @result{}
@@ -6082,319 +6685,399 @@ match-key description below for details.
(aix powerpc aix -))
@end example
-@defun row:remove
-Returns a procedure of arguments @var{key1} @var{key2} @dots{} which
-removes and returns the row associated with primary keys @var{key1},
-@var{key2} @dots{} if it exists, or @code{#f} otherwise.
-
-@defunx row:remove*
+@defop {Operation} {relational-table} row:remove*
Returns a procedure of optional arguments @var{match-key1} @dots{} which
removes and returns a list of all rows in this table. The optional
@var{match-key1} @dots{} arguments restrict actions to a subset of the
-table. See the match-key description below for details.
-@end defun
+table.
+@end defop
-@defun row:delete
-Returns a procedure of arguments @var{key1} @var{key2} @dots{} which
-deletes the row associated with primary keys @var{key1}, @var{key2}
-@dots{} if it exists. The value returned is unspecified.
+@defop {Operation} {relational-table} row:delete*
+Returns a procedure of optional arguments @var{match-key1} @dots{}
+which Deletes all rows from this table. The optional @var{match-key1}
+@dots{} arguments restrict deletions to a subset of the table. The
+value returned is unspecified. The descriptor table and catalog entry
+for this table are not affected.
+@end defop
-@defunx row:delete*
-Returns a procedure of optional arguments @var{match-key1} @dots{} which
-Deletes all rows from this table. The optional @var{match-key1} @dots{}
-arguments restrict deletions to a subset of the table. See the
-match-key description below for details. The value returned is
-unspecified. The descriptor table and catalog entry for this table are
-not affected.
-@end defun
+@defop {Operation} {relational-table} for-each-row
+Returns a procedure of arguments @var{proc} @var{match-key1} @dots{}
+which calls @var{proc} with each @var{row} in this table. The
+optional @var{match-key1} @dots{} arguments restrict actions to a
+subset of the table. For details see @xref{Match-Keys}.
+@end defop
-@defun row:update
-Returns a procedure of one argument, @var{row}, which adds the row,
-@var{row}, to this table. If a row for the primary key(s) specified by
-@var{row} already exists in this table, it will be overwritten. The
-value returned is unspecified.
+@noindent
+Note that @code{row:insert*} and @code{row:update*} do @emph{not} use
+match-keys.
-@defunx row:update*
+@defop {Operation} {relational-table} row:insert*
Returns a procedure of one argument, @var{rows}, which adds each row in
the list of rows, @var{rows}, to this table. If a row for the primary
key specified by an element of @var{rows} already exists in this table,
-it will be overwritten. The value returned is unspecified.
-@end defun
-
-@defun row:insert
-Adds the row @var{row} to this table. If a row for the primary key(s)
-specified by @var{row} already exists in this table an error is
-signaled. The value returned is unspecified.
+an error is signaled. The value returned is unspecified.
+@end defop
-@defunx row:insert*
+@defop {Operation} {relational-table} row:update*
Returns a procedure of one argument, @var{rows}, which adds each row in
the list of rows, @var{rows}, to this table. If a row for the primary
key specified by an element of @var{rows} already exists in this table,
-an error is signaled. The value returned is unspecified.
-@end defun
-
-@defun for-each-row
-Returns a procedure of arguments @var{proc} @var{match-key1} @dots{}
-which calls @var{proc} with each @var{row} in this table in the
-(implementation-dependent) natural ordering for rows. The optional
-@var{match-key1} @dots{} arguments restrict actions to a subset of the
-table. See the match-key description below for details.
+it will be overwritten. The value returned is unspecified.
+@end defop
-@emph{Real} relational programmers would use some least-upper-bound join
-for every row to get them in order; But we don't have joins yet.
-@end defun
-@noindent
-@cindex match-keys
-The (optional) @var{match-key1} @dots{} arguments are used to restrict
-actions of a whole-table operation to a subset of that table. Those
-procedures (returned by methods) which accept match-key arguments will
-accept any number of match-key arguments between zero and the number of
-primary keys in the table. Any unspecified @var{match-key} arguments
-default to @code{#f}.
+@node Indexed Sequential Access Methods, Sequential Index Operations, Multi-Row Operations, Table Operations
+@subsubsection Indexed Sequential Access Methods
@noindent
-The @var{match-key1} @dots{} restrict the actions of the table command
-to those records whose primary keys each satisfy the corresponding
-@var{match-key} argument. The arguments and their actions are:
-
-@quotation
-@table @asis
-@item @code{#f}
-The false value matches any key in the corresponding position.
-@item an object of type procedure
-This procedure must take a single argument, the key in the corresponding
-position. Any key for which the procedure returns a non-false value is
-a match; Any key for which the procedure returns a @code{#f} is not.
-@item other values
-Any other value matches only those keys @code{equal?} to it.
-@end table
-@end quotation
-
-@defun close-table
-Subsequent operations to this table will signal an error.
-@end defun
-
-@defvr Constant column-names
-@defvrx Constant column-foreigns
-@defvrx Constant column-domains
-@defvrx Constant column-types
-Return a list of the column names, foreign-key table names, domain
-names, or type names respectively for this table. These 4 methods are
-different from the others in that the list is returned, rather than a
-procedure to obtain the list.
-
-@defvrx Constant primary-limit
-Returns the number of primary keys fields in the relations in this
-table.
-@end defvr
-
-@node Catalog Representation, Unresolved Issues, Table Operations, Relational Database
-@subsection Catalog Representation
+@cindex ISAM
+@dfn{Indexed Sequential Access Methods} are a way of arranging
+database information so that records can be accessed both by key and
+by key sequence (ordering). @dfn{ISAM} is not part of Codd's
+relational model. Hardcore relational programmers might use some
+least-upper-bound join for every row to get them into an order.
@noindent
-Each database (in an implementation) has a @dfn{system catalog} which
-describes all the user accessible tables in that database (including
-itself).
+Associative memory in B-Trees is an example of a database
+implementation which can support a native key ordering. SLIB's
+@code{alist-table} implementation uses @code{sort} to implement
+@code{for-each-row-in-order}, but does not support @code{isam-next}
+and @code{isam-prev}.
@noindent
-The system catalog base table has the following fields. @code{PRI}
-indicates a primary key for that table.
+The multi-primary-key ordering employed by these operations is the
+lexicographic collation of those primary-key fields in their given
+order. For example:
@example
-@group
-PRI table-name
- column-limit the highest column number
- coltab-name descriptor table name
- bastab-id data base table identifier
- user-integrity-rule
- view-procedure A scheme thunk which, when called,
- produces a handle for the view. coltab
- and bastab are specified if and only if
- view-procedure is not.
-@end group
+(12 a 34) < (12 a 36) < (12 b 1) < (13 a 0)
@end example
-@noindent
-Descriptors for base tables (not views) are tables (pointed to by
-system catalog). Descriptor (base) tables have the fields:
-@example
-@group
-PRI column-number sequential integers from 1
- primary-key? boolean TRUE for primary key components
- column-name
- column-integrity-rule
- domain-name
-@end group
-@end example
+@node Sequential Index Operations, Table Administration, Indexed Sequential Access Methods, Table Operations
+@subsubsection Sequential Index Operations
@noindent
-A @dfn{primary key} is any column marked as @code{primary-key?} in the
-corresponding descriptor table. All the @code{primary-key?} columns
-must have lower column numbers than any non-@code{primary-key?} columns.
-Every table must have at least one primary key. Primary keys must be
-sufficient to distinguish all rows from each other in the table. All of
-the system defined tables have a single primary key.
+The following procedures are individually optional depending on the
+base-table implememtation. If an operation is @emph{not} supported,
+then calling the table with that operation symbol will return false.
-@noindent
-This package currently supports tables having from 1 to 4 primary keys
-if there are non-primary columns, and any (natural) number if @emph{all}
-columns are primary keys. If you need more than 4 primary keys, I would
-like to hear what you are doing!
+@defop {Operation} {relational-table} for-each-row-in-order
+Returns a procedure of arguments @var{proc} @var{match-key1} @dots{}
+which calls @var{proc} with each @var{row} in this table in the
+(implementation-dependent) natural, repeatable ordering for rows. The
+optional @var{match-key1} @dots{} arguments restrict actions to a
+subset of the table. For details see @xref{Match-Keys}.
+@end defop
-@noindent
-A @dfn{domain} is a category describing the allowable values to occur in
-a column. It is described by a (base) table with the fields:
+@defop {Operation} {relational-table} isam-next
+Returns a procedure of arguments @var{key1} @var{key2} @dots{} which
+returns the key-list identifying the lowest record higher than
+@var{key1} @var{key2} @dots{} which is stored in the relational-table;
+or false if no higher record is present.
-@example
-@group
-PRI domain-name
- foreign-table
- domain-integrity-rule
- type-id
- type-param
-@end group
-@end example
+@defopx {Operation} {relational-table} isam-next column-name
+The symbol @var{column-name} names a key field. In the list returned
+by @code{isam-next}, that field, or a field to its left, will be
+changed. This allows one to skip over less significant key fields.
+@end defop
-@noindent
-The @dfn{type-id} field value is a symbol. This symbol may be used by
-the underlying base table implementation in storing that field.
+@defop {Operation} {relational-table} isam-prev
+Returns a procedure of arguments @var{key1} @var{key2} @dots{} which
+returns the key-list identifying the highest record less than
+@var{key1} @var{key2} @dots{} which is stored in the relational-table;
+or false if no lower record is present.
-@noindent
-If the @code{foreign-table} field is non-@code{#f} then that field names
-a table from the catalog. The values for that domain must match a
-primary key of the table referenced by the @var{type-param} (or
-@code{#f}, if allowed). This package currently does not support
-composite foreign-keys.
+@defopx {Operation} {relational-table} isam-prev index
+The symbol @var{column-name} names a key field. In the list returned
+by @code{isam-next}, that field, or a field to its left, will be
+changed. This allows one to skip over less significant key fields.
+@end defop
-@noindent
-The types for which support is planned are:
+For example, if a table has key fields:
@example
-@group
- atom
- symbol
- string [<length>]
- number [<base>]
- money <currency>
- date-time
- boolean
+(col1 col2)
+(9 5)
+(9 6)
+(9 7)
+(9 8)
+(12 5)
+(12 6)
+(12 7)
+@end example
- foreign-key <table-name>
- expression
- virtual <expression>
-@end group
+Then:
+@example
+((table 'isam-next) '(9 5)) @result{} (9 6)
+((table 'isam-next 'col2) '(9 5)) @result{} (9 6)
+((table 'isam-next 'col1) '(9 5)) @result{} (12 5)
+((table 'isam-prev) '(12 7)) @result{} (12 6)
+((table 'isam-prev 'col2) '(12 7)) @result{} (12 6)
+((table 'isam-prev 'col1) '(12 7)) @result{} (9 8)
@end example
-@node Unresolved Issues, Database Utilities, Catalog Representation, Relational Database
-@subsection Unresolved Issues
-Although @file{rdms.scm} is not large, I found it very difficult to
-write (six rewrites). I am not aware of any other examples of a
-generalized relational system (although there is little new in CS). I
-left out several aspects of the Relational model in order to simplify
-the job. The major features lacking (which might be addressed portably)
-are views, transaction boundaries, and protection.
+@node Table Administration, , Sequential Index Operations, Table Operations
+@subsubsection Table Administration
+
+@defop {Operation} {relational-table} column-names
+@defopx {Operation} {relational-table} column-foreigns
+@defopx {Operation} {relational-table} column-domains
+@defopx {Operation} {relational-table} column-types
+Return a list of the column names, foreign-key table names, domain
+names, or type names respectively for this table. These 4 methods are
+different from the others in that the list is returned, rather than a
+procedure to obtain the list.
-Protection needs a model for specifying priveledges. Given how
-operations are accessed from handles it should not be difficult to
-restrict table accesses to those allowed for that user.
+@defopx {Operation} {relational-table} primary-limit
+Returns the number of primary keys fields in the relations in this
+table.
+@end defop
-The system catalog has a field called @code{view-procedure}. This
-should allow a purely functional implementation of views. This will
-work but is unsatisfying for views resulting from a @dfn{select}ion
-(subset of rows); for whole table operations it will not be possible to
-reduce the number of keys scanned over when the selection is specified
-only by an opaque procedure.
+@defop {Operation} {relational-table} close-table
+Subsequent operations to this table will signal an error.
+@end defop
-Transaction boundaries present the most intriguing area. Transaction
-boundaries are actually a feature of the "Comprehensive Language" of the
-Relational database and not of the database. Scheme would seem to
-provide the opportunity for an extremely clean semantics for transaction
-boundaries since the builtin procedures with side effects are small in
-number and easily identified.
+@node Database Interpolation, Embedded Commands, Table Operations, Relational Database
+@subsection Database Interpolation
-These side-effect builtin procedures might all be portably redefined to
-versions which properly handled transactions. Compiled library routines
-would need to be recompiled as well. Many system extensions
-(delete-file, system, etc.) would also need to be redefined.
+@code{(require 'database-interpolate)}
@noindent
-There are 2 scope issues that must be resolved for multiprocess
-transaction boundaries:
+Indexed sequential access methods allow finding the keys (having
+associations) closest to a given value. This facilitates the
+interpolation of associations between those in the table.
-@table @asis
-@item Process scope
-The actions captured by a transaction should be only for the process
-which invoked the start of transaction. Although standard Scheme does
-not provide process primitives as such, @code{dynamic-wind} would
-provide a workable hook into process switching for many implementations.
-@item Shared utilities with state
-Some shared utilities have state which should @emph{not} be part of a
-transaction. An example would be calling a pseudo-random number
-generator. If the success of a transaction depended on the
-pseudo-random number and failed, the state of the generator would be set
-back. Subsequent calls would keep returning the same number and keep
-failing.
-
-Pseudo-random number generators are not reentrant; thus they would
-require locks in order to operate properly in a multiprocess
-environment. Are all examples of utilities whose state should not be
-part of transactions also non-reentrant? If so, perhaps suspending
-transaction capture for the duration of locks would solve this problem.
-@end table
+@defun interpolate-from-table table column
+@var{Table} should be a relational table with one numeric primary key
+field which supports the @code{isam-prev} and @code{isam-next}
+operations. @var{column} should be a symbol or exact positive integer
+designating a numerically valued column of @var{table}.
+
+@code{interpolate-from-table} calculates and returns a value
+proportionally intermediate between its values in the next and
+previous key records contained in @var{table}. For keys larger than
+all the stored keys the value associated with the largest stored key
+is used. For keys smaller than all the stored keys the value
+associated with the smallest stored key is used.
+@end defun
-@node Database Utilities, Database Reports, Unresolved Issues, Relational Database
-@subsection Database Utilities
-@code{(require 'database-utilities)}
-@ftindex database-utilities
+
+@node Embedded Commands, Database Macros, Database Interpolation, Relational Database
+@subsection Embedded Commands
+
+@code{(require 'database-commands)}
@noindent
This enhancement wraps a utility layer on @code{relational-database}
which provides:
+
@itemize @bullet
@item
-Automatic loading of the appropriate base-table package when opening a
-database.
-@item
Automatic execution of initialization commands stored in database.
@item
Transparent execution of database commands stored in @code{*commands*}
table in database.
@end itemize
-@noindent
-Also included are utilities which provide:
-@itemize @bullet
-@item
-Data definition from Scheme lists and
-@item
-Report generation
-@end itemize
-@noindent
-for any SLIB relational database.
+When an enhanced relational-database is called with a symbol which
+matches a @var{name} in the @code{*commands*} table, the associated
+procedure expression is evaluated and applied to the enhanced
+relational-database. A procedure should then be returned which the user
+can invoke on (optional) arguments.
+
+The command @code{*initialize*} is special. If present in the
+@code{*commands*} table, @code{open-database} or @code{open-database!}
+will return the value of the @code{*initialize*} command. Notice that
+arbitrary code can be run when the @code{*initialize*} procedure is
+automatically applied to the enhanced relational-database.
+
+Note also that if you wish to shadow or hide from the user
+relational-database methods described in @ref{Database Operations}, this
+can be done by a dispatch in the closure returned by the
+@code{*initialize*} expression rather than by entries in the
+@code{*commands*} table if it is desired that the underlying methods
+remain accessible to code in the @code{*commands*} table.
+
+
+@menu
+* Database Extension::
+* Command Intrinsics::
+* Define-tables Example::
+* The *commands* Table::
+* Command Service::
+* Command Example::
+@end menu
+
+
+@node Database Extension, Command Intrinsics, Embedded Commands, Embedded Commands
+@subsubsection Database Extension
+
+@defun wrap-command-interface rdb
+Returns relational database @var{rdb} wrapped with additional commands
+defined in its *commands* table.
+@end defun
+
+@defun add-command-tables rdb
+The relational database @var{rdb} must be mutable.
+@var{add-command-tables} adds a *command* table to @var{rdb}; then
+returns @code{(wrap-command-interface @var{rdb})}.
+@end defun
+
+@defun define-*commands* rdb spec-0 @dots{}
+
+Adds commands to the @code{*commands*} table as specified in
+@var{spec-0} @dots{} to the open relational-database @var{rdb}. Each
+@var{spec} has the form:
+
+@lisp
+((@r{<name>} @r{<rdb>}) @r{"comment"} @r{<expression1>} @r{<expression2>} @dots{})
+@end lisp
+or
+@lisp
+((@r{<name>} @r{<rdb>}) @r{<expression1>} @r{<expression2>} @dots{})
+@end lisp
+
+where @r{<name>} is the command name, @r{<rdb>} is a formal passed the
+calling relational database, @r{"comment"} describes the
+command, and @r{<expression1>}, @r{<expression1>}, @dots{} are the
+body of the procedure.
+
+@code{define-*commands*} adds to the @code{*commands*} table a command
+@r{<name>}:
+
+@lisp
+(lambda (@r{<name>} @r{<rdb>}) @r{<expression1>} @r{<expression2>} @dots{})
+@end lisp
-@defun create-database filename base-table-type
-Returns an open, nearly empty enhanced (with @code{*commands*} table)
-relational database (with base-table type @var{base-table-type})
-associated with @var{filename}.
@end defun
-@defun open-database filename
-@defunx open-database filename base-table-type
-Returns an open enchanced relational database associated with
+
+@defun open-command-database filename
+@defunx open-command-database filename base-table-type
+Returns an open enhanced relational database associated with
@var{filename}. The database will be opened with base-table type
@var{base-table-type}) if supplied. If @var{base-table-type} is not
-supplied, @code{open-database} will attempt to deduce the correct
+supplied, @code{open-command-database} will attempt to deduce the correct
base-table-type. If the database can not be opened or if it lacks the
@code{*commands*} table, @code{#f} is returned.
-@defunx open-database! filename
-@defunx open-database! filename base-table-type
-Returns @emph{mutable} open enchanced relational database @dots{}
+@defunx open-command-database! filename
+@defunx open-command-database! filename base-table-type
+Returns @emph{mutable} open enhanced relational database @dots{}
+
+@defunx open-command-database database
+Returns @var{database} if it is an immutable relational database; #f
+otherwise.
+
+@defunx open-command-database! database
+Returns @var{database} if it is a mutable relational database; #f
+otherwise.
@end defun
+
+@node Command Intrinsics, Define-tables Example, Database Extension, Embedded Commands
+@subsubsection Command Intrinsics
+
+Some commands are defined in all extended relational-databases. The are
+called just like @ref{Database Operations}.
+
+@defop {Operation} {relational-database} add-domain domain-row
+Adds @var{domain-row} to the @dfn{domains} table if there is no row in
+the domains table associated with key @code{(car @var{domain-row})} and
+returns @code{#t}. Otherwise returns @code{#f}.
+
+For the fields and layout of the domain table, @xref{Catalog
+Representation}. Currently, these fields are
+@itemize @bullet
+@item
+domain-name
+@item
+foreign-table
+@item
+domain-integrity-rule
+@item
+type-id
+@item
+type-param
+@end itemize
+
+The following example adds 3 domains to the @samp{build} database.
+@samp{Optstring} is either a string or @code{#f}. @code{filename} is a
+string and @code{build-whats} is a symbol.
+
+@example
+(for-each (build 'add-domain)
+ '((optstring #f
+ (lambda (x) (or (not x) (string? x)))
+ string
+ #f)
+ (filename #f #f string #f)
+ (build-whats #f #f symbol #f)))
+@end example
+@end defop
+
+@defop {Operation} {relational-database} delete-domain domain-name
+Removes and returns the @var{domain-name} row from the @dfn{domains}
+table.
+@end defop
+
+@defop {Operation} {relational-database} domain-checker domain
+Returns a procedure to check an argument for conformance to domain
+@var{domain}.
+@end defop
+
+
+@node Define-tables Example, The *commands* Table, Command Intrinsics, Embedded Commands
+@subsubsection Define-tables Example
+
+@noindent
+The following example shows a new database with the name of
+@file{foo.db} being created with tables describing processor families
+and processor/os/compiler combinations. The database is then
+solidified; saved and changed to immutable.
+
+@example
+(require 'databases)
+@ftindex databases
+(define my-rdb (create-database "foo.db" 'alist-table))
+(define-tables my-rdb
+ '(processor-family
+ ((family atom))
+ ((also-ran processor-family))
+ ((m68000 #f)
+ (m68030 m68000)
+ (i386 i8086)
+ (i8086 #f)
+ (powerpc #f)))
+
+ '(platform
+ ((name symbol))
+ ((processor processor-family)
+ (os symbol)
+ (compiler symbol))
+ ((aix powerpc aix -)
+ (amiga-dice-c m68000 amiga dice-c)
+ (amiga-aztec m68000 amiga aztec)
+ (amiga-sas/c-5.10 m68000 amiga sas/c)
+ (atari-st-gcc m68000 atari gcc)
+ (atari-st-turbo-c m68000 atari turbo-c)
+ (borland-c-3.1 i8086 ms-dos borland-c)
+ (djgpp i386 ms-dos gcc)
+ (linux i386 linux gcc)
+ (microsoft-c i8086 ms-dos microsoft-c)
+ (os/2-emx i386 os/2 gcc)
+ (turbo-c-2 i8086 ms-dos turbo-c)
+ (watcom-9.0 i386 ms-dos watcom))))
+
+(solidify-database my-rdb)
+@end example
+
+
+@node The *commands* Table, Command Service, Define-tables Example, Embedded Commands
+@subsubsection The *commands* Table
+
@noindent
The table @code{*commands*} in an @dfn{enhanced} relational-database has
the fields (with domains):
@@ -6417,7 +7100,7 @@ plain-text queries) can operate from the same table. A
@code{parameter-list} table has the following fields:
@example
@group
-PRI index uint
+PRI index ordinal
name symbol
arity parameter-arity
domain domain
@@ -6458,26 +7141,9 @@ Note that since the @code{defaulter} procedure is called every time a
default parameter is needed for this column, @dfn{sticky} defaults can
be implemented using shared state with the domain-integrity-rule.
-@subsubheading Invoking Commands
-When an enhanced relational-database is called with a symbol which
-matches a @var{name} in the @code{*commands*} table, the associated
-procedure expression is evaluated and applied to the enhanced
-relational-database. A procedure should then be returned which the user
-can invoke on (optional) arguments.
-
-The command @code{*initialize*} is special. If present in the
-@code{*commands*} table, @code{open-database} or @code{open-database!}
-will return the value of the @code{*initialize*} command. Notice that
-arbitrary code can be run when the @code{*initialize*} procedure is
-automatically applied to the enhanced relational-database.
-
-Note also that if you wish to shadow or hide from the user
-relational-database methods described in @ref{Relational Database
-Operations}, this can be done by a dispatch in the closure returned by
-the @code{*initialize*} expression rather than by entries in the
-@code{*commands*} table if it is desired that the underlying methods
-remain accessible to code in the @code{*commands*} table.
+@node Command Service, Command Example, The *commands* Table, Embedded Commands
+@subsubsection Command Service
@defun make-command-server rdb table-name
Returns a procedure of 2 arguments, a (symbol) command and a call-back
@@ -6518,21 +7184,31 @@ more than one alias per @var{parameter-name}.
@end table
@end defun
-For information about parameters, @xref{Parameter lists}. Here is an
-example of setting up a command with arguments and parsing those
-arguments from a @code{getopt} style argument list (@pxref{Getopt}).
+For information about parameters, @xref{Parameter lists}.
+
+
+@node Command Example, , Command Service, Embedded Commands
+@subsubsection Command Example
+
+Here is an example of setting up a command with arguments and parsing
+those arguments from a @code{getopt} style argument list
+(@pxref{Getopt}).
@example
-(require 'database-utilities)
-@ftindex database-utilities
-(require 'fluid-let)
-@ftindex fluid-let
+(require 'database-commands)
+@ftindex database-commands
+(require 'databases)
+@ftindex databases
+(require 'getopt-parameters)
+@ftindex getopt-parameters
(require 'parameters)
@ftindex parameters
(require 'getopt)
@ftindex getopt
+(require 'fluid-let)
+(require 'printf)
-(define my-rdb (create-database #f 'alist-table))
+(define my-rdb (add-command-tables (create-database #f 'alist-table)))
(define-tables my-rdb
'(foo-params
@@ -6544,13 +7220,13 @@ arguments from a @code{getopt} style argument list (@pxref{Getopt}).
(lambda (pl) '()) #f "zero or more symbols")
(3 nary1-symbols nary1 symbol
(lambda (pl) '(symb)) #f "one or more symbols")
- (4 optional-number optional uint
+ (4 optional-number optional ordinal
(lambda (pl) '()) #f "zero or one number")
(5 flag boolean boolean
(lambda (pl) '(#f)) #f "a boolean flag")))
'(foo-pnames
((name string))
- ((parameter-index uint))
+ ((parameter-index ordinal))
(("s" 1)
("single-string" 1)
("n" 2)
@@ -6573,15 +7249,13 @@ arguments from a @code{getopt} style argument list (@pxref{Getopt}).
(lambda (rdb) (lambda args (print args)))
"test command arguments"))))
-(define (dbutil:serve-command-line rdb command-table
- command argc argv)
- (set! argv (if (vector? argv) (vector->list argv) argv))
+(define (dbutil:serve-command-line rdb command-table command argv)
+ (set! *argv* (if (vector? argv) (vector->list argv) argv))
((make-command-server rdb command-table)
command
(lambda (comname comval options positions
arities types defaulters dirs aliases)
- (apply comval (getopt->arglist
- argc argv options positions
+ (apply comval (getopt->arglist options positions
arities types defaulters dirs aliases)))))
(define (cmd . opts)
@@ -6630,68 +7304,59 @@ Usage: cmd [OPTION ARGUMENT ...] ...
ERROR: getopt->parameter-list "unrecognized option" "-?"
@end example
-Some commands are defined in all extended relational-databases. The are
-called just like @ref{Relational Database Operations}.
-@defun add-domain domain-row
-Adds @var{domain-row} to the @dfn{domains} table if there is no row in
-the domains table associated with key @code{(car @var{domain-row})} and
-returns @code{#t}. Otherwise returns @code{#f}.
-For the fields and layout of the domain table, @xref{Catalog
-Representation}. Currently, these fields are
-@itemize @bullet
-@item
-domain-name
-@item
-foreign-table
-@item
-domain-integrity-rule
-@item
-type-id
-@item
-type-param
-@end itemize
+@node Database Macros, Database Browser, Embedded Commands, Relational Database
+@subsection Database Macros
-The following example adds 3 domains to the @samp{build} database.
-@samp{Optstring} is either a string or @code{#f}. @code{filename} is a
-string and @code{build-whats} is a symbol.
+@code{(require 'within-database)}
+
+The object-oriented programming interface to SLIB relational databases
+has failed to support clear, understandable, and modular code-writing
+for database applications.
+
+This seems to be a failure of the object-oriented paradigm where the
+type of an object is not manifest (or even traceable) in source code.
+
+@code{within-database}, along with the @samp{databases} package,
+reorganizes high-level database functions toward a more declarative
+style. Using this package, one can tag database table and command
+declarations for emacs:
@example
-(for-each (build 'add-domain)
- '((optstring #f
- (lambda (x) (or (not x) (string? x)))
- string
- #f)
- (filename #f #f string #f)
- (build-whats #f #f symbol #f)))
+etags -lscheme -r'/ *(define-\(command\|table\) (\([^; \t]+\)/\2/' \
+ source1.scm ...
@end example
-@end defun
-@defun delete-domain domain-name
-Removes and returns the @var{domain-name} row from the @dfn{domains}
-table.
-@end defun
+@menu
+* Within-database Example::
+@end menu
-@defun domain-checker domain
-Returns a procedure to check an argument for conformance to domain
-@var{domain}.
+@defun within-database database statement-1 @dots{}
+
+@code{within-database} creates a lexical scope in which the commands
+@code{define-table} and @code{define-command} create tables and
+@code{*commands*}-table entries respectively in open relational
+database @var{database}.
+
+@code{within-database} Returns @var{database}.
@end defun
-@subsubheading Defining Tables
+@deffn Syntax define-command (@r{<name>} @r{<rdb>}) @r{"comment"} @r{<expression1>} @r{<expression2>} @dots{}
+@deffnx Syntax define-command (@r{<name>} @r{<rdb>}) @r{<expression1>} @r{<expression2>} @dots{}
-@deffn Procedure define-tables rdb spec-0 @dots{}
-Adds tables as specified in @var{spec-0} @dots{} to the open
-relational-database @var{rdb}. Each @var{spec} has the form:
+Adds to the @code{*commands*} table a command
+@r{<name>}:
@lisp
-(@r{<name>} @r{<descriptor-name>} @r{<descriptor-name>} @r{<rows>})
-@end lisp
-or
-@lisp
-(@r{<name>} @r{<primary-key-fields>} @r{<other-fields>} @r{<rows>})
+(lambda (@r{<name>} @r{<rdb>}) @r{<expression1>} @r{<expression2>} @dots{})
@end lisp
+@end deffn
+
+@deffn Syntax define-table @r{<name>} @r{<descriptor-name>} @r{<descriptor-name>} @r{<rows>}
+@deffnx Syntax define-table @r{<name>} @r{<primary-key-fields>} @r{<other-fields>} @r{<rows>}
+
where @r{<name>} is the table name, @r{<descriptor-name>} is the symbol
name of a descriptor table, @r{<primary-key-fields>} and
@r{<other-fields>} describe the primary keys and other fields
@@ -6716,205 +7381,105 @@ an error).
If @r{<domain>} is not a defined domain name and it matches the name of
this table or an already defined (in one of @var{spec-0} @dots{}) single
-key field table, a foriegn-key domain will be created for it.
+key field table, a foreign-key domain will be created for it.
+
@end deffn
-@noindent
-The following example shows a new database with the name of
-@file{foo.db} being created with tables describing processor families
-and processor/os/compiler combinations.
+@node Within-database Example, , Database Macros, Database Macros
+@subsubsection Within-database Example
@noindent
-The database command @code{define-tables} is defined to call
-@code{define-tables} with its arguments. The database is also
-configured to print @samp{Welcome} when the database is opened. The
-database is then closed and reopened.
+Here is an example of @code{within-database} macros:
@example
-(require 'database-utilities)
-@ftindex database-utilities
-(define my-rdb (create-database "foo.db" 'alist-table))
-
-(define-tables my-rdb
- '(*commands*
- ((name symbol))
- ((parameters parameter-list)
- (procedure expression)
- (documentation string))
- ((define-tables
- no-parameters
- no-parameter-names
- (lambda (rdb) (lambda specs (apply define-tables rdb specs)))
- "Create or Augment tables from list of specs")
- (*initialize*
- no-parameters
- no-parameter-names
- (lambda (rdb) (display "Welcome") (newline) rdb)
- "Print Welcome"))))
-
-((my-rdb 'define-tables)
- '(processor-family
- ((family atom))
- ((also-ran processor-family))
- ((m68000 #f)
- (m68030 m68000)
- (i386 8086)
- (8086 #f)
- (powerpc #f)))
-
- '(platform
- ((name symbol))
- ((processor processor-family)
- (os symbol)
- (compiler symbol))
- ((aix powerpc aix -)
- (amiga-dice-c m68000 amiga dice-c)
+(require 'within-database)
+
+(define my-rdb
+ (add-command-tables
+ (create-database "foo.db" 'alist-table)))
+
+(within-database my-rdb
+ (define-command (*initialize* rdb)
+ "Print Welcome"
+ (display "Welcome")
+ (newline)
+ rdb)
+ (define-command (without-documentation rdb)
+ (display "without-documentation called")
+ (newline))
+ (define-table (processor-family
+ ((family atom))
+ ((also-ran processor-family)))
+ (m68000 #f)
+ (m68030 m68000)
+ (i386 i8086)
+ (i8086 #f)
+ (powerpc #f))
+ (define-table (platform
+ ((name symbol))
+ ((processor processor-family)
+ (os symbol)
+ (compiler symbol)))
+ (aix powerpc aix -)
+ ;; ...
(amiga-aztec m68000 amiga aztec)
(amiga-sas/c-5.10 m68000 amiga sas/c)
(atari-st-gcc m68000 atari gcc)
- (atari-st-turbo-c m68000 atari turbo-c)
- (borland-c-3.1 8086 ms-dos borland-c)
- (djgpp i386 ms-dos gcc)
- (linux i386 linux gcc)
- (microsoft-c 8086 ms-dos microsoft-c)
- (os/2-emx i386 os/2 gcc)
- (turbo-c-2 8086 ms-dos turbo-c)
- (watcom-9.0 i386 ms-dos watcom))))
-
-((my-rdb 'close-database))
-
-(set! my-rdb (open-database "foo.db" 'alist-table))
-@print{}
-Welcome
-@end example
-
-@subsubheading Listing Tables
+ ;; ...
+ (watcom-9.0 i386 ms-dos watcom))
+ (define-command (get-processor rdb)
+ "Get processor for given platform."
+ (((rdb 'open-table) 'platform #f) 'get 'processor)))
-@deffn Procedure list-table-definition rdb table-name
-If symbol @var{table-name} exists in the open relational-database
-@var{rdb}, then returns a list of the table-name, its primary key names
-and domains, its other key names and domains, and the table's records
-(as lists). Otherwise, returns #f.
-
-The list returned by @code{list-table-definition}, when passed as an
-argument to @code{define-tables}, will recreate the table.
-@end deffn
-
-
-@node Database Reports, Database Browser, Database Utilities, Relational Database
-@subsection Database Reports
-
-@noindent
-Code for generating database reports is in @file{report.scm}. After
-writing it using @code{format}, I discovered that Common-Lisp
-@code{format} is not useable for this application because there is no
-mechanismm for truncating fields. @file{report.scm} needs to be
-rewritten using @code{printf}.
-
-@deffn Procedure create-report rdb destination report-name table
-@deffnx Procedure create-report rdb destination report-name
-The symbol @var{report-name} must be primary key in the table named
-@code{*reports*} in the relational database @var{rdb}.
-@var{destination} is a port, string, or symbol. If @var{destination} is
-a:
-
-@table @asis
-@item port
-The table is created as ascii text and written to that port.
-@item string
-The table is created as ascii text and written to the file named by
-@var{destination}.
-@item symbol
-@var{destination} is the primary key for a row in the table named *printers*.
-@end table
-
-The report is prepared as follows:
-
-@itemize @bullet
-@item
-@code{Format} (@pxref{Format}) is called with the @code{header} field
-and the (list of) @code{column-names} of the table.
-@item
-@code{Format} is called with the @code{reporter} field and (on
-successive calls) each record in the natural order for the table. A
-count is kept of the number of newlines output by format. When the
-number of newlines to be output exceeds the number of lines per page,
-the set of lines will be broken if there are more than
-@code{minimum-break} left on this page and the number of lines for this
-row is larger or equal to twice @code{minimum-break}.
-@item
-@code{Format} is called with the @code{footer} field and the (list of)
-@code{column-names} of the table. The footer field should not output a
-newline.
-@item
-A new page is output.
-@item
-This entire process repeats until all the rows are output.
-@end itemize
-@end deffn
+(close-database my-rdb)
-Each row in the table *reports* has the fields:
+(set! my-rdb (open-command-database! "foo.db"))
+@print{}
+Welcome
-@table @asis
-@item name
-The report name.
-@item default-table
-The table to report on if none is specified.
-@item header, footer
-A @code{format} string. At the beginning and end of each page
-respectively, @code{format} is called with this string and the (list of)
-column-names of this table.
-@item reporter
-A @code{format} string. For each row in the table, @code{format} is
-called with this string and the row.
-@item minimum-break
-The minimum number of lines into which the report lines for a row can be
-broken. Use @code{0} if a row's lines should not be broken over page
-boundaries.
-@end table
+(my-rdb 'without-documentation)
+@print{}
+without-documentation called
-Each row in the table *printers* has the fields:
+((my-rdb 'get-processor) 'amiga-sas/c-5.10)
+@result{} m68000
-@table @asis
-@item name
-The printer name.
-@item print-procedure
-The procedure to call to actually print.
-@end table
+(close-database my-rdb)
+@end example
-@node Database Browser, , Database Reports, Relational Database
+@node Database Browser, , Database Macros, Relational Database
@subsection Database Browser
(require 'database-browse)
-@deffn Procedure browse database
+@deffn {Procedure} browse database
Prints the names of all the tables in @var{database} and sets browse's
default to @var{database}.
-@deffnx Procedure browse
+@deffnx {Procedure} browse
Prints the names of all the tables in the default database.
-@deffnx Procedure browse table-name
+@deffnx {Procedure} browse table-name
For each record of the table named by the symbol @var{table-name},
prints a line composed of all the field values.
-@deffnx Procedure browse pathname
+@deffnx {Procedure} browse pathname
Opens the database named by the string @var{pathname}, prints the names
of all its tables, and sets browse's default to the database.
-@deffnx Procedure browse database table-name
+@deffnx {Procedure} browse database table-name
Sets browse's default to @var{database} and prints the records of the
table named by the symbol @var{table-name}.
-@deffnx Procedure browse pathname table-name
+@deffnx {Procedure} browse pathname table-name
Opens the database named by the string @var{pathname} and sets browse's
default to it; @code{browse} prints the records of the table named by
@@ -6922,7 +7487,642 @@ the symbol @var{table-name}.
@end deffn
-@node Weight-Balanced Trees, , Relational Database, Database Packages
+
+@node Relational Infrastructure, Weight-Balanced Trees, Relational Database, Database Packages
+@section Relational Infrastructure
+
+
+@menu
+* Base Table::
+* Catalog Representation::
+* Relational Database Objects::
+* Database Operations::
+@end menu
+
+
+@node Base Table, Catalog Representation, Relational Infrastructure, Relational Infrastructure
+@subsection Base Table
+
+@cindex base-table
+A @dfn{base-table} is the primitive database layer upon which SLIB
+relational databases are built. At the minimum, it must support the
+types integer, symbol, string, and boolean. The base-table may restrict
+the size of integers, symbols, and strings it supports.
+
+A base table implementation is available as the value of the identifier
+naming it (eg. @var{alist-table}) after requiring the symbol of that
+name.
+
+@deftp {Feature} alist-table
+@code{(require 'alist-table)}
+@ftindex alist-table
+
+Association-list base tables support all Scheme types and are suitable
+for small databases. In order to be retrieved after being written to a
+file, the data stored should include only objects which are readable and
+writeable in the Scheme implementation.
+
+The @dfn{alist-table} base-table implementation is included in the
+SLIB distribution.
+@end deftp
+
+@dfn{WB} is a B-tree database package with SCM interfaces. Being
+disk-based, WB databases readily store and access hundreds of
+megabytes of data. WB comes with two base-table embeddings.
+
+@deftp {Feature} wb-table
+@code{(require 'wb-table)}
+@ftindex wb-table
+
+@cindex WB
+@code{wb-table} supports scheme expressions for keys and values whose
+text representations are less than 255 characters in length.
+@xref{wb-table, , , wb, WB}.
+@end deftp
+
+
+@deftp {Feature} rwb-isam
+@code{(require 'rwb-isam)}
+@ftindex rwb-isam
+
+@dfn{rwb-isam} is a sophisticated base-table implementation built on
+WB and SCM which uses binary numerical formats for key and non-key
+fields. It supports IEEE floating-point and fixed-precision integer
+keys with the correct numerical collation order.
+@end deftp
+
+This rest of this section documents the interface for a base table
+implementation from which the @ref{Relational Database} package
+constructs a Relational system. It will be of interest primarily to
+those wishing to port or write new base-table implementations.
+
+@defvar *base-table-implementations*
+To support automatic dispatch for @code{open-database}, each base-table
+module adds an association to @var{*base-table-implementations*} when
+loaded. This association is the list of the base-table symbol and the
+value returned by @code{(make-relational-system @var{base-table})}.
+@end defvar
+
+@menu
+* The Base::
+* Base Tables::
+* Base Field Types::
+* Composite Keys::
+* Base Record Operations::
+* Match Keys::
+* Aggregate Base Operations::
+* Base ISAM Operations::
+@end menu
+
+@node The Base, Base Tables, Base Table, Base Table
+@subsubsection The Base
+
+All of these functions are accessed through a single procedure by
+calling that procedure with the symbol name of the operation. A
+procedure will be returned if that operation is supported and @code{#f}
+otherwise. For example:
+
+@example
+@group
+(require 'alist-table)
+@ftindex alist-table
+@findex alist-table
+(define my-base (alist-table 'make-base))
+my-base @result{} *a procedure*
+(define foo (alist-table 'foo))
+foo @result{} #f
+@end group
+@end example
+
+@defop {Operation} {base-table} make-base filename key-dimension column-types
+Returns a new, open, low-level database (collection of tables)
+associated with @var{filename}. This returned database has an empty
+table associated with @var{catalog-id}. The positive integer
+@var{key-dimension} is the number of keys composed to make a
+@var{primary-key} for the catalog table. The list of symbols
+@var{column-types} describes the types of each column for that table.
+If the database cannot be created as specified, @code{#f} is returned.
+
+Calling the @code{close-base} method on this database and possibly other
+operations will cause @var{filename} to be written to. If
+@var{filename} is @code{#f} a temporary, non-disk based database will be
+created if such can be supported by the base table implelentation.
+@end defop
+
+@defop {Operation} {base-table} open-base filename mutable
+Returns an open low-level database associated with @var{filename}. If
+@var{mutable} is @code{#t}, this database will have methods capable of
+effecting change to the database. If @var{mutable} is @code{#f}, only
+methods for inquiring the database will be available. If the database
+cannot be opened as specified @code{#f} is returned.
+
+Calling the @code{close-base} (and possibly other) method on a
+@var{mutable} database will cause @var{filename} to be written to.
+@end defop
+
+@defop {Operation} {base-table} write-base lldb filename
+Causes the low-level database @var{lldb} to be written to
+@var{filename}. If the write is successful, also causes @var{lldb} to
+henceforth be associated with @var{filename}. Calling the
+@code{close-database} (and possibly other) method on @var{lldb} may
+cause @var{filename} to be written to. If @var{filename} is @code{#f}
+this database will be changed to a temporary, non-disk based database if
+such can be supported by the underlying base table implelentation. If
+the operations completed successfully, @code{#t} is returned.
+Otherwise, @code{#f} is returned.
+@end defop
+
+@defop {Operation} {base-table} sync-base lldb
+Causes the file associated with the low-level database @var{lldb} to be
+updated to reflect its current state. If the associated filename is
+@code{#f}, no action is taken and @code{#f} is returned. If this
+operation completes successfully, @code{#t} is returned. Otherwise,
+@code{#f} is returned.
+@end defop
+
+@defop {Operation} {base-table} close-base lldb
+Causes the low-level database @var{lldb} to be written to its associated
+file (if any). If the write is successful, subsequent operations to
+@var{lldb} will signal an error. If the operations complete
+successfully, @code{#t} is returned. Otherwise, @code{#f} is returned.
+@end defop
+
+
+@node Base Tables, Base Field Types, The Base, Base Table
+@subsubsection Base Tables
+
+@defop {Operation} {base-table} make-table lldb key-dimension column-types
+Returns the ordinal @var{base-id} for a new base table, otherwise
+returns @code{#f}. The base table can then be opened using
+@code{(open-table @var{lldb} @var{base-id})}. The positive integer
+@var{key-dimension} is the number of keys composed to make a
+@var{primary-key} for this table. The list of symbols
+@var{column-types} describes the types of each column.
+@end defop
+
+@defop {Operation} {base-table} open-table lldb base-id key-dimension column-types
+Returns a @var{handle} for an existing base table in the low-level
+database @var{lldb} if that table exists and can be opened in the mode
+indicated by @var{mutable}, otherwise returns @code{#f}.
+
+As with @code{make-table}, the positive integer @var{key-dimension} is
+the number of keys composed to make a @var{primary-key} for this table.
+The list of symbols @var{column-types} describes the types of each
+column.
+@end defop
+
+@defop {Operation} {base-table} kill-table lldb base-id key-dimension column-types
+Returns @code{#t} if the base table associated with @var{base-id} was
+removed from the low level database @var{lldb}, and @code{#f} otherwise.
+@end defop
+
+@defop {Operation} {base-table} catalog-id
+A constant @var{base-id} ordinal suitable for passing as a parameter to
+@code{open-table}. @var{catalog-id} will be used as the base table for
+the system catalog.
+@end defop
+
+
+@node Base Field Types, Composite Keys, Base Tables, Base Table
+@subsubsection Base Field Types
+
+@defop {Operation} {base-table} supported-type? symbol
+Returns @code{#t} if @var{symbol} names a type allowed as a column
+value by the implementation, and @code{#f} otherwise. At a minimum,
+an implementation must support the types @code{integer},
+@code{ordinal}, @code{symbol}, @code{string}, and @code{boolean}.
+@end defop
+
+@defop {Operation} {base-table} supported-key-type? symbol
+Returns @code{#t} if @var{symbol} names a type allowed as a key value
+by the implementation, and @code{#f} otherwise. At a minimum, an
+implementation must support the types @code{ordinal}, and
+@code{symbol}.
+@end defop
+
+@noindent
+An @dfn{ordinal} is an exact positive integer. The other types are
+standard Scheme.
+
+
+@node Composite Keys, Base Record Operations, Base Field Types, Base Table
+@subsubsection Composite Keys
+
+@defop {Operation} {base-table} make-keyifier-1 type
+Returns a procedure which accepts a single argument which must be of
+type @var{type}. This returned procedure returns an object suitable for
+being a @var{key} argument in the functions whose descriptions follow.
+
+Any 2 arguments of the supported type passed to the returned function
+which are not @code{equal?} must result in returned values which are not
+@code{equal?}.
+@end defop
+
+@defop {Operation} {base-table} make-list-keyifier key-dimension types
+The list of symbols @var{types} must have at least @var{key-dimension}
+elements. Returns a procedure which accepts a list of length
+@var{key-dimension} and whose types must corresopond to the types named
+by @var{types}. This returned procedure combines the elements of its
+list argument into an object suitable for being a @var{key} argument in
+the functions whose descriptions follow.
+
+Any 2 lists of supported types (which must at least include symbols and
+non-negative integers) passed to the returned function which are not
+@code{equal?} must result in returned values which are not
+@code{equal?}.
+@end defop
+
+@defop {Operation} {base-table} make-key-extractor key-dimension types column-number
+Returns a procedure which accepts objects produced by application of the
+result of @code{(make-list-keyifier @var{key-dimension} @var{types})}.
+This procedure returns a @var{key} which is @code{equal?} to the
+@var{column-number}th element of the list which was passed to create
+@var{composite-key}. The list @var{types} must have at least
+@var{key-dimension} elements.
+@end defop
+
+@defop {Operation} {base-table} make-key->list key-dimension types
+Returns a procedure which accepts objects produced by application of
+the result of @code{(make-list-keyifier @var{key-dimension}
+@var{types})}. This procedure returns a list of @var{key}s which are
+elementwise @code{equal?} to the list which was passed to create
+@var{composite-key}.
+@end defop
+
+
+@node Base Record Operations, Match Keys, Composite Keys, Base Table
+@subsubsection Base Record Operations
+
+@noindent
+In the following functions, the @var{key} argument can always be assumed
+to be the value returned by a call to a @emph{keyify} routine.
+
+@defop {Operation} {base-table} present? handle key
+Returns a non-@code{#f} value if there is a row associated with
+@var{key} in the table opened in @var{handle} and @code{#f} otherwise.
+@end defop
+
+@defop {Operation} {base-table} make-getter key-dimension types
+Returns a procedure which takes arguments @var{handle} and @var{key}.
+This procedure returns a list of the non-primary values of the relation
+(in the base table opened in @var{handle}) whose primary key is
+@var{key} if it exists, and @code{#f} otherwise.
+@end defop
+
+@noindent
+@code{make-getter-1} is a new operation. The relational-database
+module works with older base-table implementations by using
+@code{make-getter}.
+
+@defop {Operation} {base-table} make-getter-1 key-dimension types index
+Returns a procedure which takes arguments @var{handle} and @var{key}.
+This procedure returns the value of the @var{index}th field (in the
+base table opened in @var{handle}) whose primary key is @var{key} if
+it exists, and @code{#f} otherwise.
+
+@var{index} must be larger than @var{key-dimension}.
+@end defop
+
+@defop {Operation} {base-table} make-putter key-dimension types
+Returns a procedure which takes arguments @var{handle} and @var{key} and
+@var{value-list}. This procedure associates the primary key @var{key}
+with the values in @var{value-list} (in the base table opened in
+@var{handle}) and returns an unspecified value.
+@end defop
+
+@defop {Operation} {base-table} delete handle key
+Removes the row associated with @var{key} from the table opened in
+@var{handle}. An unspecified value is returned.
+@end defop
+
+
+@node Match Keys, Aggregate Base Operations, Base Record Operations, Base Table
+@subsubsection Match Keys
+
+@noindent
+@cindex match-keys
+@cindex match
+@cindex wild-card
+A @var{match-keys} argument is a list of length equal to
+the number of primary keys. The @var{match-keys} restrict the actions
+of the table command to those records whose primary keys all satisfy the
+corresponding element of the @var{match-keys} list. The elements and
+their actions are:
+
+@quotation
+@table @asis
+@item @code{#f}
+The false value matches any key in the corresponding position.
+@item an object of type procedure
+This procedure must take a single argument, the key in the corresponding
+position. Any key for which the procedure returns a non-false value is
+a match; Any key for which the procedure returns a @code{#f} is not.
+@item other values
+Any other value matches only those keys @code{equal?} to it.
+@end table
+@end quotation
+
+
+@node Aggregate Base Operations, Base ISAM Operations, Match Keys, Base Table
+@subsubsection Aggregate Base Operations
+
+@noindent
+The @var{key-dimension} and @var{column-types} arguments are needed to
+decode the composite-keys for matching with @var{match-keys}.
+
+@defop {Operation} {base-table} delete* handle key-dimension column-types match-keys
+Removes all rows which satisfy @var{match-keys} from the table opened in
+@var{handle}. An unspecified value is returned.
+@end defop
+
+@defop {Operation} {base-table} for-each-key handle procedure key-dimension column-types match-keys
+Calls @var{procedure} once with each @var{key} in the table opened in
+@var{handle} which satisfy @var{match-keys} in an unspecified order.
+An unspecified value is returned.
+@end defop
+
+@defop {Operation} {base-table} map-key handle procedure key-dimension column-types match-keys
+Returns a list of the values returned by calling @var{procedure} once
+with each @var{key} in the table opened in @var{handle} which satisfy
+@var{match-keys} in an unspecified order.
+@end defop
+
+
+@node Base ISAM Operations, , Aggregate Base Operations, Base Table
+@subsubsection Base ISAM Operations
+
+@noindent
+These operations are optional for a Base-Table implementation.
+
+@defop {Operation} {base-table} ordered-for-each-key handle procedure key-dimension column-types match-keys
+Calls @var{procedure} once with each @var{key} in the table opened in
+@var{handle} which satisfy @var{match-keys} in the natural order for
+the types of the primary key fields of that table. An unspecified value
+is returned.
+@end defop
+
+@defop {Operation} {base-table} make-nexter handle key-dimension column-types index
+Returns a procedure of arguments @var{key1} @var{key2} @dots{} which
+returns the key-list identifying the lowest record higher than
+@var{key1} @var{key2} @dots{} which is stored in the base-table and
+which differs in column @var{index} or a lower indexed key; or false
+if no higher record is present.
+@end defop
+
+@defop {Operation} {base-table} make-prever handle key-dimension column-types index
+Returns a procedure of arguments @var{key1} @var{key2} @dots{} which
+returns the key-list identifying the highest record less than
+@var{key1} @var{key2} @dots{} which is stored in the base-table and
+which differs in column @var{index} or a lower indexed key; or false
+if no higher record is present.
+@end defop
+
+@node Catalog Representation, Relational Database Objects, Base Table, Relational Infrastructure
+@subsection Catalog Representation
+
+@noindent
+Each database (in an implementation) has a @dfn{system catalog} which
+describes all the user accessible tables in that database (including
+itself).
+
+@noindent
+The system catalog base table has the following fields. @code{PRI}
+indicates a primary key for that table.
+
+@example
+@group
+PRI table-name
+ column-limit the highest column number
+ coltab-name descriptor table name
+ bastab-id data base table identifier
+ user-integrity-rule
+ view-procedure A scheme thunk which, when called,
+ produces a handle for the view. coltab
+ and bastab are specified if and only if
+ view-procedure is not.
+@end group
+@end example
+
+@noindent
+Descriptors for base tables (not views) are tables (pointed to by
+system catalog). Descriptor (base) tables have the fields:
+
+@example
+@group
+PRI column-number sequential integers from 1
+ primary-key? boolean TRUE for primary key components
+ column-name
+ column-integrity-rule
+ domain-name
+@end group
+@end example
+
+@noindent
+A @dfn{primary key} is any column marked as @code{primary-key?} in the
+corresponding descriptor table. All the @code{primary-key?} columns
+must have lower column numbers than any non-@code{primary-key?} columns.
+Every table must have at least one primary key. Primary keys must be
+sufficient to distinguish all rows from each other in the table. All of
+the system defined tables have a single primary key.
+
+@noindent
+A @dfn{domain} is a category describing the allowable values to occur in
+a column. It is described by a (base) table with the fields:
+
+@example
+@group
+PRI domain-name
+ foreign-table
+ domain-integrity-rule
+ type-id
+ type-param
+@end group
+@end example
+
+@noindent
+The @dfn{type-id} field value is a symbol. This symbol may be used by
+the underlying base table implementation in storing that field.
+
+@noindent
+If the @code{foreign-table} field is non-@code{#f} then that field names
+a table from the catalog. The values for that domain must match a
+primary key of the table referenced by the @var{type-param} (or
+@code{#f}, if allowed). This package currently does not support
+composite foreign-keys.
+
+@noindent
+The types for which support is planned are:
+@example
+@group
+ atom
+ symbol
+ string [<length>]
+ number [<base>]
+ money <currency>
+ date-time
+ boolean
+
+ foreign-key <table-name>
+ expression
+ virtual <expression>
+@end group
+@end example
+
+
+@node Relational Database Objects, Database Operations, Catalog Representation, Relational Infrastructure
+@subsection Relational Database Objects
+
+@noindent
+This object-oriented interface is deprecated for typical database
+applications; @ref{Using Databases} provides an application programmer
+interface which is easier to understand and use.
+
+@defun make-relational-system base-table-implementation
+
+Returns a procedure implementing a relational database using the
+@var{base-table-implementation}.
+
+All of the operations of a base table implementation are accessed
+through a procedure defined by @code{require}ing that implementation.
+Similarly, all of the operations of the relational database
+implementation are accessed through the procedure returned by
+@code{make-relational-system}. For instance, a new relational database
+could be created from the procedure returned by
+@code{make-relational-system} by:
+
+@example
+(require 'alist-table)
+@ftindex alist-table
+(define relational-alist-system
+ (make-relational-system alist-table))
+(define create-alist-database
+ (relational-alist-system 'create-database))
+(define my-database
+ (create-alist-database "mydata.db"))
+@end example
+@end defun
+
+@noindent
+What follows are the descriptions of the methods available from
+relational system returned by a call to @code{make-relational-system}.
+
+@defop {Operation} {relational-system} create-database filename
+
+Returns an open, nearly empty relational database associated with
+@var{filename}. The only tables defined are the system catalog and
+domain table. Calling the @code{close-database} method on this database
+and possibly other operations will cause @var{filename} to be written
+to. If @var{filename} is @code{#f} a temporary, non-disk based database
+will be created if such can be supported by the underlying base table
+implelentation. If the database cannot be created as specified
+@code{#f} is returned. For the fields and layout of descriptor tables,
+@ref{Catalog Representation}
+@end defop
+
+@defop {Operation} {relational-system} open-database filename mutable?
+
+Returns an open relational database associated with @var{filename}. If
+@var{mutable?} is @code{#t}, this database will have methods capable of
+effecting change to the database. If @var{mutable?} is @code{#f}, only
+methods for inquiring the database will be available. Calling the
+@code{close-database} (and possibly other) method on a @var{mutable?}
+database will cause @var{filename} to be written to. If the database
+cannot be opened as specified @code{#f} is returned.
+@end defop
+
+
+@node Database Operations, , Relational Database Objects, Relational Infrastructure
+@subsection Database Operations
+
+@noindent
+This object-oriented interface is deprecated for typical database
+applications; @ref{Using Databases} provides an application programmer
+interface which is easier to understand and use.
+
+@noindent
+These are the descriptions of the methods available from an open
+relational database. A method is retrieved from a database by calling
+the database with the symbol name of the operation. For example:
+
+@example
+(define my-database
+ (create-alist-database "mydata.db"))
+(define telephone-table-desc
+ ((my-database 'create-table) 'telephone-table-desc))
+@end example
+
+@defop {Operation} {relational-database} close-database
+Causes the relational database to be written to its associated file (if
+any). If the write is successful, subsequent operations to this
+database will signal an error. If the operations completed
+successfully, @code{#t} is returned. Otherwise, @code{#f} is returned.
+@end defop
+
+@defop {Operation} {relational-database} write-database filename
+Causes the relational database to be written to @var{filename}. If the
+write is successful, also causes the database to henceforth be
+associated with @var{filename}. Calling the @code{close-database} (and
+possibly other) method on this database will cause @var{filename} to be
+written to. If @var{filename} is @code{#f} this database will be
+changed to a temporary, non-disk based database if such can be supported
+by the underlying base table implelentation. If the operations
+completed successfully, @code{#t} is returned. Otherwise, @code{#f} is
+returned.
+@end defop
+
+@defop {Operation} {relational-database} sync-database
+Causes any pending updates to the database file to be written out. If
+the operations completed successfully, @code{#t} is returned.
+Otherwise, @code{#f} is returned.
+@end defop
+
+@defop {Operation} {relational-database} solidify-database
+Causes any pending updates to the database file to be written out. If
+the writes completed successfully, then the database is changed to be
+immutable and @code{#t} is returned. Otherwise, @code{#f} is returned.
+@end defop
+
+@defop {Operation} {relational-database} table-exists? table-name
+Returns @code{#t} if @var{table-name} exists in the system catalog,
+otherwise returns @code{#f}.
+@end defop
+
+@defop {Operation} {relational-database} open-table table-name mutable?
+Returns a @dfn{methods} procedure for an existing relational table in
+this database if it exists and can be opened in the mode indicated by
+@var{mutable?}, otherwise returns @code{#f}.
+@end defop
+
+@noindent
+These methods will be present only in mutable databases.
+
+@defop {Operation} {relational-database} delete-table table-name
+Removes and returns the @var{table-name} row from the system catalog if
+the table or view associated with @var{table-name} gets removed from the
+database, and @code{#f} otherwise.
+@end defop
+
+@defop {Operation} {relational-database} create-table table-desc-name
+Returns a methods procedure for a new (open) relational table for
+describing the columns of a new base table in this database, otherwise
+returns @code{#f}. For the fields and layout of descriptor tables,
+@xref{Catalog Representation}.
+
+@defopx {Operation} {relational-database} create-table table-name table-desc-name
+Returns a methods procedure for a new (open) relational table with
+columns as described by @var{table-desc-name}, otherwise returns
+@code{#f}.
+@end defop
+
+@defop {Operation} {relational-database} create-view ??
+@defopx {Operation} {relational-database} project-table ??
+@defopx {Operation} {relational-database} restrict-table ??
+@defopx {Operation} {relational-database} cart-prod-tables ??
+Not yet implemented.
+@end defop
+
+
+@node Weight-Balanced Trees, , Relational Infrastructure, Database Packages
@section Weight-Balanced Trees
@code{(require 'wt-tree)}
@@ -7013,7 +8213,7 @@ To use weight balanced trees, execute
@example
(load-option 'wt-tree)
@end example
-@findex load-option
+@ftindex load-option
@noindent
once before calling any of the procedures defined here.
@@ -7126,10 +8326,10 @@ trees. These operations are the usual tree operations for insertion,
deletion and lookup, some predicates and a procedure for determining the
number of associations in a tree.
-@deffn {procedure+} wt-tree? object
-Returns @code{#t} if @var{object} is a weight-balanced tree, otherwise
-returns @code{#f}.
-@end deffn
+@c @deffn {procedure+} wt-tree? object
+@c Returns @code{#t} if @var{object} is a weight-balanced tree, otherwise
+@c returns @code{#f}.
+@c @end deffn
@deffn {procedure+} wt-tree/empty? wt-tree
Returns @code{#t} if @var{wt-tree} contains no associations, otherwise
@@ -7366,15 +8566,13 @@ number of associations in the tree.
Indexing can be used to find the median and maximum keys in the tree as
follows:
+@end deffn
@example
-median: (wt-tree/index @var{wt-tree}
- (quotient (wt-tree/size @var{wt-tree}) 2))
+median: (wt-tree/index @var{wt-tree} (quotient (wt-tree/size @var{wt-tree}) 2))
-maximum: (wt-tree/index @var{wt-tree}
- (-1+ (wt-tree/size @var{wt-tree})))
+maximum: (wt-tree/index @var{wt-tree} (-1+ (wt-tree/size @var{wt-tree})))
@end example
-@end deffn
@deffn {procedure+} wt-tree/rank wt-tree key
Determines the 0-based position of @var{key} in the sorted sequence of
@@ -7441,7 +8639,8 @@ operation is equivalent to
* Procedures:: Miscellaneous utility procedures.
* Standards Support:: Support for Scheme Standards.
* Session Support:: REPL and Debugging.
-* Extra-SLIB Packages::
+* System Interface:: 'system, 'getenv, and other programs.
+* Extra-SLIB Packages:: Outside the envelope.
@end menu
@@ -7452,14 +8651,16 @@ operation is equivalent to
@menu
* Arrays:: 'array
+* Subarrays:: 'subarray
* Array Mapping:: 'array-for-each
* Association Lists:: 'alist
* Byte:: 'byte
+* Byte/Number Conversions:: 'byte-number
+* MAT-File Format:: 'matfile
* Portable Image Files:: 'pnm
* Collections:: 'collect
* Dynamic Data Type:: 'dynamic
* Hash Tables:: 'hash-table
-* Hashing:: 'hash, 'sierpinski, 'soundex
* Object:: 'object
* Priority Queues:: 'priority-queue
* Queues:: 'queue
@@ -7469,277 +8670,52 @@ operation is equivalent to
-@node Arrays, Array Mapping, Data Structures, Data Structures
+@node Arrays, Subarrays, Data Structures, Data Structures
@subsection Arrays
@include array.txi
-@node Array Mapping, Association Lists, Arrays, Data Structures
-@subsection Array Mapping
+@node Subarrays, Array Mapping, Arrays, Data Structures
+@subsection Subarrays
-@code{(require 'array-for-each)}
-@ftindex array-for-each
+@include subarray.txi
-@defun array-map! array0 proc array1 @dots{}
-@var{array1}, @dots{} must have the same number of dimensions as
-@var{array0} and have a range for each index which includes the range
-for the corresponding index in @var{array0}. @var{proc} is applied to
-each tuple of elements of @var{array1} @dots{} and the result is stored
-as the corresponding element in @var{array0}. The value returned is
-unspecified. The order of application is unspecified.
-@end defun
-@defun array-for-each @var{proc} @var{array0} @dots{}
-@var{proc} is applied to each tuple of elements of @var{array0} @dots{}
-in row-major order. The value returned is unspecified.
-@end defun
-
-@defun array-indexes @var{array}
-Returns an array of lists of indexes for @var{array} such that, if
-@var{li} is a list of indexes for which @var{array} is defined, (equal?
-@var{li} (apply array-ref (array-indexes @var{array}) @var{li})).
-@end defun
-
-@defun array-index-map! array proc
-applies @var{proc} to the indices of each element of @var{array} in
-turn, storing the result in the corresponding element. The value
-returned and the order of application are unspecified.
-
-One can implement @var{array-indexes} as
-@example
-(define (array-indexes array)
- (let ((ra (apply make-array #f (array-shape array))))
- (array-index-map! ra (lambda x x))
- ra))
-@end example
-Another example:
-@example
-(define (apl:index-generator n)
- (let ((v (make-uniform-vector n 1)))
- (array-index-map! v (lambda (i) i))
- v))
-@end example
-@end defun
+@node Array Mapping, Association Lists, Subarrays, Data Structures
+@subsection Array Mapping
-@defun array-copy! source destination
-Copies every element from vector or array @var{source} to the
-corresponding element of @var{destination}. @var{destination} must have
-the same rank as @var{source}, and be at least as large in each
-dimension. The order of copying is unspecified.
-@end defun
+@include arraymap.txi
@node Association Lists, Byte, Array Mapping, Data Structures
@subsection Association Lists
-@code{(require 'alist)}
-@ftindex alist
-
-Alist functions provide utilities for treating a list of key-value pairs
-as an associative database. These functions take an equality predicate,
-@var{pred}, as an argument. This predicate should be repeatable,
-symmetric, and transitive.
+@include alist.txi
-Alist functions can be used with a secondary index method such as hash
-tables for improved performance.
-@defun predicate->asso pred
-Returns an @dfn{association function} (like @code{assq}, @code{assv}, or
-@code{assoc}) corresponding to @var{pred}. The returned function
-returns a key-value pair whose key is @code{pred}-equal to its first
-argument or @code{#f} if no key in the alist is @var{pred}-equal to the
-first argument.
-@end defun
-
-@defun alist-inquirer pred
-Returns a procedure of 2 arguments, @var{alist} and @var{key}, which
-returns the value associated with @var{key} in @var{alist} or @code{#f} if
-@var{key} does not appear in @var{alist}.
-@end defun
-
-@defun alist-associator pred
-Returns a procedure of 3 arguments, @var{alist}, @var{key}, and
-@var{value}, which returns an alist with @var{key} and @var{value}
-associated. Any previous value associated with @var{key} will be
-lost. This returned procedure may or may not have side effects on its
-@var{alist} argument. An example of correct usage is:@refill
-@lisp
-(define put (alist-associator string-ci=?))
-(define alist '())
-(set! alist (put alist "Foo" 9))
-@end lisp
-@end defun
-
-@defun alist-remover pred
-Returns a procedure of 2 arguments, @var{alist} and @var{key}, which
-returns an alist with an association whose @var{key} is key removed.
-This returned procedure may or may not have side effects on its
-@var{alist} argument. An example of correct usage is:@refill
-@lisp
-(define rem (alist-remover string-ci=?))
-(set! alist (rem alist "foo"))
-@end lisp
-@end defun
-
-@defun alist-map proc alist
-Returns a new association list formed by mapping @var{proc} over the
-keys and values of @var{alist}. @var{proc} must be a function of 2
-arguments which returns the new value part.
-@end defun
-
-@defun alist-for-each proc alist
-Applies @var{proc} to each pair of keys and values of @var{alist}.
-@var{proc} must be a function of 2 arguments. The returned value is
-unspecified.
-@end defun
-
-@node Byte, Portable Image Files, Association Lists, Data Structures
+@node Byte, Byte/Number Conversions, Association Lists, Data Structures
@subsection Byte
-@code{(require 'byte)}
-
-Some algorithms are expressed in terms of arrays of small integers.
-Using Scheme strings to implement these arrays is not portable vis-a-vis
-the correspondence between integers and characters and non-ascii
-character sets. These functions abstract the notion of a @dfn{byte}.
-@cindex byte
-
-@deffn Function byte-ref bytes k
-@var{k} must be a valid index of @var{bytes}. @code{byte-ref} returns
-byte @var{k} of @var{bytes} using zero-origin indexing.
-@findex byte-ref
-@end deffn
-
-@deffn Procedure byte-set! bytes k byte
-@var{k} must be a valid index of @var{bytes}%, and @var{byte} must be a
-small integer. @code{Byte-set!} stores @var{byte} in element @var{k}
-of @var{bytes}
-@findex byte-set!
-and returns an unspecified value. @c <!>
+@include byte.txi
-@end deffn
-
-@deffn Function make-bytes k
-@deffnx Function make-bytes k byte
-
-@code{Make-bytes} returns a newly allocated byte-array of
-@findex make-bytes
-length @var{k}. If @var{byte} is given, then all elements of the
-byte-array are initialized to @var{byte}, otherwise the contents of the
-byte-array are unspecified.
-@end deffn
-
-@deffn Function bytes-length bytes
+@node Byte/Number Conversions, MAT-File Format, Byte, Data Structures
+@subsection Byte/Number Conversions
-@code{bytes-length} returns length of byte-array @var{bytes}.
-@findex bytes-length
+@include bytenumb.txi
-@end deffn
-@deffn Function write-byte byte
-@deffnx Function write-byte byte port
+@node MAT-File Format, Portable Image Files, Byte/Number Conversions, Data Structures
+@subsection MAT-File Format
-Writes the byte @var{byte} (not an external representation of the
-byte) to the given @var{port} and returns an unspecified value. The
-@var{port} argument may be omitted, in which case it defaults to the value
-returned by @code{current-output-port}.
-@findex current-output-port
+@include matfile.txi
-@end deffn
-
-@deffn Function read-byte
-@deffnx Function read-byte port
-
-Returns the next byte available from the input @var{port}, updating
-the @var{port} to point to the following byte. If no more bytes
-are available, an end of file object is returned. @var{Port} may be
-omitted, in which case it defaults to the value returned by
-@code{current-input-port}.
-@findex current-input-port
-
-@end deffn
-
-@deffn Function bytes byte @dots{}
-
-Returns a newly allocated byte-array composed of the arguments.
-
-@end deffn
-
-@deffn Function bytes->list bytes
-@deffnx Function list->bytes bytes
-
-@code{Bytes->list} returns a newly allocated list of the
-@findex bytes->list
-bytes that make up the given byte-array. @code{List->bytes}
-@findex list->bytes
-returns a newly allocated byte-array formed from the small integers in
-the list @var{bytes}. @code{Bytes->list} and @code{list->bytes} are
-@findex list->bytes
-@findex bytes->list
-inverses so far as @code{equal?} is concerned.
-@findex equal?
-
-@end deffn
-@node Portable Image Files, Collections, Byte, Data Structures
+@node Portable Image Files, Collections, MAT-File Format, Data Structures
@subsection Portable Image Files
-@code{(require 'pnm)}
-
-@deffn Function pnm:type-dimensions path
-The string @var{path} must name a @dfn{portable bitmap graphics} file.
-@code{pnm:type-dimensions} returns a list of 4 items:
-@enumerate
-@item
-A symbol describing the type of the file named by @var{path}.
-@item
-The image width in pixels.
-@item
-The image height in pixels.
-@item
-The maximum value of pixels assume in the file.
-@end enumerate
-
-The current set of file-type symbols is:
-@table @asis
-@item pbm
-@itemx pbm-raw
-Black-and-White image; pixel values are 0 or 1.
-@item pgm
-@itemx pgm-raw
-Gray (monochrome) image; pixel values are from 0 to @var{maxval}
-specified in file header.
-@item ppm
-@itemx ppm-raw
-RGB (full color) image; red, green, and blue interleaved pixel values
-are from 0 to @var{maxval}
-@end table
-
-@end deffn
-
-@deffn Function pnm:image-file->array path array
-
-Reads the @dfn{portable bitmap graphics} file named by @var{path} into
-@var{array}. @var{array} must be the correct size and type for
-@var{path}. @var{array} is returned.
-
-@deffnx Function pnm:image-file->array path
-
-@code{pnm:image-file->array} creates and returns an array with the
-@dfn{portable bitmap graphics} file named by @var{path} read into it.
-
-@end deffn
-
-@deffn Procedure pnm:array-write type array maxval path
-
-Writes the contents of @var{array} to a @var{type} image file named
-@var{path}. The file will have pixel values between 0 and @var{maxval},
-which must be compatible with @var{type}. For @samp{pbm} files,
-@var{maxval} must be @samp{1}.
-
-@end deffn
+@include pnm.txi
@node Collections, Dynamic Data Type, Portable Image Files, Data Structures
@@ -7752,14 +8728,17 @@ which must be compatible with @var{type}. For @samp{pbm} files,
@code{(require 'collect)}
@ftindex collect
+@noindent
Routines for managing collections. Collections are aggregate data
structures supporting iteration over their elements, similar to the
Dylan(TM) language, but with a different interface. They have
@dfn{elements} indexed by corresponding @dfn{keys}, although the keys
may be implicit (as with lists).
+@noindent
New types of collections may be defined as YASOS objects (@pxref{Yasos}).
They must support the following operations:
+
@itemize @bullet
@item
@code{(collection? @var{self})} (always returns @code{#t});
@@ -7770,28 +8749,33 @@ They must support the following operations:
@item
@code{(print @var{self} @var{port})} is a specialized print operation
for the collection which prints a suitable representation on the given
-@var{port} or returns it as a string if @var{port} is @code{#t};@refill
+@var{port} or returns it as a string if @var{port} is @code{#t};
@item
+@findex gen-elts
@code{(gen-elts @var{self})} returns a thunk which on successive
invocations yields elements of @var{self} in order or gives an error if
-it is invoked more than @code{(size @var{self})} times;@refill
+it is invoked more than @code{(size @var{self})} times;
@item
+@findex gen-keys
@code{(gen-keys @var{self})} is like @code{gen-elts}, but yields the
collection's keys in order.
-
@end itemize
+
+@noindent
They might support specialized @code{for-each-key} and
@code{for-each-elt} operations.
+
+
@defun collection? obj
A predicate, true initially of lists, vectors and strings. New sorts of
collections must answer @code{#t} to @code{collection?}.
@end defun
-@deffn Procedure map-elts proc collection1 @dots{}
-@deffnx Procedure do-elts proc collection1 @dots{}
+@deffn {Procedure} map-elts proc collection1 @dots{}
+@deffnx {Procedure} do-elts proc collection1 @dots{}
@var{proc} is a procedure taking as many arguments as there are
@var{collections} (at least one). The @var{collections} are iterated
over in their natural order and @var{proc} is applied to the elements
@@ -7809,8 +8793,8 @@ Example:
@end lisp
@end deffn
-@deffn Procedure map-keys proc collection1 @dots{}
-@deffnx Procedure do-keys proc collection1 @dots{}
+@deffn {Procedure} map-keys proc collection1 @dots{}
+@deffnx {Procedure} do-keys proc collection1 @dots{}
These are analogous to @code{map-elts} and @code{do-elts}, but each
iteration is over the @var{collections}' @emph{keys} rather than their
elements.
@@ -7822,14 +8806,14 @@ Example:
@end lisp
@end deffn
-@deffn Procedure for-each-key collection proc
-@deffnx Procedure for-each-elt collection proc
+@deffn {Procedure} for-each-key collection proc
+@deffnx {Procedure} for-each-elt collection proc
These are like @code{do-keys} and @code{do-elts} but only for a single
collection; they are potentially more efficient.
@end deffn
@defun reduce proc seed collection1 @dots{}
-A generalization of the list-based @code{comlist:reduce-init}
+A generalization of the list-based @code{reduce-init}
(@pxref{Lists as sequences}) to collections which will shadow the
list-based version if @code{(require 'collect)} follows
@ftindex collect
@@ -7858,8 +8842,8 @@ Example:
@end defun
@defun every? pred collection1 @dots{}
-A generalization of the list-based @code{every} (@pxref{Lists as
-sequences}) to collections.
+A generalization of the list-based @code{every}
+(@pxref{Lists as sequences}) to collections.
Example:
@lisp
@@ -7934,6 +8918,7 @@ Here is a sample collection: @code{simple-table} which is also a
(loop (cdr last) (cdr this)))
) ) )
))
+@group
;; collection behaviors
((COLLECTION? self) #t)
((GEN-KEYS self) (collect:list-gen-elts (map car table)))
@@ -7943,8 +8928,8 @@ Here is a sample collection: @code{simple-table} which is also a
)
((FOR-EACH-ELT self proc)
(for-each (lambda (bucket) (proc (cdr bucket))) table)
- )
- ) ) )
+ ) ) ) )
+@end group
@end lisp
@@ -7972,7 +8957,7 @@ Return the value of the given dynamic in the current dynamic
environment.
@end defun
-@deffn Procedure dynamic-set! dyn obj
+@deffn {Procedure} dynamic-set! dyn obj
Change the value of the given dynamic to @var{obj} in the current
dynamic environment. The returned value is unspecified.
@end deffn
@@ -7991,297 +8976,29 @@ The @code{dynamic-bind} macro is not implemented.
-@node Hash Tables, Hashing, Dynamic Data Type, Data Structures
+@node Hash Tables, Object, Dynamic Data Type, Data Structures
@subsection Hash Tables
-@code{(require 'hash-table)}
-@ftindex hash-table
-
-@defun predicate->hash pred
-Returns a hash function (like @code{hashq}, @code{hashv}, or
-@code{hash}) corresponding to the equality predicate @var{pred}.
-@var{pred} should be @code{eq?}, @code{eqv?}, @code{equal?}, @code{=},
-@code{char=?}, @code{char-ci=?}, @code{string=?}, or
-@code{string-ci=?}.
-@end defun
-
-A hash table is a vector of association lists.
-
-@defun make-hash-table k
-Returns a vector of @var{k} empty (association) lists.
-@end defun
-
-Hash table functions provide utilities for an associative database.
-These functions take an equality predicate, @var{pred}, as an argument.
-@var{pred} should be @code{eq?}, @code{eqv?}, @code{equal?}, @code{=},
-@code{char=?}, @code{char-ci=?}, @code{string=?}, or
-@code{string-ci=?}.
-
-@defun predicate->hash-asso pred
-Returns a hash association function of 2 arguments, @var{key} and
-@var{hashtab}, corresponding to @var{pred}. The returned function
-returns a key-value pair whose key is @var{pred}-equal to its first
-argument or @code{#f} if no key in @var{hashtab} is @var{pred}-equal to
-the first argument.
-@end defun
-
-@defun hash-inquirer pred
-Returns a procedure of 2 arguments, @var{hashtab} and @var{key}, which
-returns the value associated with @var{key} in @var{hashtab} or
-@code{#f} if @var{key} does not appear in @var{hashtab}.
-@end defun
-
-@defun hash-associator pred
-Returns a procedure of 3 arguments, @var{hashtab}, @var{key}, and
-@var{value}, which modifies @var{hashtab} so that @var{key} and
-@var{value} associated. Any previous value associated with @var{key}
-will be lost.
-@end defun
-
-@defun hash-remover pred
-Returns a procedure of 2 arguments, @var{hashtab} and @var{key}, which
-modifies @var{hashtab} so that the association whose key is @var{key} is
-removed.
-@end defun
-
-@defun hash-map proc hash-table
-Returns a new hash table formed by mapping @var{proc} over the
-keys and values of @var{hash-table}. @var{proc} must be a function of 2
-arguments which returns the new value part.
-@end defun
-
-@defun hash-for-each proc hash-table
-Applies @var{proc} to each pair of keys and values of @var{hash-table}.
-@var{proc} must be a function of 2 arguments. The returned value is
-unspecified.
-@end defun
-
-
-
-
-
-@node Hashing, Object, Hash Tables, Data Structures
-@subsection Hashing
-
-@code{(require 'hash)}
-@ftindex hash
-
-These hashing functions are for use in quickly classifying objects.
-Hash tables use these functions.
-
-@defun hashq obj k
-@defunx hashv obj k
-@defunx hash obj k
-Returns an exact non-negative integer less than @var{k}. For each
-non-negative integer less than @var{k} there are arguments @var{obj} for
-which the hashing functions applied to @var{obj} and @var{k} returns
-that integer.
-
-For @code{hashq}, @code{(eq? obj1 obj2)} implies @code{(= (hashq obj1 k)
-(hashq obj2))}.
-
-For @code{hashv}, @code{(eqv? obj1 obj2)} implies @code{(= (hashv obj1 k)
-(hashv obj2))}.
-
-For @code{hash}, @code{(equal? obj1 obj2)} implies @code{(= (hash obj1 k)
-(hash obj2))}.
-
-@code{hash}, @code{hashv}, and @code{hashq} return in time bounded by a
-constant. Notice that items having the same @code{hash} implies the
-items have the same @code{hashv} implies the items have the same
-@code{hashq}.
-@end defun
-
-
-@code{(require 'sierpinski)}
-@ftindex sierpinski
-
-@defun make-sierpinski-indexer max-coordinate
-Returns a procedure (eg hash-function) of 2 numeric arguments which
-preserves @emph{nearness} in its mapping from NxN to N.
-
-@var{max-coordinate} is the maximum coordinate (a positive integer) of a
-population of points. The returned procedures is a function that takes
-the x and y coordinates of a point, (non-negative integers) and returns
-an integer corresponding to the relative position of that point along a
-Sierpinski curve. (You can think of this as computing a (pseudo-)
-inverse of the Sierpinski spacefilling curve.)
-
-Example use: Make an indexer (hash-function) for integer points lying in
-square of integer grid points [0,99]x[0,99]:
-@example
-(define space-key (make-sierpinski-indexer 100))
-@end example
-Now let's compute the index of some points:
-@example
-(space-key 24 78) @result{} 9206
-(space-key 23 80) @result{} 9172
-@end example
-
-Note that locations (24, 78) and (23, 80) are near in index and
-therefore, because the Sierpinski spacefilling curve is continuous, we
-know they must also be near in the plane. Nearness in the plane does
-not, however, necessarily correspond to nearness in index, although it
-@emph{tends} to be so.
-
-Example applications:
-@itemize @bullet
-
-@item
-Sort points by Sierpinski index to get heuristic solution to
-@emph{travelling salesman problem}. For details of performance,
-see L. Platzman and J. Bartholdi, "Spacefilling curves and the
-Euclidean travelling salesman problem", JACM 36(4):719--737
-(October 1989) and references therein.
-
-@item
-Use Sierpinski index as key by which to store 2-dimensional data
-in a 1-dimensional data structure (such as a table). Then
-locations that are near each other in 2-d space will tend to
-be near each other in 1-d data structure; and locations that
-are near in 1-d data structure will be near in 2-d space. This
-can significantly speed retrieval from secondary storage because
-contiguous regions in the plane will tend to correspond to
-contiguous regions in secondary storage. (This is a standard
-technique for managing CAD/CAM or geographic data.)
-
-@end itemize
-@end defun
-
-
-
-@code{(require 'soundex)}
-@ftindex soundex
-
-@defun soundex name
-Computes the @emph{soundex} hash of @var{name}. Returns a string of an
-initial letter and up to three digits between 0 and 6. Soundex
-supposedly has the property that names that sound similar in normal
-English pronunciation tend to map to the same key.
-
-Soundex was a classic algorithm used for manual filing of personal
-records before the advent of computers. It performs adequately for
-English names but has trouble with other languages.
-
-See Knuth, Vol. 3 @cite{Sorting and searching}, pp 391--2
-
-To manage unusual inputs, @code{soundex} omits all non-alphabetic
-characters. Consequently, in this implementation:
-
-@example
-(soundex <string of blanks>) @result{} ""
-(soundex "") @result{} ""
-@end example
-
-Examples from Knuth:
-
-@example
-(map soundex '("Euler" "Gauss" "Hilbert" "Knuth"
- "Lloyd" "Lukasiewicz"))
- @result{} ("E460" "G200" "H416" "K530" "L300" "L222")
-
-(map soundex '("Ellery" "Ghosh" "Heilbronn" "Kant"
- "Ladd" "Lissajous"))
- @result{} ("E460" "G200" "H416" "K530" "L300" "L222")
-@end example
-
-Some cases in which the algorithm fails (Knuth):
-
-@example
-(map soundex '("Rogers" "Rodgers")) @result{} ("R262" "R326")
-
-(map soundex '("Sinclair" "St. Clair")) @result{} ("S524" "S324")
+@include hashtab.txi
-(map soundex '("Tchebysheff" "Chebyshev")) @result{} ("T212" "C121")
-@end example
-@end defun
-@node Object, Priority Queues, Hashing, Data Structures
+@node Object, Priority Queues, Hash Tables, Data Structures
@subsection Macroless Object System
-@include objdoc.txi
+
+@include object.texi
@node Priority Queues, Queues, Object, Data Structures
@subsection Priority Queues
-@code{(require 'priority-queue)}
-@ftindex priority-queue
-
-@defun make-heap pred<?
-Returns a binary heap suitable which can be used for priority queue
-operations.
-@end defun
-
-@defun heap-length heap
-Returns the number of elements in @var{heap}.
-@end defun
-
-@deffn Procedure heap-insert! heap item
-Inserts @var{item} into @var{heap}. @var{item} can be inserted multiple
-times. The value returned is unspecified.
-@end deffn
-
-@defun heap-extract-max! heap
-Returns the item which is larger than all others according to the
-@var{pred<?} argument to @code{make-heap}. If there are no items in
-@var{heap}, an error is signaled.
-@end defun
-
-The algorithm for priority queues was taken from @cite{Introduction to
-Algorithms} by T. Cormen, C. Leiserson, R. Rivest. 1989 MIT Press.
-
+@include priorque.txi
@node Queues, Records, Priority Queues, Data Structures
@subsection Queues
-@code{(require 'queue)}
-@ftindex queue
-
-A @dfn{queue} is a list where elements can be added to both the front
-and rear, and removed from the front (i.e., they are what are often
-called @dfn{dequeues}). A queue may also be used like a stack.
-
-@defun make-queue
-Returns a new, empty queue.
-@end defun
-
-@defun queue? obj
-Returns @code{#t} if @var{obj} is a queue.
-@end defun
-
-@defun queue-empty? q
-Returns @code{#t} if the queue @var{q} is empty.
-@end defun
-
-@deffn Procedure queue-push! q datum
-Adds @var{datum} to the front of queue @var{q}.
-@end deffn
-
-@deffn Procedure enquque! q datum
-Adds @var{datum} to the rear of queue @var{q}.
-@end deffn
-
-All of the following functions raise an error if the queue @var{q} is
-empty.
-
-@defun queue-front q
-Returns the datum at the front of the queue @var{q}.
-@end defun
-
-@defun queue-rear q
-Returns the datum at the rear of the queue @var{q}.
-@end defun
-
-@deffn Prcoedure queue-pop! q
-@deffnx Procedure dequeue! q
-Both of these procedures remove and return the datum at the front of the
-queue. @code{queue-pop!} is used to suggest that the queue is being
-used like a stack.
-@end deffn
-
-
+@include queue.txi
@@ -8309,7 +9026,7 @@ unspecified how record-type descriptors are represented.
@c type, disjoint from all others. The @var{type-name} argument must be a
@c string. The @var{field-names} argument is a list of symbols naming the
@c additional @dfn{fields} to be appended to @var{field-names} of
-@c @var{rtd}. It is an error if the combinded list contains any
+@c @var{rtd}. It is an error if the combined list contains any
@c duplicates.
@c
@c Record-modifiers and record-accessors for @var{rtd} work for the new
@@ -8426,6 +9143,9 @@ created the type represented by @var{rtd}.
* Chapter Ordering:: 'chapter-order
* Sorting:: 'sort
* Topological Sort:: Keep your socks on.
+* Hashing:: 'hash
+* Space-Filling Curves:: 'hilbert and 'sierpinski
+* Soundex:: Dimension Reduction of Last Names
* String Search:: Also Search from a Port.
* Sequence Comparison:: 'diff and longest-common-subsequence
@end menu
@@ -8472,7 +9192,8 @@ Example:
@defun list* obj1 obj2 @dots{}
Works like @code{list} except that the cdr of the last pair is the last
argument unless there is only one argument, when the result is just that
-argument. Sometimes called @code{cons*}. E.g.:@refill
+argument. Sometimes called @code{cons*}. E.g.:
+
@lisp
(list* 1)
@result{} 1
@@ -8537,22 +9258,23 @@ Example:
@end defun
@defun union l1 l2
-@code{union} returns the combination of @var{l1} and @var{l2}.
-Duplicates between @var{l1} and @var{l2} are culled. Duplicates within
-@var{l1} or within @var{l2} may or may not be removed.
+@code{union} returns a list of all elements that are in @var{l1} or
+@var{l2}. Duplicates between @var{l1} and @var{l2} are culled.
+Duplicates within @var{l1} or within @var{l2} may or may not be
+removed.
Example:
@lisp
(union '(1 2 3 4) '(5 6 7 8))
- @result{} (8 7 6 5 1 2 3 4)
-(union '(1 2 3 4) '(3 4 5 6))
- @result{} (6 5 1 2 3 4)
+ @result{} (1 2 3 4 5 6 7 8)
+(union '(0 1 2 3 4) '(3 4 5 6))
+ @result{} (5 6 0 1 2 3 4)
@end lisp
@end defun
@defun intersection l1 l2
-@code{intersection} returns all elements that are in both @var{l1} and
-@var{l2}.
+@code{intersection} returns a list of all elements that are in both
+@var{l1} and @var{l2}.
Example:
@lisp
@@ -8564,8 +9286,8 @@ Example:
@end defun
@defun set-difference l1 l2
-@code{set-difference} returns all elements that are in @var{l1} but not
-in @var{l2}.
+@code{set-difference} returns a list of all elements that are in
+@var{l1} but not in @var{l2}.
Example:
@lisp
@@ -8576,17 +9298,31 @@ Example:
@end lisp
@end defun
+@defun subset? list1 list2
+Returns @code{#t} if every element of @var{list1} is @code{eqv?} an
+element of @var{list2}; otherwise returns @code{#f}.
+
+Example:
+@lisp
+(subset? '(1 2 3 4) '(3 4 5 6))
+ @result{} #f
+(subset? '(1 2 3 4) '(6 5 4 3 2 1 0))
+ @result{} #t
+@end lisp
+@end defun
+
@defun member-if pred lst
-@code{member-if} returns @var{lst} if @code{(@var{pred} @var{element})}
-is @code{#t} for any @var{element} in @var{lst}. Returns @code{#f} if
-@var{pred} does not apply to any @var{element} in @var{lst}.
+@code{member-if} returns the list headed by the first element of
+@var{lst} to satisfy @code{(@var{pred} @var{element})}.
+@code{Member-if} returns @code{#f} if @var{pred} returns @code{#f} for
+every @var{element} in @var{lst}.
Example:
@lisp
-(member-if vector? '(1 2 3 4))
+(member-if vector? '(a 2 b 4))
@result{} #f
-(member-if number? '(1 2 3 4))
- @result{} (1 2 3 4)
+(member-if number? '(a 2 b 4))
+ @result{} (2 b 4)
@end lisp
@end defun
@@ -8607,7 +9343,7 @@ Example:
(some odd? '(2 4 6 8))
@result{} #f
-(some > '(2 3) '(1 4))
+(some > '(1 3) '(2 4))
@result{} #f
@end lisp
@end defun
@@ -8973,7 +9709,7 @@ given identical arugments.
These procedures may mutate the list they operate on, but any such
mutation is undefined.
-@deffn Procedure nconc args
+@deffn {Procedure} nconc args
@code{nconc} destructively concatenates its arguments. (Compare this
with @code{append}, which copies arguments rather than destroying them.)
Sometimes called @code{append!} (@pxref{Rev2 Procedures}).
@@ -8984,8 +9720,8 @@ Example: You want to find the subsets of a set. Here's the obvious way:
(define (subsets set)
(if (null? set)
'(())
- (append (mapcar (lambda (sub) (cons (car set) sub))
- (subsets (cdr set)))
+ (append (map (lambda (sub) (cons (car set) sub))
+ (subsets (cdr set)))
(subsets (cdr set)))))
@end lisp
But that does way more consing than you need. Instead, you could
@@ -9005,7 +9741,7 @@ x
@code{nconc} is the same as @code{append!} in @file{sc2.scm}.
@end deffn
-@deffn Procedure nreverse lst
+@deffn {Procedure} nreverse lst
@code{nreverse} reverses the order of elements in @var{lst} by mutating
@code{cdr}s of the list. Sometimes called @code{reverse!}.
@@ -9020,7 +9756,8 @@ foo
Some people have been confused about how to use @code{nreverse},
thinking that it doesn't return a value. It needs to be pointed out
-that@refill
+that
+
@lisp
(set! lst (nreverse lst))
@end lisp
@@ -9032,21 +9769,21 @@ is the proper usage, not
The example should suffice to show why this is the case.
@end deffn
-@deffn Procedure delete elt lst
-@deffnx Procedure delete-if pred lst
-@deffnx Procedure delete-if-not pred lst
+@deffn {Procedure} delete elt lst
+@deffnx {Procedure} delete-if pred lst
+@deffnx {Procedure} delete-if-not pred lst
Destructive versions of @code{remove} @code{remove-if}, and
@code{remove-if-not}.
Example:
@lisp
-(define lst '(foo bar baz bang))
+(define lst (list 'foo 'bar 'baz 'bang))
(delete 'foo lst)
@result{} (bar baz bang)
lst
@result{} (foo bar baz bang)
-(define lst '(1 2 3 4 5 6 7 8 9))
+(define lst (list 1 2 3 4 5 6 7 8 9))
(delete-if odd? lst)
@result{} (2 4 6 8)
lst
@@ -9054,8 +9791,9 @@ lst
@end lisp
Some people have been confused about how to use @code{delete},
-@code{delete-if}, and @code{delete-if}, thinking that they dont' return
-a value. It needs to be pointed out that@refill
+@code{delete-if}, and @code{delete-if}, thinking that they don't return
+a value. It needs to be pointed out that
+
@lisp
(set! lst (delete el lst))
@end lisp
@@ -9076,7 +9814,7 @@ The examples should suffice to show why this is the case.
@code{and?} checks to see if all its arguments are true. If they are,
@code{and?} returns @code{#t}, otherwise, @code{#f}. (In contrast to
@code{and}, this is a function, so all arguments are always evaluated
-and in an unspecified order.)@refill
+and in an unspecified order.)
Example:
@lisp
@@ -9090,7 +9828,7 @@ Example:
@defun or? arg1 @dots{}
@code{or?} checks to see if any of its arguments are true. If any is
true, @code{or?} returns @code{#t}, and @code{#f} otherwise. (To
-@code{or} as @code{and?} is to @code{and}.)@refill
+@code{or} as @code{and?} is to @code{and}.)
Example:
@lisp
@@ -9118,96 +9856,13 @@ pair. (Called @code{atom} in Common LISP.)
@node Tree Operations, Chapter Ordering, Common List Functions, Sorting and Searching
@subsection Tree operations
-@code{(require 'tree)}
-@ftindex tree
-
-These are operations that treat lists a representations of trees.
-
-@defun subst new old tree
-@defunx subst new old tree equ?
-@defunx substq new old tree
-@defunx substv new old tree
-@code{subst} makes a copy of @var{tree}, substituting @var{new} for
-every subtree or leaf of @var{tree} which is @code{equal?} to @var{old}
-and returns a modified tree. The original @var{tree} is unchanged, but
-may share parts with the result.
-
-@code{substq} and @code{substv} are similar, but test against @var{old}
-using @code{eq?} and @code{eqv?} respectively. If @code{subst} is
-called with a fourth argument, @var{equ?} is the equality predicate.
-
-Examples:
-@lisp
-(substq 'tempest 'hurricane '(shakespeare wrote (the hurricane)))
- @result{} (shakespeare wrote (the tempest))
-(substq 'foo '() '(shakespeare wrote (twelfth night)))
- @result{} (shakespeare wrote (twelfth night . foo) . foo)
-(subst '(a . cons) '(old . pair)
- '((old . spice) ((old . shoes) old . pair) (old . pair)))
- @result{} ((old . spice) ((old . shoes) a . cons) (a . cons))
-@end lisp
-@end defun
-
-@defun copy-tree tree
-Makes a copy of the nested list structure @var{tree} using new pairs and
-returns it. All levels are copied, so that none of the pairs in the
-tree are @code{eq?} to the original ones -- only the leaves are.
-
-Example:
-@lisp
-(define bar '(bar))
-(copy-tree (list bar 'foo))
- @result{} ((bar) foo)
-(eq? bar (car (copy-tree (list bar 'foo))))
- @result{} #f
-@end lisp
-@end defun
+@include tree.txi
@node Chapter Ordering, Sorting, Tree Operations, Sorting and Searching
@subsection Chapter Ordering
-@code{(require 'chapter-order)}
-@ftindex chapter-order
-
-The @samp{chap:} functions deal with strings which are ordered like
-chapter numbers (or letters) in a book. Each section of the string
-consists of consecutive numeric or consecutive aphabetic characters of
-like case.
-
-@defun chap:string<? string1 string2
-Returns #t if the first non-matching run of alphabetic upper-case or the
-first non-matching run of alphabetic lower-case or the first
-non-matching run of numeric characters of @var{string1} is
-@code{string<?} than the corresponding non-matching run of characters of
-@var{string2}.
-
-@example
-(chap:string<? "a.9" "a.10") @result{} #t
-(chap:string<? "4c" "4aa") @result{} #t
-(chap:string<? "Revised^@{3.99@}" "Revised^@{4@}") @result{} #t
-@end example
-
-@defunx chap:string>? string1 string2
-@defunx chap:string<=? string1 string2
-@defunx chap:string>=? string1 string2
-Implement the corresponding chapter-order predicates.
-@end defun
-
-@defun chap:next-string string
-Returns the next string in the @emph{chapter order}. If @var{string}
-has no alphabetic or numeric characters,
-@code{(string-append @var{string} "0")} is returnd. The argument to
-chap:next-string will always be @code{chap:string<?} than the result.
-
-@example
-(chap:next-string "a.9") @result{} "a.10"
-(chap:next-string "4c") @result{} "4d"
-(chap:next-string "4z") @result{} "4aa"
-(chap:next-string "Revised^@{4@}") @result{} "Revised^@{5@}"
-
-@end example
-@end defun
+@include chap.txi
@node Sorting, Topological Sort, Chapter Ordering, Sorting and Searching
@@ -9298,7 +9953,7 @@ Common LISP as made sense, in order to avoid NIH-itis.
Each of the five functions has a required @emph{last} parameter which is
a comparison function. A comparison function @code{f} is a function of
-2 arguments which acts like @code{<}. For example,@refill
+2 arguments which acts like @code{<}. For example,
@lisp
(not (f x x))
@@ -9317,7 +9972,8 @@ according to @var{less?} (that is, there is no adjacent pair @code{@dots{} x
y @dots{}} for which @code{(less? y x)}).
Returns @code{#f} when the sequence contains at least one out-of-order
-pair. It is an error if the sequence is neither a list nor a vector.
+pair. It is an error if the sequence is not a list, vector, or
+string.
@end defun
@defun merge list1 list2 less?
@@ -9330,7 +9986,7 @@ bit of work anyway. I did, however, appeal to CL to determine the
@emph{order} of the arguments.
@end defun
-@deffn Procedure merge! list1 list2 less?
+@deffn {Procedure} merge! list1 list2 less?
Merges two lists, re-using the pairs of @var{list1} and @var{list2} to
build the result. If the code is compiled, and @var{less?} constructs
no new pairs, no pairs at all will be allocated. The first pair of the
@@ -9340,22 +9996,23 @@ result will be either the first pair of @var{list1} or the first pair of
The code of @code{merge} and @code{merge!} could have been quite a bit
simpler, but they have been coded to reduce the amount of work done per
iteration. (For example, we only have one @code{null?} test per
-iteration.)@refill
+iteration.)
+
@end deffn
@defun sort sequence less?
-Accepts either a list or a vector, and returns a new sequence which is
-sorted. The new sequence is the same type as the input. Always
-@code{(sorted? (sort sequence less?) less?)}. The original sequence is
-not altered in any way. The new sequence shares its @emph{elements}
-with the old one; no elements are copied.
+Accepts either a list, vector, or string; and returns a new sequence
+which is sorted. The new sequence is the same type as the input.
+Always @code{(sorted? (sort sequence less?) less?)}. The original
+sequence is not altered in any way. The new sequence shares its
+@emph{elements} with the old one; no elements are copied.
@end defun
-@deffn Procedure sort! sequence less?
+@deffn {Procedure} sort! sequence less?
Returns its sorted result in the original boxes. If the original
-sequence is a list, no new storage is allocated at all. If the original
-sequence is a vector, the sorted elements are put back in the same
-vector.
+sequence is a list, no new storage is allocated at all. If the
+original sequence is a vector or string, the sorted elements are put
+back in the same vector or string.
Some people have been confused about how to use @code{sort!}, thinking
that it doesn't return a value. It needs to be pointed out that
@@ -9371,7 +10028,8 @@ is the proper usage, not
Note that these functions do @emph{not} accept a CL-style @samp{:key}
argument. A simple device for obtaining the same expressiveness is to
-define@refill
+define
+
@lisp
(define (keyed less? key)
(lambda (x y) (less? (key x) (key y))))
@@ -9389,84 +10047,190 @@ in Common LISP, just write
@noindent
in Scheme.
-@node Topological Sort, String Search, Sorting, Sorting and Searching
+@node Topological Sort, Hashing, Sorting, Sorting and Searching
@subsection Topological Sort
-@code{(require 'topological-sort)} or @code{(require 'tsort)}
-@ftindex topological-sort
-@ftindex tsort
+@include tsort.txi
-@noindent
-The algorithm is inspired by Cormen, Leiserson and Rivest (1990)
-@cite{Introduction to Algorithms}, chapter 23.
-@defun tsort dag pred
-@defunx topological-sort dag pred
-where
-@table @var
-@item dag
-is a list of sublists. The car of each sublist is a vertex. The cdr is
-the adjacency list of that vertex, i.e. a list of all vertices to which
-there exists an edge from the car vertex.
-@item pred
-is one of @code{eq?}, @code{eqv?}, @code{equal?}, @code{=},
-@code{char=?}, @code{char-ci=?}, @code{string=?}, or @code{string-ci=?}.
-@end table
+@node Hashing, Space-Filling Curves, Topological Sort, Sorting and Searching
+@subsection Hashing
-Sort the directed acyclic graph @var{dag} so that for every edge from
-vertex @var{u} to @var{v}, @var{u} will come before @var{v} in the
-resulting list of vertices.
+@code{(require 'hash)}
+@ftindex hash
-Time complexity: O (|V| + |E|)
+These hashing functions are for use in quickly classifying objects.
+Hash tables use these functions.
-Example (from Cormen):
-@quotation
-Prof. Bumstead topologically sorts his clothing when getting
-dressed. The first argument to `tsort' describes which
-garments he needs to put on before others. (For example,
-Prof Bumstead needs to put on his shirt before he puts on his
-tie or his belt.) `tsort' gives the correct order of dressing:
-@end quotation
+@defun hashq obj k
+@defunx hashv obj k
+@defunx hash obj k
+Returns an exact non-negative integer less than @var{k}. For each
+non-negative integer less than @var{k} there are arguments @var{obj} for
+which the hashing functions applied to @var{obj} and @var{k} returns
+that integer.
+
+For @code{hashq}, @code{(eq? obj1 obj2)} implies @code{(= (hashq obj1 k)
+(hashq obj2))}.
+
+For @code{hashv}, @code{(eqv? obj1 obj2)} implies @code{(= (hashv obj1 k)
+(hashv obj2))}.
+
+For @code{hash}, @code{(equal? obj1 obj2)} implies @code{(= (hash obj1 k)
+(hash obj2))}.
+
+@code{hash}, @code{hashv}, and @code{hashq} return in time bounded by a
+constant. Notice that items having the same @code{hash} implies the
+items have the same @code{hashv} implies the items have the same
+@code{hashq}.
+@end defun
+
+
+@node Space-Filling Curves, Soundex, Hashing, Sorting and Searching
+@subsection Space-Filling Curves
+
+@menu
+* Peano-Hilbert Space-Filling Curve::
+* Sierpinski Curve::
+@end menu
+
+@node Peano-Hilbert Space-Filling Curve, Sierpinski Curve, Space-Filling Curves, Space-Filling Curves
+@subsubsection Peano-Hilbert Space-Filling Curve
+
+@include phil-spc.txi
+
+
+@node Sierpinski Curve, , Peano-Hilbert Space-Filling Curve, Space-Filling Curves
+@subsubsection Sierpinski Curve
+
+@code{(require 'sierpinski)}
+@ftindex sierpinski
+
+@defun make-sierpinski-indexer max-coordinate
+Returns a procedure (eg hash-function) of 2 numeric arguments which
+preserves @emph{nearness} in its mapping from NxN to N.
+@var{max-coordinate} is the maximum coordinate (a positive integer) of a
+population of points. The returned procedures is a function that takes
+the x and y coordinates of a point, (non-negative integers) and returns
+an integer corresponding to the relative position of that point along a
+Sierpinski curve. (You can think of this as computing a (pseudo-)
+inverse of the Sierpinski spacefilling curve.)
+
+Example use: Make an indexer (hash-function) for integer points lying in
+square of integer grid points [0,99]x[0,99]:
@example
-(require 'tsort)
-@ftindex tsort
-(tsort '((shirt tie belt)
- (tie jacket)
- (belt jacket)
- (watch)
- (pants shoes belt)
- (undershorts pants shoes)
- (socks shoes))
- eq?)
-@result{}
-(socks undershorts pants shoes watch shirt belt tie jacket)
+(define space-key (make-sierpinski-indexer 100))
+@end example
+Now let's compute the index of some points:
+@example
+(space-key 24 78) @result{} 9206
+(space-key 23 80) @result{} 9172
+@end example
+
+Note that locations (24, 78) and (23, 80) are near in index and
+therefore, because the Sierpinski spacefilling curve is continuous, we
+know they must also be near in the plane. Nearness in the plane does
+not, however, necessarily correspond to nearness in index, although it
+@emph{tends} to be so.
+
+Example applications:
+@itemize @bullet
+
+@item
+Sort points by Sierpinski index to get heuristic solution to
+@emph{travelling salesman problem}. For details of performance,
+see L. Platzman and J. Bartholdi, "Spacefilling curves and the
+Euclidean travelling salesman problem", JACM 36(4):719--737
+(October 1989) and references therein.
+
+@item
+Use Sierpinski index as key by which to store 2-dimensional data
+in a 1-dimensional data structure (such as a table). Then
+locations that are near each other in 2-d space will tend to
+be near each other in 1-d data structure; and locations that
+are near in 1-d data structure will be near in 2-d space. This
+can significantly speed retrieval from secondary storage because
+contiguous regions in the plane will tend to correspond to
+contiguous regions in secondary storage. (This is a standard
+technique for managing CAD/CAM or geographic data.)
+
+@end itemize
+@end defun
+
+
+@node Soundex, String Search, Space-Filling Curves, Sorting and Searching
+@subsection Soundex
+
+@code{(require 'soundex)}
+@ftindex soundex
+
+@defun soundex name
+Computes the @emph{soundex} hash of @var{name}. Returns a string of an
+initial letter and up to three digits between 0 and 6. Soundex
+supposedly has the property that names that sound similar in normal
+English pronunciation tend to map to the same key.
+
+Soundex was a classic algorithm used for manual filing of personal
+records before the advent of computers. It performs adequately for
+English names but has trouble with other languages.
+
+See Knuth, Vol. 3 @cite{Sorting and searching}, pp 391--2
+
+To manage unusual inputs, @code{soundex} omits all non-alphabetic
+characters. Consequently, in this implementation:
+
+@example
+(soundex <string of blanks>) @result{} ""
+(soundex "") @result{} ""
+@end example
+
+Examples from Knuth:
+
+@example
+(map soundex '("Euler" "Gauss" "Hilbert" "Knuth"
+ "Lloyd" "Lukasiewicz"))
+ @result{} ("E460" "G200" "H416" "K530" "L300" "L222")
+
+(map soundex '("Ellery" "Ghosh" "Heilbronn" "Kant"
+ "Ladd" "Lissajous"))
+ @result{} ("E460" "G200" "H416" "K530" "L300" "L222")
+@end example
+
+Some cases in which the algorithm fails (Knuth):
+
+@example
+(map soundex '("Rogers" "Rodgers")) @result{} ("R262" "R326")
+
+(map soundex '("Sinclair" "St. Clair")) @result{} ("S524" "S324")
+
+(map soundex '("Tchebysheff" "Chebyshev")) @result{} ("T212" "C121")
@end example
@end defun
-@node String Search, Sequence Comparison, Topological Sort, Sorting and Searching
+@node String Search, Sequence Comparison, Soundex, Sorting and Searching
@subsection String Search
@code{(require 'string-search)}
@ftindex string-search
-@deffn Procedure string-index string char
-@deffnx Procedure string-index-ci string char
+@deffn {Procedure} string-index string char
+@deffnx {Procedure} string-index-ci string char
Returns the index of the first occurence of @var{char} within
@var{string}, or @code{#f} if the @var{string} does not contain a
character @var{char}.
@end deffn
-@deffn Procedure string-reverse-index string char
-@deffnx Procedure string-reverse-index-ci string char
+@deffn {Procedure} string-reverse-index string char
+@deffnx {Procedure} string-reverse-index-ci string char
Returns the index of the last occurence of @var{char} within
@var{string}, or @code{#f} if the @var{string} does not contain a
character @var{char}.
@end deffn
-@deffn procedure substring? pattern string
-@deffnx procedure substring-ci? pattern string
+@deffn {Procedure} substring? pattern string
+@deffnx {Procedure} substring-ci? pattern string
Searches @var{string} to see if some substring of @var{string} is equal
to @var{pattern}. @code{substring?} returns the index of the first
character of the first substring of @var{string} that is equal to
@@ -9480,19 +10244,19 @@ character of the first substring of @var{string} that is equal to
@end example
@end deffn
-@deffn Procedure find-string-from-port? str in-port max-no-chars
+@deffn {Procedure} find-string-from-port? str in-port max-no-chars
Looks for a string @var{str} within the first @var{max-no-chars} chars
of the input port @var{in-port}.
-@deffnx Procedure find-string-from-port? str in-port
+@deffnx {Procedure} find-string-from-port? str in-port
When called with two arguments, the search span is limited by the end of
the input stream.
-@deffnx Procedure find-string-from-port? str in-port char
+@deffnx {Procedure} find-string-from-port? str in-port char
Searches up to the first occurrence of character @var{char} in
@var{str}.
-@deffnx Procedure find-string-from-port? str in-port proc
+@deffnx {Procedure} find-string-from-port? str in-port proc
Searches up to the first occurrence of the procedure @var{proc}
returning non-false when called with a character (from @var{in-port})
argument.
@@ -9510,8 +10274,13 @@ open to a pipe or other communication channel.
@defun string-subst txt old1 new1 @dots{}
Returns a copy of string @var{txt} with all occurrences of string
-@var{old1} in @var{txt} replaced with @var{new1}, @var{old2} replaced
-with @var{new2} @dots{}.
+@var{old1} in @var{txt} replaced with @var{new1}; then @var{old2}
+replaced with @var{new2} @dots{}. Matches are found from the left.
+Matches do not overlap.
+@end defun
+
+@defun count-newlines str
+Returns the number of @samp{#\newline} characters in string @var{str}.
@end defun
@@ -9555,15 +10324,15 @@ up here.
@code{(require 'string-case)}
@ftindex string-case
-@deffn Procedure string-upcase str
-@deffnx Procedure string-downcase str
-@deffnx Procedure string-capitalize str
+@deffn {Procedure} string-upcase str
+@deffnx {Procedure} string-downcase str
+@deffnx {Procedure} string-capitalize str
The obvious string conversion routines. These are non-destructive.
@end deffn
@defun string-upcase! str
@defunx string-downcase! str
-@defunx string-captialize! str
+@defunx string-capitalize! str
The destructive versions of the functions above.
@end defun
@@ -9579,6 +10348,29 @@ symbol case; the case of symbol characters is not changed. #f is
converted to the empty string (symbol).
@end defun
+@defun StudlyCapsExpand str delimiter
+@defunx StudlyCapsExpand str
+@var{delimiter} must be a string or character. If absent,
+@var{delimiter} defaults to @samp{-}. @code{StudlyCapsExpand} returns a
+copy of @var{str} where @var{delimiter} is inserted between each
+lower-case character immediately followed by an upper-case character;
+and between two upper-case characters immediately followed by a
+lower-case character.
+
+@example
+(StudlyCapsExpand "aX" " ") @result{} "a X"
+(StudlyCapsExpand "aX" "..") @result{} "a..X"
+(StudlyCapsExpand "AX") @result{} "AX"
+(StudlyCapsExpand "Ax") @result{} "Ax"
+(StudlyCapsExpand "AXLE") @result{} "AXLE"
+(StudlyCapsExpand "aAXACz") @result{} "a-AXA-Cz"
+(StudlyCapsExpand "AaXACz") @result{} "Aa-XA-Cz"
+(StudlyCapsExpand "AAaXACz") @result{} "A-Aa-XA-Cz"
+(StudlyCapsExpand "AAaXAC") @result{} "A-Aa-XAC"
+@end example
+
+@end defun
+
@node String Ports, Line I/O, String-Case, Procedures
@@ -9587,14 +10379,14 @@ converted to the empty string (symbol).
@code{(require 'string-port)}
@ftindex string-port
-@deffn Procedure call-with-output-string proc
+@deffn {Procedure} call-with-output-string proc
@var{proc} must be a procedure of one argument. This procedure calls
@var{proc} with one argument: a (newly created) output port. When the
function returns, the string composed of the characters written into the
port is returned.
@end deffn
-@deffn Procedure call-with-input-string string proc
+@deffn {Procedure} call-with-input-string string proc
@var{proc} must be a procedure of one argument. This procedure calls
@var{proc} with one argument: an (newly created) input port from which
@var{string}'s contents may be read. When @var{proc} returns, the port
@@ -9621,25 +10413,25 @@ returned.
This module implements asynchronous (non-polled) time-sliced
multi-processing in the SCM Scheme implementation using procedures
@code{alarm} and @code{alarm-interrupt}.
-@findex alarm
-@findex alarm-interrupt
+@cindex alarm
+@cindex alarm-interrupt
Until this is ported to another implementation, consider it an example
of writing schedulers in Scheme.
-@deffn Procedure add-process! proc
+@deffn {Procedure} add-process! proc
Adds proc, which must be a procedure (or continuation) capable of
accepting accepting one argument, to the @code{process:queue}. The
value returned is unspecified. The argument to @var{proc} should be
ignored. If @var{proc} returns, the process is killed.
@end deffn
-@deffn Procedure process:schedule!
+@deffn {Procedure} process:schedule!
Saves the current process on @code{process:queue} and runs the next
process from @code{process:queue}. The value returned is
unspecified.
@end deffn
-@deffn Procedure kill-process!
+@deffn {Procedure} kill-process!
Kills the current process and runs the next process from
@code{process:queue}. If there are no more processes on
@code{process:queue}, @code{(slib:exit)} is called (@pxref{System}).
@@ -9724,7 +10516,7 @@ A unit exponent follows the unit, separated by a CIRCUMFLEX (@samp{^}).
Exponents may be positive or negative. Fractional exponents must be
parenthesized.
-@subsubheading SI Prefixes
+@subsubsection SI Prefixes
@example
Factor Name Symbol | Factor Name Symbol
====== ==== ====== | ====== ==== ======
@@ -9740,7 +10532,7 @@ parenthesized.
1e1 deka da | 1e-24 yocto y
@end example
-@subsubheading Binary Prefixes
+@subsubsection Binary Prefixes
These binary prefixes are valid only with the units B (byte) and bit.
However, decimal prefixes can also be used with bit; and decimal
@@ -9757,7 +10549,7 @@ multiple (not submultiple) prefixes can also be used with B (byte).
1.024e3 (2^10) kibi Ki
@end example
-@subsubheading Unit Symbols
+@subsubsection Unit Symbols
@example
Type of Quantity Name Symbol Equivalent
@@ -9861,6 +10653,7 @@ if linear conversion (by a factor) is not possible.
@menu
+* RnRS:: Revised Reports on Scheme
* With-File:: 'with-file
* Transcripts:: 'transcript
* Rev2 Procedures:: 'rev2-procedures
@@ -9868,14 +10661,54 @@ if linear conversion (by a factor) is not possible.
* Multi-argument / and -:: 'multiarg/and-
* Multi-argument Apply:: 'multiarg-apply
* Rationalize:: 'rationalize
-* Promises:: 'promise
+* Promises:: 'delay
* Dynamic-Wind:: 'dynamic-wind
* Eval:: 'eval
* Values:: 'values
* SRFI:: 'http://srfi.schemers.org/srfi-0/srfi-0.html
@end menu
-@node With-File, Transcripts, Standards Support, Standards Support
+@node RnRS, With-File, Standards Support, Standards Support
+@subsection RnRS
+
+@noindent
+The @code{r2rs}, @code{r3rs}, @code{r4rs}, and @code{r5rs} features
+attempt to provide procedures and macros to bring a Scheme
+implementation to the desired version of Scheme.
+
+@deftp {Feature} r2rs
+@ftindex r2rs
+Requires features implementing procedures and optional procedures
+specified by @cite{Revised^2 Report on the Algorithmic Language Scheme};
+namely @code{rev3-procedures} and @code{rev2-procedures}.
+@end deftp
+
+@deftp {Feature} r3rs
+@ftindex r3rs
+Requires features implementing procedures and optional procedures
+specified by @cite{Revised^3 Report on the Algorithmic Language Scheme};
+namely @code{rev3-procedures}.
+
+@emph{Note:} SLIB already mandates the @code{r3rs} procedures which can
+be portably implemented in @code{r4rs} implementations.
+@end deftp
+
+@deftp {Feature} r4rs
+@ftindex r4rs
+Requires features implementing procedures and optional procedures
+specified by @cite{Revised^4 Report on the Algorithmic Language Scheme};
+namely @code{rev4-optional-procedures}.
+@end deftp
+
+@deftp {Feature} r5rs
+@ftindex r5rs
+Requires features implementing procedures and optional procedures
+specified by @cite{Revised^5 Report on the Algorithmic Language Scheme};
+namely @code{values}, @code{macro}, and @code{eval}.
+@end deftp
+
+
+@node With-File, Transcripts, RnRS, Standards Support
@subsection With-File
@code{(require 'with-file)}
@@ -9910,13 +10743,13 @@ Redefines @code{read-char}, @code{read}, @code{write-char},
The procedures below were specified in the @cite{Revised^2 Report on
Scheme}. @strong{N.B.}: The symbols @code{1+} and @code{-1+} are not
-@cite{R4RS} syntax. Scheme->C, for instance, barfs on this
+@cite{R4RS} syntax. Scheme->C, for instance, chokes on this
module.
-@deffn Procedure substring-move-left! string1 start1 end1 string2 start2
-@deffnx Procedure substring-move-right! string1 start1 end1 string2 start2
+@deffn {Procedure} substring-move-left! string1 start1 end1 string2 start2
+@deffnx {Procedure} substring-move-right! string1 start1 end1 string2 start2
@var{string1} and @var{string2} must be a strings, and @var{start1},
-@var{start2} and @var{end1} must be exact integers satisfying@refill
+@var{start2} and @var{end1} must be exact integers satisfying
@display
0 <= @var{start1} <= @var{end1} <= (string-length @var{string1})
@@ -9933,7 +10766,7 @@ increasing indices. @code{substring-move-right!} stores characters in
time order of increasing indeces.
@end deffn
-@deffn Procedure substring-fill! string start end char
+@deffn {Procedure} substring-fill! string start end char
Fills the elements @var{start}--@var{end} of @var{string} with the
character @var{char}.
@end deffn
@@ -9942,7 +10775,7 @@ character @var{char}.
@equiv{} @code{(= 0 (string-length @var{str}))}
@end defun
-@deffn Procedure append! pair1 @dots{}
+@deffn {Procedure} append! pair1 @dots{}
Destructively appends its arguments. Equivalent to @code{nconc}.
@end deffn
@@ -9986,7 +10819,7 @@ For the specification of these optional procedures,
@defun string-copy
@end defun
-@deffn Procedure string-fill! s obj
+@deffn {Procedure} string-fill! s obj
@end deffn
@defun list->vector l
@@ -9995,7 +10828,7 @@ For the specification of these optional procedures,
@defun vector->list s
@end defun
-@deffn Procedure vector-fill! s obj
+@deffn {Procedure} vector-fill! s obj
@end deffn
@@ -10005,25 +10838,15 @@ For the specification of these optional procedures,
@node Multi-argument / and -, Multi-argument Apply, Rev4 Optional Procedures, Standards Support
@subsection Multi-argument / and -
-@code{(require 'mutliarg/and-)}
-@ftindex mutliarg
+@code{(require 'multiarg/and-)}
+@ftindex multiarg
For the specification of these optional forms, @xref{Numerical
-operations, , ,r4rs, Revised(4) Scheme}. The @code{two-arg:}* forms are
-only defined if the implementation does not support the many-argument
-forms.
-
-@defun two-arg:/ n1 n2
-The original two-argument version of @code{/}.
-@end defun
+operations, , ,r4rs, Revised(4) Scheme}.
@defun / dividend divisor1 @dots{}
@end defun
-@defun two-arg:- n1 n2
-The original two-argument version of @code{-}.
-@end defun
-
@defun - minuend subtrahend1 @dots{}
@end defun
@@ -10041,61 +10864,16 @@ The original two-argument version of @code{-}.
For the specification of this optional form,
@xref{Control features, , ,r4rs, Revised(4) Scheme}.
-@defun two-arg:apply proc l
-The implementation's native @code{apply}. Only defined for
-implementations which don't support the many-argument version.
-@end defun
-
@defun apply proc arg1 @dots{}
@end defun
-
-
@node Rationalize, Promises, Multi-argument Apply, Standards Support
@subsection Rationalize
-@code{(require 'rationalize)}
-@ftindex rationalize
-
-The procedure @dfn{rationalize} is interesting because most programming
-languages do not provide anything analogous to it. Thanks to Alan
-Bawden for contributing this algorithm.
-
-@defun rationalize x y
-Computes the correct result for exact arguments (provided the
-implementation supports exact rational numbers of unlimited precision);
-and produces a reasonable answer for inexact arguments when inexact
-arithmetic is implemented using floating-point.
-@end defun
-
-@code{Rationalize} has limited use in implementations lacking exact
-(non-integer) rational numbers. The following procedures return a list
-of the numerator and denominator.
-
-@defun find-ratio x y
-@code{find-ratio} returns the list of the @emph{simplest}
-numerator and denominator whose quotient differs from @var{x} by no more
-than @var{y}.
+@include ratize.txi
-@format
-@t{(find-ratio 3/97 .0001) @result{} (3 97)
-(find-ratio 3/97 .001) @result{} (1 32)
-}
-@end format
-@end defun
-
-@defun find-ratio-between x y
-@code{find-ratio-between} returns the list of the @emph{simplest}
-numerator and denominator between @var{x} and @var{y}.
-
-@format
-@t{(find-ratio-between 2/7 3/5) @result{} (1 2)
-(find-ratio-between -3/5 -2/7) @result{} (-1 2)
-}
-@end format
-@end defun
@node Promises, Dynamic-Wind, Rationalize, Standards Support
@@ -10107,13 +10885,21 @@ numerator and denominator between @var{x} and @var{y}.
@defun make-promise proc
@end defun
+@defun force promise
+@end defun
+
+@code{(require 'delay)} provides @code{force} and @code{delay}:
+
+@defmac delay obj
Change occurrences of @code{(delay @var{expression})} to
-@code{(make-promise (lambda () @var{expression}))} and @code{(define
-force promise:force)} to implement promises if your implementation
-doesn't support them
-(@pxref{Control features, , ,r4rs, Revised(4) Scheme}).
+@example
+(make-promise (lambda () @var{expression}))
+@end example
+
+@end defmac
+(@pxref{Control features, , ,r4rs, Revised(4) Scheme}).
@node Dynamic-Wind, Eval, Promises, Standards Support
@@ -10126,7 +10912,7 @@ This facility is a generalization of Common LISP @code{unwind-protect},
designed to take into account the fact that continuations produced by
@code{call-with-current-continuation} may be reentered.
-@deffn Procedure dynamic-wind thunk1 thunk2 thunk3
+@deffn {Procedure} dynamic-wind thunk1 thunk2 thunk3
The arguments @var{thunk1}, @var{thunk2}, and @var{thunk3} must all be
procedures of no arguments (thunks).
@@ -10150,6 +10936,7 @@ the time of the error or interrupt.
@subsection Eval
@code{(require 'eval)}
+@ftindex eval
@defun eval expression environment-specifier
@@ -10270,15 +11057,49 @@ unspecified.
@menu
* SRFI-1:: list-processing
+* SRFI-2:: guarded LET* special form
+* SRFI-8:: Binding to multiple values
+* SRFI-9:: Defining Record Types
@end menu
-@node SRFI-1, , SRFI, SRFI
+@node SRFI-1, SRFI-2, SRFI, SRFI
@subsubsection SRFI-1
@include srfi-1.txi
+@node SRFI-2, SRFI-8, SRFI-1, SRFI
+@subsubsection SRFI-2
+
+@include srfi-2.txi
-@node Session Support, Extra-SLIB Packages, Standards Support, Other Packages
+@node SRFI-8, SRFI-9, SRFI-2, SRFI
+@subsubsection SRFI-8
+
+@include srfi-8.txi
+
+@node SRFI-9, , SRFI-8, SRFI
+@subsubsection SRFI-9
+
+@code{(require 'srfi-9)}
+@ftindex srfi-9
+
+@url{http://srfi.schemers.org/srfi-9/srfi-9.html}
+
+@defspec define-record-type <type-name> (<constructor-name> <field-tag> ...) <predicate-name> <field spec> ...
+
+Where
+@lisp
+<field-spec> @equiv{} (<field-tag> <accessor-name>)
+ @equiv{} (<field-tag> <accessor-name> <modifier-name>)
+
+@end lisp
+
+@code{define-record-type} is a syntax wrapper for the SLIB
+@code{record} module.
+@end defspec
+
+
+@node Session Support, System Interface, Standards Support, Other Packages
@section Session Support
@menu
@@ -10287,7 +11108,6 @@ unspecified.
* Debug:: To err is human ...
* Breakpoints:: Pause execution
* Trace:: 'trace
-* System Interface:: 'system, 'getenv, and 'net-clients
@end menu
@@ -10299,7 +11119,7 @@ unspecified.
Here is a read-eval-print-loop which, given an eval, evaluates forms.
-@deffn Procedure repl:top-level repl:eval
+@deffn {Procedure} repl:top-level repl:eval
@code{read}s, @code{repl:eval}s and @code{write}s expressions from
@code{(current-input-port)} to @code{(current-output-port)} until an
end-of-file is encountered. @code{load}, @code{slib:eval},
@@ -10307,7 +11127,7 @@ end-of-file is encountered. @code{load}, @code{slib:eval},
@code{repl:top-level}.
@end deffn
-@deffn Procedure repl:quit
+@deffn {Procedure} repl:quit
Exits from the invocation of @code{repl:top-level}.
@end deffn
@@ -10350,9 +11170,9 @@ Common-Lisp's @ref{Format} from consideration; even when variables
bit-vectors are @emph{not} limited.
@end quotation
-@deffn Procedure qp arg1 @dots{}
-@deffnx Procedure qpn arg1 @dots{}
-@deffnx Procedure qpr arg1 @dots{}
+@deffn {Procedure} qp arg1 @dots{}
+@deffnx {Procedure} qpn arg1 @dots{}
+@deffnx {Procedure} qpr arg1 @dots{}
@code{qp} writes its arguments, separated by spaces, to
@code{(current-output-port)}. @code{qp} compresses printing by
substituting @samp{...} for substructure it does not have sufficient
@@ -10362,8 +11182,11 @@ its last argument.
@end deffn
@defvar *qp-width*
-@code{*qp-width*} is the largest number of characters that @code{qp}
-should use.
+@var{*qp-width*} is the largest number of characters that @code{qp}
+should use. If @var{*qp-width*} is #f, then all items will be
+@code{write}n. If @var{*qp-width*} is 0, then all items except
+procedures will be @code{write}n; procedures will be indicated by
+@samp{#[proc]}.
@end defvar
@node Debug, Breakpoints, Quick Print, Session Support
@@ -10387,18 +11210,20 @@ printer for @code{qp}. This example shows how to do this:
@ftindex debug
@end example
-@deffn Procedure trace-all file @dots{}
+@deffn {Procedure} trace-all file @dots{}
Traces (@pxref{Trace}) all procedures @code{define}d at top-level in
@file{file} @dots{}.
-@deffnx Procedure track-all file @dots{}
+
+@deffnx {Procedure} track-all file @dots{}
Tracks (@pxref{Trace}) all procedures @code{define}d at top-level in
@file{file} @dots{}.
-@deffnx Procedure stack-all file @dots{}
+
+@deffnx {Procedure} stack-all file @dots{}
Stacks (@pxref{Trace}) all procedures @code{define}d at top-level in
@file{file} @dots{}.
@end deffn
-@deffn Procedure break-all file @dots{}
+@deffn {Procedure} break-all file @dots{}
Breakpoints (@pxref{Breakpoints}) all procedures @code{define}d at
top-level in @file{file} @dots{}.
@end deffn
@@ -10483,7 +11308,7 @@ To unbreak, type
@end lisp
@end defun
-@node Trace, System Interface, Breakpoints, Session Support
+@node Trace, , Breakpoints, Session Support
@subsection Tracing
@code{(require 'trace)}
@@ -10567,6 +11392,10 @@ supported by your implementation, these might be more convenient to use.
@defun tracef proc
@defunx tracef proc name
+@defunx trackf proc
+@defunx trackf proc name
+@defunx stackf proc
+@defunx stackf proc name
To trace, type
@lisp
(set! @var{symbol} (tracef @var{symbol}))
@@ -10597,8 +11426,8 @@ To untrace, type
@end defun
-@node System Interface, , Trace, Session Support
-@subsection System Interface
+@node System Interface, Extra-SLIB Packages, Session Support, Other Packages
+@section System Interface
@noindent
If @code{(provided? 'getenv)}:
@@ -10616,18 +11445,43 @@ Executes the @var{command-string} on the computer and returns the
integer status code.
@end defun
+
+@menu
+* Directories::
+* Transactions::
+* CVS::
+@end menu
+
+@node Directories, Transactions, System Interface, System Interface
+@subsection Directories
+
+@include dirs.txi
+
+
+@node Transactions, CVS, Directories, System Interface
+@subsection Transactions
+
@noindent
If @code{system} is provided by the Scheme implementation, the
-@dfn{net-clients} package provides interfaces to common network client
-programs like FTP, mail, and Netscape.
+@dfn{transact} package provides functions for file-locking and
+file-replacement transactions.
+
+@code{(require 'transact)}
+@ftindex transact
+
+@include transact.txi
-@code{(require 'net-clients)}
-@ftindex net-clients
-@include nclients.txi
+@node CVS, , Transactions, System Interface
+@subsection CVS
+@code{(require 'cvs)}
+@ftindex cvs
-@node Extra-SLIB Packages, , Session Support, Other Packages
+@include cvs.txi
+
+
+@node Extra-SLIB Packages, , System Interface, Other Packages
@section Extra-SLIB Packages
Several Scheme packages have been written using SLIB. There are several
@@ -10690,18 +11544,19 @@ http://www.cs.tut.fi/staff/pk/scheme/psd/article/article.html
@sp 1
@item SCHELOG
-is an embedding of Prolog in Scheme.
+is an embedding of Prolog in Scheme.@*
@ifset html
-<A HREF="http://www.cs.rice.edu/CS/PLT/packages/schelog/">
+<A HREF="http://www.ccs.neu.edu/~dorai/schelog/schelog.html">
@end ifset
-http://www.cs.rice.edu/CS/PLT/packages/schelog/
+http://www.ccs.neu.edu/~dorai/schelog/schelog.html
@ifset html
</A>
@end ifset
@sp 1
@item JFILTER
-is a Scheme program which converts text among the JIS, EUC, and Shift-JIS Japanese character sets.
+is a Scheme program which converts text among the JIS, EUC, and
+Shift-JIS Japanese character sets.@*
@ifset html
<A HREF="http://www.sci.toyama-u.ac.jp/~iwao/Scheme/Jfilter/index.html">
@end ifset
@@ -10733,13 +11588,13 @@ Aubrey Jaffer <agj @@ alum.mit.edu>@*
* Porting:: SLIB to new platforms.
* Coding Guidelines:: How to write modules for SLIB.
* Copyrights:: Intellectual propery issues.
+* About this manual::
@end menu
@node Installation, Porting, About SLIB, About SLIB
@section Installation
-
@ifset html
<A NAME="Installation">
@end ifset
@@ -10747,6 +11602,8 @@ Aubrey Jaffer <agj @@ alum.mit.edu>@*
</A>
@end ifset
+@cindex install
+@cindex installation
There are four parts to installation:
@itemize @bullet
@@ -10818,6 +11675,15 @@ SLIB), then:
(require 'new-catalog)
@end example
+The catalog also supports color-name dictionaries. With an
+SLIB-installed scheme implementation, type:
+@example
+(require 'color-names)
+(make-slib-color-name-db)
+(require 'new-catalog)
+(slib:exit)
+@end example
+
@subsection Implementation-specific Instructions
Multiple implementations of Scheme can all use the same SLIB directory.
@@ -10885,7 +11751,7 @@ initialization file.
To use SLIB in MzScheme, set the @var{SCHEME_LIBRARY_PATH} environment
variable to the installed SLIB location; then invoke MzScheme thus:
-@code{mzscheme -L init.ss slibinit}
+@code{mzscheme -f $@{SCHEME_LIBRARY_PATH@}DrScheme.init}
@end deftp
@deftp Implementation {MIT Scheme}
@@ -10903,10 +11769,15 @@ variable to the installed SLIB location; then invoke MzScheme thus:
If there is no initialization file for your Scheme implementation, you
will have to create one. Your Scheme implementation must be largely
-compliant with @cite{IEEE Std 1178-1990}, @cite{Revised^4 Report on the
-Algorithmic Language Scheme}, or @cite{Revised^5 Report on the
-Algorithmic Language Scheme} in order to support SLIB. @footnote{If you
-are porting a @cite{Revised^3 Report on the Algorithmic Language Scheme}
+compliant with
+@lisp
+@cite{IEEE Std 1178-1990},
+@cite{Revised^4 Report on the Algorithmic Language Scheme}, or
+@cite{Revised^5 Report on the Algorithmic Language Scheme}
+@end lisp
+@noindent
+in order to support SLIB. @footnote{If you are porting a
+@cite{Revised^3 Report on the Algorithmic Language Scheme}
implementation, then you will need to finish writing @file{sc4sc3.scm}
and @code{load} it from your initialization file.}
@@ -10921,9 +11792,9 @@ Your customized version should then be loaded as part of your scheme
implementation's initialization. It will load @file{require.scm} from
the library; this will allow the use of @code{provide},
@code{provided?}, and @code{require} along with the @dfn{vicinity}
-functions (these functions are documented in the section @ref{Require}).
-The rest of the library will then be accessible in a system independent
-fashion.
+functions (these functions are documented in the sections
+@ref{Feature} and @ref{Require}). The rest of the library will then
+be accessible in a system independent fashion.
Please mail new working configuration files to @code{agj @@ alum.mit.edu}
so that they can be included in the SLIB distribution.
@@ -10935,28 +11806,39 @@ so that they can be included in the SLIB distribution.
All library packages are written in IEEE P1178 Scheme and assume that a
configuration file and @file{require.scm} package have already been
loaded. Other versions of Scheme can be supported in library packages
-as well by using, for example, @code{(provided? 'rev3-report)} or
-@code{(require 'rev3-report)} (@pxref{Require}).
-@ftindex rev3-report
+as well by using, for example, @code{(provided? 'r3rs)} or
+@code{(require 'r3rs)} (@pxref{Require}).
+@ftindex r3rs
+
+If a procedure defined in a module is called by other procedures in
+that module, then those procedures should instead call an alias
+defined in that module:
-The module name and @samp{:} should prefix each symbol defined in the
-package. Definitions for external use should then be exported by having
-@code{(define foo module-name:foo)}.
+@lisp
+(define module-name:foo foo)
+@end lisp
+
+The module name and @samp{:} should prefix that symbol for the
+internal name. Do not export internal aliases.
-Code submitted for inclusion in SLIB should not duplicate routines
-already in SLIB files. Use @code{require} to force those library
-routines to be used by your package. Care should be taken that there
-are no circularities in the @code{require}s and @code{load}s between the
-library packages.
+A procedure is exported from a module by putting Schmooz-style
+comments (@pxref{Schmooz}) or @samp{;@@} at the beginning of the line
+immediately preceding the definition (@code{define},
+@code{define-syntax}, or @code{defmacro}). Modules, exports and other
+relevant issues are discussed in @ref{Compiling Scheme}.
+
+Code submitted for inclusion in SLIB should not duplicate (more than
+one) routines already in SLIB files. Use @code{require} to force
+those library routines to be used by your package.
Documentation should be provided in Emacs Texinfo format if possible,
-But documentation must be provided.
+but documentation must be provided.
Your package will be released sooner with SLIB if you send me a file
which tests your code. Please run this test @emph{before} you send me
the code!
-@subheading Modifications
+@subsection Modifications
Please document your changes. A line or two for @file{ChangeLog} is
sufficient for simple fixes or extensions. Look at the format of
@@ -10975,7 +11857,7 @@ Please @emph{do not} reformat the source code with your favorite
beautifier, make 10 fixes, and send me the resulting source code. I do
not have the time to fish through 10000 diffs to find your 10 real fixes.
-@node Copyrights, , Coding Guidelines, About SLIB
+@node Copyrights, About this manual, Coding Guidelines, About SLIB
@section Copyrights
@ifset html
@@ -10986,6 +11868,7 @@ not have the time to fish through 10000 diffs to find your 10 real fixes.
@end ifset
This section has instructions for SLIB authors regarding copyrights.
+@cindex copyright
Each package in SLIB must either be in the public domain, or come with a
statement of terms permitting users to copy, redistribute and modify it.
@@ -10995,88 +11878,111 @@ The comments at the beginning of @file{require.scm} and
If your code or changes amount to less than about 10 lines, you do not
need to add your copyright or send a disclaimer.
-@subheading Putting code into the Public Domain
+@subsection Putting code into the Public Domain
In order to put code in the public domain you should sign a copyright
disclaimer and send it to the SLIB maintainer. Contact
agj @@ alum.mit.edu for the address to mail the disclaimer to.
+@need 1000
@quotation
-I, @var{name}, hereby affirm that I have placed the software package
-@var{name} in the public domain.
+I, @var{<my-name>}, hereby affirm that I have placed the software
+package @var{<name>} in the public domain.
I affirm that I am the sole author and sole copyright holder for the
software package, that I have the right to place this software package
in the public domain, and that I will do nothing to undermine this
status in the future.
-
@flushright
@var{signature and date}
@end flushright
@end quotation
This wording assumes that you are the sole author. If you are not the
-sole author, the wording needs to be different. If you don't want to be
-bothered with sending a letter every time you release or modify a
+sole author, the wording needs to be different. If you don't want to
+be bothered with sending a letter every time you release or modify a
module, make your letter say that it also applies to your future
revisions of that module.
-Make sure no employer has any claim to the copyright on the work you are
-submitting. If there is any doubt, create a copyright disclaimer and
-have your employer sign it. Mail the signed disclaimer to the SLIB
-maintainer. Contact agj @@ alum.mit.edu for the address to mail the
-disclaimer to. An example disclaimer follows.
+Make sure no employer has any claim to the copyright on the work you
+are submitting. If there is any doubt, create a copyright disclaimer
+and have your employer sign it. Mail the signed disclaimer to the
+SLIB maintainer. Contact agj @@ alum.mit.edu for the address to mail
+the disclaimer to. An example disclaimer follows.
-@subheading Explicit copying terms
+@subsection Explicit copying terms
@noindent
-If you submit more than about 10 lines of code which you are not placing
-into the Public Domain (by sending me a disclaimer) you need to:
+If you submit more than about 10 lines of code which you are not
+placing into the Public Domain (by sending me a disclaimer) you need
+to:
@itemize @bullet
@item
Arrange that your name appears in a copyright line for the appropriate
-year. Multiple copyright lines are acceptable.
+year. Multiple copyright lines are acceptable.
@item
-With your copyright line, specify any terms you require to be different
-from those already in the file.
+With your copyright line, specify any terms you require to be
+different from those already in the file.
@item
-Make sure no employer has any claim to the copyright on the work you are
-submitting. If there is any doubt, create a copyright disclaimer and
-have your employer sign it. Mail the signed disclaim to the SLIB
+Make sure no employer has any claim to the copyright on the work you
+are submitting. If there is any doubt, create a copyright disclaimer
+and have your employer sign it. Mail the signed disclaim to the SLIB
maintainer. Contact agj @@ alum.mit.edu for the address to mail the
disclaimer to.
@end itemize
-@subheading Example: Company Copyright Disclaimer
+@subsection Example: Company Copyright Disclaimer
-This disclaimer should be signed by a vice president or general manager
-of the company. If you can't get at them, anyone else authorized to
-license out software produced there will do. Here is a sample wording:
+This disclaimer should be signed by a vice president or general
+manager of the company. If you can't get at them, anyone else
+authorized to license out software produced there will do. Here is a
+sample wording:
@quotation
-@var{employer} Corporation hereby disclaims all copyright
-interest in the program @var{program} written by @var{name}.
+@var{<employer>} Corporation hereby disclaims all copyright
+interest in the program @var{<program>} written by @var{<name>}.
-@var{employer} Corporation affirms that it has no other intellectual
-property interest that would undermine this release, and will do nothing
-to undermine it in the future.
+@var{<employer>} Corporation affirms that it has no other intellectual
+property interest that would undermine this release, and will do
+nothing to undermine it in the future.
@flushleft
-@var{signature and date},
-@var{name}, @var{title}, @var{employer} Corporation
+@var{<signature and date>},
+@var{<name>}, @var{<title>}, @var{<employer>} Corporation
@end flushleft
@end quotation
+@node About this manual, , Copyrights, About SLIB
+@section About this manual
+
+@itemize @bullet
+@item
+Entries that are labeled as Functions are called for their return
+values. Entries that are labeled as Procedures are called primarily for
+their side effects.
+
+@item
+Examples in this text were produced using the @code{scm} Scheme
+implementation.
+
+@item
+At the beginning of each section, there is a line that looks like
+@ftindex feature
+@code{(require 'feature)}. Include this line in your code prior to
+using the package.
+@end itemize
+
+
@node Index, , About SLIB, Top
-@c @node Procedure and Macro Index, Variable Index, About SLIB, Top
+@c @node Procedure and Macro Index, Operator Index, About SLIB, Top
@unnumbered Procedure and Macro Index
This is an alphabetical list of all the procedures and macros in SLIB.
@printindex fn
-@c @node Variable Index, Concept Index, Procedure and Macro Index, Top
+@c @node Variable Index, Concept Index, Operator Index, Top
@unnumbered Variable Index
This is an alphabetical list of all the global variables in SLIB.