1 This is slib.info, produced by makeinfo version 4.0 from slib.texi.
3 INFO-DIR-SECTION The Algorithmic Language Scheme
5 * SLIB: (slib). Scheme Library
8 This file documents SLIB, the portable Scheme library.
10 Copyright (C) 1993 Todd R. Eigenschink
11 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000 Aubrey
14 Permission is granted to make and distribute verbatim copies of this
15 manual provided the copyright notice and this permission notice are
16 preserved on all copies.
18 Permission is granted to copy and distribute modified versions of this
19 manual under the conditions for verbatim copying, provided that the
20 entire resulting derived work is distributed under the terms of a
21 permission notice identical to this one.
23 Permission is granted to copy and distribute translations of this
24 manual into another language, under the above conditions for modified
25 versions, except that this permission notice may be stated in a
26 translation approved by the author.
29 File: slib.info, Node: Top, Next: The Library System, Prev: (dir), Up: (dir)
31 "SLIB" is a portable library for the programming language "Scheme". It
32 provides a platform independent framework for using "packages" of
33 Scheme procedures and syntax. As distributed, SLIB contains useful
34 packages for all Scheme implementations. Its catalog can be
35 transparently extended to accomodate packages specific to a site,
36 implementation, user, or directory.
40 * The Library System:: How to use and customize.
41 * Scheme Syntax Extension Packages::
42 * Textual Conversion Packages::
43 * Mathematical Packages::
46 * About SLIB:: Install, etc.
50 File: slib.info, Node: The Library System, Next: Scheme Syntax Extension Packages, Prev: Top, Up: Top
57 * Feature:: SLIB names.
58 * Requesting Features::
60 * Catalog Compilation::
65 File: slib.info, Node: Feature, Next: Requesting Features, Prev: The Library System, Up: The Library System
70 SLIB denotes "features" by symbols. SLIB maintains a list of features
71 supported by the Scheme "session". The set of features provided by a
72 session may change over time. Some features are properties of the
73 Scheme implementation being used. The following features detail what
74 sort of numbers are available from an implementation.
86 Other features correspond to the presence of sets of Scheme procedures
89 - Function: provided? feature
90 Returns `#t' if FEATURE is supported by the current Scheme session.
92 - Procedure: provide feature
93 Informs SLIB that FEATURE is supported. Henceforth `(provided?
94 FEATURE)' will return `#t'.
96 (provided? 'foo) => #f
98 (provided? 'foo) => #t
101 File: slib.info, Node: Requesting Features, Next: Library Catalogs, Prev: Feature, Up: The Library System
106 SLIB creates and maintains a "catalog" mapping features to locations of
107 files introducing procedures and syntax denoted by those features.
109 At the beginning of each section of this manual, there is a line like
110 `(require 'FEATURE)'. The Scheme files comprising SLIB are cataloged
111 so that these feature names map to the corresponding files.
113 SLIB provides a form, `require', which loads the files providing the
116 - Procedure: require feature
117 * If `(provided? FEATURE)' is true, then `require' just returns
118 an unspecified value.
120 * Otherwise, if FEATURE is found in the catalog, then the
121 corresponding files will be loaded and an unspecified value
124 Subsequently `(provided? FEATURE)' will return `#t'.
126 * Otherwise (FEATURE not found in the catalog), an error is
129 The catalog can also be queried using `require:feature->path'.
131 - Function: require:feature->path feature
132 * If FEATURE is already provided, then returns `#t'.
134 * Otherwise, if FEATURE is in the catalog, the path or list of
135 paths associated with FEATURE is returned.
137 * Otherwise, returns `#f'.
140 File: slib.info, Node: Library Catalogs, Next: Catalog Compilation, Prev: Requesting Features, Up: The Library System
145 At the start of a session no catalog is present, but is created with the
146 first catalog inquiry (such as `(require 'random)'). Several sources
147 of catalog information are combined to produce the catalog:
149 * standard SLIB packages.
151 * additional packages of interest to this site.
153 * packages specifically for the variety of Scheme which this session
156 * packages this user wants to always have available. This catalog
157 is the file `homecat' in the user's "HOME" directory.
159 * packages germane to working in this (current working) directory.
160 This catalog is the file `usercat' in the directory to which it
161 applies. One would typically `cd' to this directory before
162 starting the Scheme session.
164 Catalog files consist of one or more "association list"s. In the
165 circumstance where a feature symbol appears in more than one list, the
166 latter list's association is retrieved. Here are the supported formats
167 for elements of catalog lists:
169 `(FEATURE . <symbol>)'
170 Redirects to the feature named <symbol>.
172 `(FEATURE . "<path>")'
175 `(FEATURE source "<path>")'
176 `slib:load's the Scheme source file <path>.
178 `(FEATURE compiled "<path>" ...)'
179 `slib:load-compiled's the files <path> ....
181 The various macro styles first `require' the named macro package, then
182 just load <path> or load-and-macro-expand <path> as appropriate for the
185 `(FEATURE defmacro "<path>")'
186 `defmacro:load's the Scheme source file <path>.
188 `(FEATURE macro-by-example "<path>")'
189 `defmacro:load's the Scheme source file <path>.
191 `(FEATURE macro "<path>")'
192 `macro:load's the Scheme source file <path>.
194 `(FEATURE macros-that-work "<path>")'
195 `macro:load's the Scheme source file <path>.
197 `(FEATURE syntax-case "<path>")'
198 `macro:load's the Scheme source file <path>.
200 `(FEATURE syntactic-closures "<path>")'
201 `macro:load's the Scheme source file <path>.
203 Here is an example of a `usercat' catalog. A Program in this directory
204 can invoke the `run' feature with `(require 'run)'.
206 ;;; "usercat": SLIB catalog additions for SIMSYNCH. -*-scheme-*-
209 (simsynch . "../synch/simsynch.scm")
210 (run . "../synch/run.scm")
211 (schlep . "schlep.scm")
215 File: slib.info, Node: Catalog Compilation, Next: Built-in Support, Prev: Library Catalogs, Up: The Library System
220 SLIB combines the catalog information which doesn't vary per user into
221 the file `slibcat' in the implementation-vicinity. Therefore `slibcat'
222 needs change only when new software is installed or compiled. Because
223 the actual pathnames of files can differ from installation to
224 installation, SLIB builds a separate catalog for each implementation it
227 The definition of `*SLIB-VERSION*' in SLIB file `require.scm' is
228 checked against the catalog association of `*SLIB-VERSION*' to
229 ascertain when versions have changed. I recommend that the definition
230 of `*SLIB-VERSION*' be changed whenever the library is changed. If
231 multiple implementations of Scheme use SLIB, remember that recompiling
232 one `slibcat' will fix only that implementation's catalog.
234 The compilation scripts of Scheme implementations which work with SLIB
235 can automatically trigger catalog compilation by deleting `slibcat' or
236 by invoking a special form of `require':
238 - Procedure: require 'new-catalog
239 This will load `mklibcat', which compiles and writes a new
242 Another special form of `require' erases SLIB's catalog, forcing it to
243 be reloaded the next time the catalog is queried.
245 - Procedure: require #f
246 Removes SLIB's catalog information. This should be done before
247 saving an executable image so that, when restored, its catalog
248 will be loaded afresh.
250 Each file in the table below is descibed in terms of its file-system
251 independent "vicinity" (*note Vicinity::). The entries of a catalog in
252 the table override those of catalogs above it in the table.
254 `implementation-vicinity' `slibcat'
255 This file contains the associations for the packages comprising
256 SLIB, the `implcat' and the `sitecat's. The associations in the
257 other catalogs override those of the standard catalog.
259 `library-vicinity' `mklibcat.scm'
262 `library-vicinity' `sitecat'
263 This file contains the associations specific to an SLIB
266 `implementation-vicinity' `implcat'
267 This file contains the associations specific to an implementation
268 of Scheme. Different implementations of Scheme should have
269 different `implementation-vicinity'.
271 `implementation-vicinity' `mkimpcat.scm'
272 if present, creates `implcat'.
274 `implementation-vicinity' `sitecat'
275 This file contains the associations specific to a Scheme
276 implementation installation.
278 `home-vicinity' `homecat'
279 This file contains the associations specific to an SLIB user.
281 `user-vicinity' `usercat'
282 This file contains associations effecting only those sessions whose
283 "working directory" is `user-vicinity'.
286 File: slib.info, Node: Built-in Support, Next: About this manual, Prev: Catalog Compilation, Up: The Library System
291 The procedures described in these sections are supported by all
292 implementations as part of the `*.init' files or by `require.scm'.
296 * Require:: Module Management
297 * Vicinity:: Pathname Management
298 * Configuration:: Characteristics of Scheme Implementation
299 * Input/Output:: Things not provided by the Scheme specs.
301 * System:: LOADing, EVALing, ERRORing, and EXITing
304 File: slib.info, Node: Require, Next: Vicinity, Prev: Built-in Support, Up: Built-in Support
309 - Variable: *features*
310 Is a list of symbols denoting features supported in this
311 implementation. *FEATURES* can grow as modules are `require'd.
312 *FEATURES* must be defined by all implementations (*note
315 Here are features which SLIB (`require.scm') adds to *FEATURES*
328 For each item, `(provided? 'FEATURE)' will return `#t' if that
329 feature is available, and `#f' if not.
331 - Variable: *modules*
332 Is a list of pathnames denoting files which have been loaded.
334 - Variable: *catalog*
335 Is an association list of features (symbols) and pathnames which
336 will supply those features. The pathname can be either a string
337 or a pair. If pathname is a pair then the first element should be
338 a macro feature symbol, `source', or `compiled'. The cdr of the
339 pathname should be either a string or a list.
341 In the following functions if the argument FEATURE is not a symbol it
342 is assumed to be a pathname.
344 - Function: provided? feature
345 Returns `#t' if FEATURE is a member of `*features*' or `*modules*'
346 or if FEATURE is supported by a file already loaded and `#f'
349 - Procedure: require feature
350 FEATURE is a symbol. If `(provided? FEATURE)' is true `require'
351 returns. Otherwise, if `(assq FEATURE *catalog*)' is not `#f',
352 the associated files will be loaded and `(provided? FEATURE)' will
353 henceforth return `#t'. An unspecified value is returned. If
354 FEATURE is not found in `*catalog*', then an error is signaled.
356 - Procedure: require pathname
357 PATHNAME is a string. If PATHNAME has not already been given as
358 an argument to `require', PATHNAME is loaded. An unspecified
361 - Procedure: provide feature
362 Assures that FEATURE is contained in `*features*' if FEATURE is a
363 symbol and `*modules*' otherwise.
365 - Function: require:feature->path feature
366 Returns `#t' if FEATURE is a member of `*features*' or `*modules*'
367 or if FEATURE is supported by a file already loaded. Returns a
368 path if one was found in `*catalog*' under the feature name, and
369 `#f' otherwise. The path can either be a string suitable as an
370 argument to load or a pair as described above for *catalog*.
373 File: slib.info, Node: Vicinity, Next: Configuration, Prev: Require, Up: Built-in Support
378 A vicinity is a descriptor for a place in the file system. Vicinities
379 hide from the programmer the concepts of host, volume, directory, and
380 version. Vicinities express only the concept of a file environment
381 where a file name can be resolved to a file in a system independent
382 manner. Vicinities can even be used on "flat" file systems (which have
383 no directory structure) by having the vicinity express constraints on
384 the file name. On most systems a vicinity would be a string. All of
385 these procedures are file system dependent.
387 These procedures are provided by all implementations.
389 - Function: make-vicinity path
390 Returns the vicinity of PATH for use by `in-vicinity'.
392 - Function: program-vicinity
393 Returns the vicinity of the currently loading Scheme code. For an
394 interpreter this would be the directory containing source code.
395 For a compiled system (with multiple files) this would be the
396 directory where the object or executable files are. If no file is
397 currently loading it the result is undefined. *Warning:*
398 `program-vicinity' can return incorrect values if your program
399 escapes back into a `load'.
401 - Function: library-vicinity
402 Returns the vicinity of the shared Scheme library.
404 - Function: implementation-vicinity
405 Returns the vicinity of the underlying Scheme implementation. This
406 vicinity will likely contain startup code and messages and a
409 - Function: user-vicinity
410 Returns the vicinity of the current directory of the user. On most
411 systems this is `""' (the empty string).
413 - Function: home-vicinity
414 Returns the vicinity of the user's "HOME" directory, the directory
415 which typically contains files which customize a computer
416 environment for a user. If scheme is running without a user (eg.
417 a daemon) or if this concept is meaningless for the platform, then
418 `home-vicinity' returns `#f'.
420 - Function: in-vicinity vicinity filename
421 Returns a filename suitable for use by `slib:load',
422 `slib:load-source', `slib:load-compiled', `open-input-file',
423 `open-output-file', etc. The returned filename is FILENAME in
424 VICINITY. `in-vicinity' should allow FILENAME to override
425 VICINITY when FILENAME is an absolute pathname and VICINITY is
426 equal to the value of `(user-vicinity)'. The behavior of
427 `in-vicinity' when FILENAME is absolute and VICINITY is not equal
428 to the value of `(user-vicinity)' is unspecified. For most systems
429 `in-vicinity' can be `string-append'.
431 - Function: sub-vicinity vicinity name
432 Returns the vicinity of VICINITY restricted to NAME. This is used
433 for large systems where names of files in subsystems could
434 conflict. On systems with directory structure `sub-vicinity' will
435 return a pathname of the subdirectory NAME of VICINITY.
438 File: slib.info, Node: Configuration, Next: Input/Output, Prev: Vicinity, Up: Built-in Support
443 These constants and procedures describe characteristics of the Scheme
444 and underlying operating system. They are provided by all
447 - Constant: char-code-limit
448 An integer 1 larger that the largest value which can be returned by
451 - Constant: most-positive-fixnum
452 In implementations which support integers of practically unlimited
453 size, MOST-POSITIVE-FIXNUM is a large exact integer within the
454 range of exact integers that may result from computing the length
455 of a list, vector, or string.
457 In implementations which do not support integers of practically
458 unlimited size, MOST-POSITIVE-FIXNUM is the largest exact integer
459 that may result from computing the length of a list, vector, or
465 - Constant: slib:form-feed
466 The form-feed character.
468 - Function: software-type
469 Returns a symbol denoting the generic operating system type. For
470 instance, `unix', `vms', `macos', `amiga', or `ms-dos'.
472 - Function: slib:report-version
473 Displays the versions of SLIB and the underlying Scheme
474 implementation and the name of the operating system. An
475 unspecified value is returned.
477 (slib:report-version) => slib "2d1" on scm "5b1" on unix |
479 - Function: slib:report
480 Displays the information of `(slib:report-version)' followed by
481 almost all the information neccessary for submitting a problem
482 report. An unspecified value is returned.
484 - Function: slib:report #t
485 provides a more verbose listing.
487 - Function: slib:report filename
488 Writes the report to file `filename'.
492 slib "2d1" on scm "5b1" on unix |
493 (implementation-vicinity) is "/home/jaffer/scm/"
494 (library-vicinity) is "/home/jaffer/slib/"
495 (scheme-file-suffix) is ".scm"
498 common-list-functions macro values getopt
500 implementation *features* :
501 bignum complex real rational
502 inexact vicinity ed getenv
503 tmpnam abort transcript with-file
504 ieee-p1178 rev4-report rev4-optional-procedures hash
505 object-hash delay eval dynamic-wind
506 multiarg-apply multiarg/and- logical defmacro
507 string-port source current-time record
508 rev3-procedures rev2-procedures sun-dl string-case
509 array dump char-ready? full-continuation
511 implementation *catalog* :
512 (i/o-extensions compiled "/home/jaffer/scm/ioext.so")
516 File: slib.info, Node: Input/Output, Next: Legacy, Prev: Configuration, Up: Built-in Support
521 These procedures are provided by all implementations.
523 - Procedure: file-exists? filename
524 Returns `#t' if the specified file exists. Otherwise, returns
525 `#f'. If the underlying implementation does not support this
526 feature then `#f' is always returned.
528 - Procedure: delete-file filename
529 Deletes the file specified by FILENAME. If FILENAME can not be
530 deleted, `#f' is returned. Otherwise, `#t' is returned.
533 Returns a pathname for a file which will likely not be used by any
534 other process. Successive calls to `(tmpnam)' will return
537 - Procedure: current-error-port
538 Returns the current port to which diagnostic and error output is
541 - Procedure: force-output
542 - Procedure: force-output port
543 Forces any pending output on PORT to be delivered to the output
544 device and returns an unspecified value. The PORT argument may be
545 omitted, in which case it defaults to the value returned by
546 `(current-output-port)'.
548 - Procedure: output-port-width
549 - Procedure: output-port-width port
550 Returns the width of PORT, which defaults to
551 `(current-output-port)' if absent. If the width cannot be
552 determined 79 is returned.
554 - Procedure: output-port-height
555 - Procedure: output-port-height port
556 Returns the height of PORT, which defaults to
557 `(current-output-port)' if absent. If the height cannot be
558 determined 24 is returned.
561 File: slib.info, Node: Legacy, Next: System, Prev: Input/Output, Up: Built-in Support
566 These procedures are provided by all implementations.
568 - Function: identity x
569 IDENTITY returns its argument.
574 (identity '(foo bar))
579 The following procedures were present in Scheme until R4RS (*note
580 Language changes: (r4rs)Notes.). They are provided by all SLIB
589 - Function: last-pair l
590 Returns the last pair in the list L. Example:
591 (last-pair (cons 1 2))
598 File: slib.info, Node: System, Prev: Legacy, Up: Built-in Support
603 These procedures are provided by all implementations.
605 - Procedure: slib:load-source name
606 Loads a file of Scheme source code from NAME with the default
607 filename extension used in SLIB. For instance if the filename
608 extension used in SLIB is `.scm' then `(slib:load-source "foo")'
609 will load from file `foo.scm'.
611 - Procedure: slib:load-compiled name
612 On implementations which support separtely loadable compiled
613 modules, loads a file of compiled code from NAME with the
614 implementation's filename extension for compiled code appended.
616 - Procedure: slib:load name
617 Loads a file of Scheme source or compiled code from NAME with the
618 appropriate suffixes appended. If both source and compiled code
619 are present with the appropriate names then the implementation
620 will load just one. It is up to the implementation to choose
621 which one will be loaded.
623 If an implementation does not support compiled code then
624 `slib:load' will be identical to `slib:load-source'.
626 - Procedure: slib:eval obj
627 `eval' returns the value of OBJ evaluated in the current top level
628 environment. *Note Eval:: provides a more general evaluation
631 - Procedure: slib:eval-load filename eval
632 FILENAME should be a string. If filename names an existing file,
633 the Scheme source code expressions and definitions are read from
634 the file and EVAL called with them sequentially. The
635 `slib:eval-load' procedure does not affect the values returned by
636 `current-input-port' and `current-output-port'.
638 - Procedure: slib:warn arg1 arg2 ...
639 Outputs a warning message containing the arguments.
641 - Procedure: slib:error arg1 arg2 ...
642 Outputs an error message containing the arguments, aborts
643 evaluation of the current form and responds in a system dependent
644 way to the error. Typical responses are to abort the program or
645 to enter a read-eval-print loop.
647 - Procedure: slib:exit n
648 - Procedure: slib:exit
649 Exits from the Scheme session returning status N to the system.
650 If N is omitted or `#t', a success status is returned to the
651 system (if possible). If N is `#f' a failure is returned to the
652 system (if possible). If N is an integer, then N is returned to
653 the system (if possible). If the Scheme session cannot exit an
654 unspecified value is returned from `slib:exit'.
657 File: slib.info, Node: About this manual, Prev: Built-in Support, Up: The Library System
662 * Entries that are labeled as Functions are called for their return
663 values. Entries that are labeled as Procedures are called
664 primarily for their side effects.
666 * Examples in this text were produced using the `scm' Scheme
669 * At the beginning of each section, there is a line that looks like
670 `(require 'feature)'. Include this line in your code prior to
674 File: slib.info, Node: Scheme Syntax Extension Packages, Next: Textual Conversion Packages, Prev: The Library System, Up: Top
676 Scheme Syntax Extension Packages
677 ********************************
681 * Defmacro:: Supported by all implementations
683 * R4RS Macros:: 'macro
684 * Macro by Example:: 'macro-by-example
685 * Macros That Work:: 'macros-that-work
686 * Syntactic Closures:: 'syntactic-closures
687 * Syntax-Case Macros:: 'syntax-case
689 Syntax extensions (macros) included with SLIB. Also *Note Structures::.
691 * Fluid-Let:: 'fluid-let
692 * Yasos:: 'yasos, 'oop, 'collect
695 File: slib.info, Node: Defmacro, Next: R4RS Macros, Prev: Scheme Syntax Extension Packages, Up: Scheme Syntax Extension Packages
700 Defmacros are supported by all implementations.
703 Returns a new (interned) symbol each time it is called. The symbol
704 names are implementation-dependent
708 - Function: defmacro:eval e
709 Returns the `slib:eval' of expanding all defmacros in scheme
712 - Function: defmacro:load filename
713 FILENAME should be a string. If filename names an existing file,
714 the `defmacro:load' procedure reads Scheme source code expressions
715 and definitions from the file and evaluates them sequentially.
716 These source code expressions and definitions may contain defmacro
717 definitions. The `macro:load' procedure does not affect the values
718 returned by `current-input-port' and `current-output-port'.
720 - Function: defmacro? sym
721 Returns `#t' if SYM has been defined by `defmacro', `#f' otherwise.
723 - Function: macroexpand-1 form
724 - Function: macroexpand form
725 If FORM is a macro call, `macroexpand-1' will expand the macro
726 call once and return it. A FORM is considered to be a macro call
727 only if it is a cons whose `car' is a symbol for which a
728 `defmacro' has been defined.
730 `macroexpand' is similar to `macroexpand-1', but repeatedly
731 expands FORM until it is no longer a macro call.
733 - Macro: defmacro name lambda-list form ...
734 When encountered by `defmacro:eval', `defmacro:macroexpand*', or
735 `defmacro:load' defines a new macro which will henceforth be
736 expanded when encountered by `defmacro:eval',
737 `defmacro:macroexpand*', or `defmacro:load'.
742 `(require 'defmacroexpand)'
744 - Function: defmacro:expand* e
745 Returns the result of expanding all defmacros in scheme expression
749 File: slib.info, Node: R4RS Macros, Next: Macro by Example, Prev: Defmacro, Up: Scheme Syntax Extension Packages
754 `(require 'macro)' is the appropriate call if you want R4RS
755 high-level macros but don't care about the low level implementation. If
756 an SLIB R4RS macro implementation is already loaded it will be used.
757 Otherwise, one of the R4RS macros implemetations is loaded.
759 The SLIB R4RS macro implementations support the following uniform
762 - Function: macro:expand sexpression
763 Takes an R4RS expression, macro-expands it, and returns the result
764 of the macro expansion.
766 - Function: macro:eval sexpression
767 Takes an R4RS expression, macro-expands it, evals the result of the
768 macro expansion, and returns the result of the evaluation.
770 - Procedure: macro:load filename
771 FILENAME should be a string. If filename names an existing file,
772 the `macro:load' procedure reads Scheme source code expressions and
773 definitions from the file and evaluates them sequentially. These
774 source code expressions and definitions may contain macro
775 definitions. The `macro:load' procedure does not affect the
776 values returned by `current-input-port' and `current-output-port'.
779 File: slib.info, Node: Macro by Example, Next: Macros That Work, Prev: R4RS Macros, Up: Scheme Syntax Extension Packages
784 `(require 'macro-by-example)'
786 A vanilla implementation of `Macro by Example' (Eugene Kohlbecker,
787 R4RS) by Dorai Sitaram, (dorai@cs.rice.edu) using `defmacro'.
789 * generating hygienic global `define-syntax' Macro-by-Example macros
792 * can define macros which use `...'.
794 * needn't worry about a lexical variable in a macro definition
795 clashing with a variable from the macro use context
797 * don't suffer the overhead of redefining the repl if `defmacro'
798 natively supported (most implementations)
804 These macros are not referentially transparent (*note Macros:
805 (r4rs)Macros.). Lexically scoped macros (i.e., `let-syntax' and
806 `letrec-syntax') are not supported. In any case, the problem of
807 referential transparency gains poignancy only when `let-syntax' and
808 `letrec-syntax' are used. So you will not be courting large-scale
809 disaster unless you're using system-function names as local variables
810 with unintuitive bindings that the macro can't use. However, if you
811 must have the full `r4rs' macro functionality, look to the more
812 featureful (but also more expensive) versions of syntax-rules available
813 in slib *Note Macros That Work::, *Note Syntactic Closures::, and *Note
814 Syntax-Case Macros::.
816 - Macro: define-syntax keyword transformer-spec
817 The KEYWORD is an identifier, and the TRANSFORMER-SPEC should be
818 an instance of `syntax-rules'.
820 The top-level syntactic environment is extended by binding the
821 KEYWORD to the specified transformer.
825 ((let* () body1 body2 ...)
826 (let () body1 body2 ...))
827 ((let* ((name1 val1) (name2 val2) ...)
830 (let* (( name2 val2) ...)
833 - Macro: syntax-rules literals syntax-rule ...
834 LITERALS is a list of identifiers, and each SYNTAX-RULE should be
839 where the PATTERN and TEMPLATE are as in the grammar above.
841 An instance of `syntax-rules' produces a new macro transformer by
842 specifying a sequence of hygienic rewrite rules. A use of a macro
843 whose keyword is associated with a transformer specified by
844 `syntax-rules' is matched against the patterns contained in the
845 SYNTAX-RULEs, beginning with the leftmost SYNTAX-RULE. When a
846 match is found, the macro use is trancribed hygienically according
849 Each pattern begins with the keyword for the macro. This keyword
850 is not involved in the matching and is not considered a pattern
851 variable or literal identifier.
854 File: slib.info, Node: Macros That Work, Next: Syntactic Closures, Prev: Macro by Example, Up: Scheme Syntax Extension Packages
859 `(require 'macros-that-work)'
861 `Macros That Work' differs from the other R4RS macro implementations
862 in that it does not expand derived expression types to primitive
865 - Function: macro:expand expression
866 - Function: macwork:expand expression
867 Takes an R4RS expression, macro-expands it, and returns the result
868 of the macro expansion.
870 - Function: macro:eval expression
871 - Function: macwork:eval expression
872 `macro:eval' returns the value of EXPRESSION in the current top
873 level environment. EXPRESSION can contain macro definitions.
874 Side effects of EXPRESSION will affect the top level environment.
876 - Procedure: macro:load filename
877 - Procedure: macwork:load filename
878 FILENAME should be a string. If filename names an existing file,
879 the `macro:load' procedure reads Scheme source code expressions and
880 definitions from the file and evaluates them sequentially. These
881 source code expressions and definitions may contain macro
882 definitions. The `macro:load' procedure does not affect the
883 values returned by `current-input-port' and `current-output-port'.
887 The `Revised^4 Report on the Algorithmic Language Scheme' Clinger and
888 Rees [editors]. To appear in LISP Pointers. Also available as a
889 technical report from the University of Oregon, MIT AI Lab, and Cornell.
891 Macros That Work. Clinger and Rees. POPL '91.
893 The supported syntax differs from the R4RS in that vectors are allowed
894 as patterns and as templates and are not allowed as pattern or template
897 transformer spec ==> (syntax-rules literals rules)
902 rule ==> (pattern template)
904 pattern ==> pattern_var ; a symbol not in literals
905 | symbol ; a symbol in literals
907 | (pattern . pattern)
909 | #(pattern*) ; extends R4RS
910 | #(pattern* ellipsis_pattern) ; extends R4RS
913 template ==> pattern_var
916 | (template2 . template2)
917 | #(template*) ; extends R4RS
920 template2 ==> template
923 pattern_datum ==> string ; no vector
928 ellipsis_pattern ==> pattern ...
930 ellipsis_template ==> template ...
932 pattern_var ==> symbol ; not in literals
935 | (symbol . literals)
941 Within a pattern or template, the scope of an ellipsis (`...') is
942 the pattern or template that appears to its left.
944 Rank of a pattern variable
945 The rank of a pattern variable is the number of ellipses within
946 whose scope it appears in the pattern.
948 Rank of a subtemplate
949 The rank of a subtemplate is the number of ellipses within whose
950 scope it appears in the template.
952 Template rank of an occurrence of a pattern variable
953 The template rank of an occurrence of a pattern variable within a
954 template is the rank of that occurrence, viewed as a subtemplate.
956 Variables bound by a pattern
957 The variables bound by a pattern are the pattern variables that
960 Referenced variables of a subtemplate
961 The referenced variables of a subtemplate are the pattern
962 variables that appear within it.
964 Variables opened by an ellipsis template
965 The variables opened by an ellipsis template are the referenced
966 pattern variables whose rank is greater than the rank of the
972 No pattern variable appears more than once within a pattern.
974 For every occurrence of a pattern variable within a template, the
975 template rank of the occurrence must be greater than or equal to the
976 pattern variable's rank.
978 Every ellipsis template must open at least one variable.
980 For every ellipsis template, the variables opened by an ellipsis
981 template must all be bound to sequences of the same length.
983 The compiled form of a RULE is
985 rule ==> (pattern template inserted)
987 pattern ==> pattern_var
990 | (pattern . pattern)
995 template ==> pattern_var
998 | (template2 . template2)
1002 template2 ==> template
1005 pattern_datum ==> string
1010 pattern_var ==> #(V symbol rank)
1012 ellipsis_pattern ==> #(E pattern pattern_vars)
1014 ellipsis_template ==> #(E template pattern_vars)
1017 | (symbol . inserted)
1020 | (pattern_var . pattern_vars)
1022 rank ==> exact non-negative integer
1024 where V and E are unforgeable values.
1026 The pattern variables associated with an ellipsis pattern are the
1027 variables bound by the pattern, and the pattern variables associated
1028 with an ellipsis template are the variables opened by the ellipsis
1031 If the template contains a big chunk that contains no pattern
1032 variables or inserted identifiers, then the big chunk will be copied
1033 unnecessarily. That shouldn't matter very often.
1036 File: slib.info, Node: Syntactic Closures, Next: Syntax-Case Macros, Prev: Macros That Work, Up: Scheme Syntax Extension Packages
1041 `(require 'syntactic-closures)'
1043 - Function: macro:expand expression
1044 - Function: synclo:expand expression
1045 Returns scheme code with the macros and derived expression types of
1046 EXPRESSION expanded to primitive expression types.
1048 - Function: macro:eval expression
1049 - Function: synclo:eval expression
1050 `macro:eval' returns the value of EXPRESSION in the current top
1051 level environment. EXPRESSION can contain macro definitions.
1052 Side effects of EXPRESSION will affect the top level environment.
1054 - Procedure: macro:load filename
1055 - Procedure: synclo:load filename
1056 FILENAME should be a string. If filename names an existing file,
1057 the `macro:load' procedure reads Scheme source code expressions and
1058 definitions from the file and evaluates them sequentially. These
1059 source code expressions and definitions may contain macro
1060 definitions. The `macro:load' procedure does not affect the
1061 values returned by `current-input-port' and `current-output-port'.
1063 Syntactic Closure Macro Facility
1064 --------------------------------
1066 A Syntactic Closures Macro Facility
1072 This document describes "syntactic closures", a low-level macro
1073 facility for the Scheme programming language. The facility is an
1074 alternative to the low-level macro facility described in the `Revised^4
1075 Report on Scheme.' This document is an addendum to that report.
1077 The syntactic closures facility extends the BNF rule for TRANSFORMER
1078 SPEC to allow a new keyword that introduces a low-level macro
1080 TRANSFORMER SPEC := (transformer EXPRESSION)
1082 Additionally, the following procedures are added:
1083 make-syntactic-closure
1084 capture-syntactic-environment
1088 The description of the facility is divided into three parts. The
1089 first part defines basic terminology. The second part describes how
1090 macro transformers are defined. The third part describes the use of
1091 "identifiers", which extend the syntactic closure mechanism to be
1092 compatible with `syntax-rules'.
1097 This section defines the concepts and data types used by the syntactic
1100 * "Forms" are the syntactic entities out of which programs are
1101 recursively constructed. A form is any expression, any
1102 definition, any syntactic keyword, or any syntactic closure. The
1103 variable name that appears in a `set!' special form is also a
1104 form. Examples of forms:
1114 * An "alias" is an alternate name for a given symbol. It can appear
1115 anywhere in a form that the symbol could be used, and when quoted
1116 it is replaced by the symbol; however, it does not satisfy the
1117 predicate `symbol?'. Macro transformers rarely distinguish
1118 symbols from aliases, referring to both as identifiers.
1120 * A "syntactic" environment maps identifiers to their meanings.
1121 More precisely, it determines whether an identifier is a syntactic
1122 keyword or a variable. If it is a keyword, the meaning is an
1123 interpretation for the form in which that keyword appears. If it
1124 is a variable, the meaning identifies which binding of that
1125 variable is referenced. In short, syntactic environments contain
1126 all of the contextual information necessary for interpreting the
1127 meaning of a particular form.
1129 * A "syntactic closure" consists of a form, a syntactic environment,
1130 and a list of identifiers. All identifiers in the form take their
1131 meaning from the syntactic environment, except those in the given
1132 list. The identifiers in the list are to have their meanings
1133 determined later. A syntactic closure may be used in any context
1134 in which its form could have been used. Since a syntactic closure
1135 is also a form, it may not be used in contexts where a form would
1136 be illegal. For example, a form may not appear as a clause in the
1137 cond special form. A syntactic closure appearing in a quoted
1138 structure is replaced by its form.
1141 Transformer Definition
1142 ......................
1144 This section describes the `transformer' special form and the
1145 procedures `make-syntactic-closure' and `capture-syntactic-environment'.
1147 - Syntax: transformer expression
1148 Syntax: It is an error if this syntax occurs except as a
1151 Semantics: The EXPRESSION is evaluated in the standard transformer
1152 environment to yield a macro transformer as described below. This
1153 macro transformer is bound to a macro keyword by the special form
1154 in which the `transformer' expression appears (for example,
1157 A "macro transformer" is a procedure that takes two arguments, a
1158 form and a syntactic environment, and returns a new form. The
1159 first argument, the "input form", is the form in which the macro
1160 keyword occurred. The second argument, the "usage environment",
1161 is the syntactic environment in which the input form occurred.
1162 The result of the transformer, the "output form", is automatically
1163 closed in the "transformer environment", which is the syntactic
1164 environment in which the `transformer' expression occurred.
1166 For example, here is a definition of a push macro using
1171 (set! list (cons item list)))))
1173 Here is an equivalent definition using `transformer':
1178 (make-syntactic-closure env '() (cadr exp)))
1180 (make-syntactic-closure env '() (caddr exp))))
1181 `(set! ,list (cons ,item ,list))))))
1183 In this example, the identifiers `set!' and `cons' are closed in
1184 the transformer environment, and thus will not be affected by the
1185 meanings of those identifiers in the usage environment `env'.
1187 Some macros may be non-hygienic by design. For example, the
1188 following defines a loop macro that implicitly binds `exit' to an
1189 escape procedure. The binding of `exit' is intended to capture
1190 free references to `exit' in the body of the loop, so `exit' must
1191 be left free when the body is closed:
1195 (let ((body (cdr exp)))
1196 `(call-with-current-continuation
1199 ,@(map (lambda (exp)
1200 (make-syntactic-closure env '(exit)
1205 To assign meanings to the identifiers in a form, use
1206 `make-syntactic-closure' to close the form in a syntactic
1209 - Function: make-syntactic-closure environment free-names form
1210 ENVIRONMENT must be a syntactic environment, FREE-NAMES must be a
1211 list of identifiers, and FORM must be a form.
1212 `make-syntactic-closure' constructs and returns a syntactic closure
1213 of FORM in ENVIRONMENT, which can be used anywhere that FORM could
1214 have been used. All the identifiers used in FORM, except those
1215 explicitly excepted by FREE-NAMES, obtain their meanings from
1218 Here is an example where FREE-NAMES is something other than the
1219 empty list. It is instructive to compare the use of FREE-NAMES in
1220 this example with its use in the `loop' example above: the examples
1221 are similar except for the source of the identifier being left
1226 (let ((id (cadr exp))
1230 ,(make-syntactic-closure env (list id) exp))
1231 ,(make-syntactic-closure env '() init))))))
1233 `let1' is a simplified version of `let' that only binds a single
1234 identifier, and whose body consists of a single expression. When
1235 the body expression is syntactically closed in its original
1236 syntactic environment, the identifier that is to be bound by
1237 `let1' must be left free, so that it can be properly captured by
1238 the `lambda' in the output form.
1240 To obtain a syntactic environment other than the usage
1241 environment, use `capture-syntactic-environment'.
1243 - Function: capture-syntactic-environment procedure
1244 `capture-syntactic-environment' returns a form that will, when
1245 transformed, call PROCEDURE on the current syntactic environment.
1246 PROCEDURE should compute and return a new form to be transformed,
1247 in that same syntactic environment, in place of the form.
1249 An example will make this clear. Suppose we wanted to define a
1250 simple `loop-until' keyword equivalent to
1251 (define-syntax loop-until
1253 ((loop-until id init test return step)
1256 (if test return (loop step)))))
1259 The following attempt at defining `loop-until' has a subtle bug:
1260 (define-syntax loop-until
1263 (let ((id (cadr exp))
1266 (return (cadddr (cdr exp)))
1267 (step (cadddr (cddr exp)))
1270 (make-syntactic-closure env free exp))))
1273 (if ,(close test (list id))
1274 ,(close return (list id))
1275 (loop ,(close step (list id)))))))
1276 (loop ,(close init '())))))))
1278 This definition appears to take all of the proper precautions to
1279 prevent unintended captures. It carefully closes the
1280 subexpressions in their original syntactic environment and it
1281 leaves the `id' identifier free in the `test', `return', and
1282 `step' expressions, so that it will be captured by the binding
1283 introduced by the `lambda' expression. Unfortunately it uses the
1284 identifiers `if' and `loop' within that `lambda' expression, so if
1285 the user of `loop-until' just happens to use, say, `if' for the
1286 identifier, it will be inadvertently captured.
1288 The syntactic environment that `if' and `loop' want to be exposed
1289 to is the one just outside the `lambda' expression: before the
1290 user's identifier is added to the syntactic environment, but after
1291 the identifier loop has been added.
1292 `capture-syntactic-environment' captures exactly that environment
1294 (define-syntax loop-until
1297 (let ((id (cadr exp))
1300 (return (cadddr (cdr exp)))
1301 (step (cadddr (cddr exp)))
1304 (make-syntactic-closure env free exp))))
1306 ,(capture-syntactic-environment
1309 (,(make-syntactic-closure env '() `if)
1310 ,(close test (list id))
1311 ,(close return (list id))
1312 (,(make-syntactic-closure env '()
1314 ,(close step (list id)))))))))
1315 (loop ,(close init '())))))))
1317 In this case, having captured the desired syntactic environment,
1318 it is convenient to construct syntactic closures of the
1319 identifiers `if' and the `loop' and use them in the body of the
1322 A common use of `capture-syntactic-environment' is to get the
1323 transformer environment of a macro transformer:
1326 (capture-syntactic-environment
1327 (lambda (transformer-env)
1333 This section describes the procedures that create and manipulate
1334 identifiers. Previous syntactic closure proposals did not have an
1335 identifier data type - they just used symbols. The identifier data
1336 type extends the syntactic closures facility to be compatible with the
1337 high-level `syntax-rules' facility.
1339 As discussed earlier, an identifier is either a symbol or an "alias".
1340 An alias is implemented as a syntactic closure whose "form" is an
1342 (make-syntactic-closure env '() 'a)
1345 Aliases are implemented as syntactic closures because they behave just
1346 like syntactic closures most of the time. The difference is that an
1347 alias may be bound to a new value (for example by `lambda' or
1348 `let-syntax'); other syntactic closures may not be used this way. If
1349 an alias is bound, then within the scope of that binding it is looked
1350 up in the syntactic environment just like any other identifier.
1352 Aliases are used in the implementation of the high-level facility
1353 `syntax-rules'. A macro transformer created by `syntax-rules' uses a
1354 template to generate its output form, substituting subforms of the
1355 input form into the template. In a syntactic closures implementation,
1356 all of the symbols in the template are replaced by aliases closed in
1357 the transformer environment, while the output form itself is closed in
1358 the usage environment. This guarantees that the macro transformation
1359 is hygienic, without requiring the transformer to know the syntactic
1360 roles of the substituted input subforms.
1362 - Function: identifier? object
1363 Returns `#t' if OBJECT is an identifier, otherwise returns `#f'.
1367 (identifier? (make-syntactic-closure env '() 'a))
1382 The predicate `eq?' is used to determine if two identifers are
1383 "the same". Thus `eq?' can be used to compare identifiers exactly
1384 as it would be used to compare symbols. Often, though, it is
1385 useful to know whether two identifiers "mean the same thing". For
1386 example, the `cond' macro uses the symbol `else' to identify the
1387 final clause in the conditional. A macro transformer for `cond'
1388 cannot just look for the symbol `else', because the `cond' form
1389 might be the output of another macro transformer that replaced the
1390 symbol `else' with an alias. Instead the transformer must look
1391 for an identifier that "means the same thing" in the usage
1392 environment as the symbol `else' means in the transformer
1395 - Function: identifier=? environment1 identifier1 environment2
1397 ENVIRONMENT1 and ENVIRONMENT2 must be syntactic environments, and
1398 IDENTIFIER1 and IDENTIFIER2 must be identifiers. `identifier=?'
1399 returns `#t' if the meaning of IDENTIFIER1 in ENVIRONMENT1 is the
1400 same as that of IDENTIFIER2 in ENVIRONMENT2, otherwise it returns
1407 (capture-syntactic-environment
1408 (lambda (transformer-env)
1409 (identifier=? transformer-env 'x env 'x)))))))
1415 (let-syntax ((bar foo))
1420 (capture-syntactic-environment
1421 (lambda (transformer-env)
1422 (identifier=? transformer-env 'foo
1423 env (cadr form))))))))
1431 The syntactic closures facility was invented by Alan Bawden and
1432 Jonathan Rees. The use of aliases to implement `syntax-rules' was
1433 invented by Alan Bawden (who prefers to call them "synthetic names").
1434 Much of this proposal is derived from an earlier proposal by Alan
1438 File: slib.info, Node: Syntax-Case Macros, Next: Fluid-Let, Prev: Syntactic Closures, Up: Scheme Syntax Extension Packages
1443 `(require 'syntax-case)'
1445 - Function: macro:expand expression
1446 - Function: syncase:expand expression
1447 Returns scheme code with the macros and derived expression types of
1448 EXPRESSION expanded to primitive expression types.
1450 - Function: macro:eval expression
1451 - Function: syncase:eval expression
1452 `macro:eval' returns the value of EXPRESSION in the current top
1453 level environment. EXPRESSION can contain macro definitions.
1454 Side effects of EXPRESSION will affect the top level environment.
1456 - Procedure: macro:load filename
1457 - Procedure: syncase:load filename
1458 FILENAME should be a string. If filename names an existing file,
1459 the `macro:load' procedure reads Scheme source code expressions and
1460 definitions from the file and evaluates them sequentially. These
1461 source code expressions and definitions may contain macro
1462 definitions. The `macro:load' procedure does not affect the
1463 values returned by `current-input-port' and `current-output-port'.
1465 This is version 2.1 of `syntax-case', the low-level macro facility
1466 proposed and implemented by Robert Hieb and R. Kent Dybvig.
1468 This version is further adapted by Harald Hanche-Olsen
1469 <hanche@imf.unit.no> to make it compatible with, and easily usable
1470 with, SLIB. Mainly, these adaptations consisted of:
1472 * Removing white space from `expand.pp' to save space in the
1473 distribution. This file is not meant for human readers anyway...
1475 * Removed a couple of Chez scheme dependencies.
1477 * Renamed global variables used to minimize the possibility of name
1480 * Adding an SLIB-specific initialization file.
1482 * Removing a couple extra files, most notably the documentation (but
1485 If you wish, you can see exactly what changes were done by reading the
1486 shell script in the file `syncase.sh'.
1488 The two PostScript files were omitted in order to not burden the SLIB
1489 distribution with them. If you do intend to use `syntax-case',
1490 however, you should get these files and print them out on a PostScript
1491 printer. They are available with the original `syntax-case'
1492 distribution by anonymous FTP in
1493 `cs.indiana.edu:/pub/scheme/syntax-case'.
1495 In order to use syntax-case from an interactive top level, execute:
1496 (require 'syntax-case)
1498 (repl:top-level macro:eval)
1499 See the section Repl (*note Repl::) for more information.
1501 To check operation of syntax-case get
1502 `cs.indiana.edu:/pub/scheme/syntax-case', and type
1503 (require 'syntax-case)
1504 (syncase:sanity-check)
1506 Beware that `syntax-case' takes a long time to load - about 20s on a
1507 SPARCstation SLC (with SCM) and about 90s on a Macintosh SE/30 (with
1513 All R4RS syntactic forms are defined, including `delay'. Along with
1514 `delay' are simple definitions for `make-promise' (into which `delay'
1515 expressions expand) and `force'.
1517 `syntax-rules' and `with-syntax' (described in `TR356') are defined.
1519 `syntax-case' is actually defined as a macro that expands into calls
1520 to the procedure `syntax-dispatch' and the core form `syntax-lambda';
1521 do not redefine these names.
1523 Several other top-level bindings not documented in TR356 are created:
1524 * the "hooks" in `hooks.ss'
1526 * the `build-' procedures in `output.ss'
1528 * `expand-syntax' (the expander)
1530 The syntax of define has been extended to allow `(define ID)', which
1531 assigns ID to some unspecified value.
1533 We have attempted to maintain R4RS compatibility where possible. The
1534 incompatibilities should be confined to `hooks.ss'. Please let us know
1535 if there is some incompatibility that is not flagged as such.
1537 Send bug reports, comments, suggestions, and questions to Kent Dybvig
1538 (dyb@iuvax.cs.indiana.edu).
1540 Note from maintainer
1541 --------------------
1543 Included with the `syntax-case' files was `structure.scm' which
1544 defines a macro `define-structure'. There is no documentation for this
1545 macro and it is not used by any code in SLIB.
1548 File: slib.info, Node: Fluid-Let, Next: Yasos, Prev: Syntax-Case Macros, Up: Scheme Syntax Extension Packages
1553 `(require 'fluid-let)'
1555 - Syntax: fluid-let `(BINDINGS ...)' FORMS...
1557 (fluid-let ((VARIABLE INIT) ...)
1558 EXPRESSION EXPRESSION ...)
1560 The INITs are evaluated in the current environment (in some
1561 unspecified order), the current values of the VARIABLEs are saved, the
1562 results are assigned to the VARIABLEs, the EXPRESSIONs are evaluated
1563 sequentially in the current environment, the VARIABLEs are restored to
1564 their original values, and the value of the last EXPRESSION is returned.
1566 The syntax of this special form is similar to that of `let', but
1567 `fluid-let' temporarily rebinds existing VARIABLEs. Unlike `let',
1568 `fluid-let' creates no new bindings; instead it _assigns_ the values of
1569 each INIT to the binding (determined by the rules of lexical scoping)
1570 of its corresponding VARIABLE.
1573 File: slib.info, Node: Yasos, Prev: Fluid-Let, Up: Scheme Syntax Extension Packages
1578 `(require 'oop)' or `(require 'yasos)'
1580 `Yet Another Scheme Object System' is a simple object system for
1581 Scheme based on the paper by Norman Adams and Jonathan Rees: `Object
1582 Oriented Programming in Scheme', Proceedings of the 1988 ACM Conference
1583 on LISP and Functional Programming, July 1988 [ACM #552880].
1585 Another reference is:
1587 Ken Dickey. Scheming with Objects `AI Expert' Volume 7, Number 10
1588 (October 1992), pp. 24-33.
1592 * Yasos terms:: Definitions and disclaimer.
1593 * Yasos interface:: The Yasos macros and procedures.
1594 * Setters:: Dylan-like setters in Yasos.
1595 * Yasos examples:: Usage of Yasos and setters.
1598 File: slib.info, Node: Yasos terms, Next: Yasos interface, Prev: Yasos, Up: Yasos
1604 Any Scheme data object.
1607 An instance of the OO system; an "object".
1613 The object system supports multiple inheritance. An instance can
1614 inherit from 0 or more ancestors. In the case of multiple
1615 inherited operations with the same identity, the operation used is
1616 that from the first ancestor which contains it (in the ancestor
1617 `let'). An operation may be applied to any Scheme data
1618 object--not just instances. As code which creates instances is
1619 just code, there are no "classes" and no meta-ANYTHING. Method
1620 dispatch is by a procedure call a la CLOS rather than by `send'
1621 syntax a la Smalltalk.
1624 There are a number of optimizations which can be made. This
1625 implementation is expository (although performance should be quite
1626 reasonable). See the L&FP paper for some suggestions.
1629 File: slib.info, Node: Yasos interface, Next: Setters, Prev: Yasos terms, Up: Yasos
1634 - Syntax: define-operation `('opname self arg ...`)' DEFAULT-BODY
1635 Defines a default behavior for data objects which don't handle the
1636 operation OPNAME. The default behavior (for an empty
1637 DEFAULT-BODY) is to generate an error.
1639 - Syntax: define-predicate opname?
1640 Defines a predicate OPNAME?, usually used for determining the
1641 "type" of an object, such that `(OPNAME? OBJECT)' returns `#t' if
1642 OBJECT has an operation OPNAME? and `#f' otherwise.
1644 - Syntax: object `((NAME SELF ARG ...) BODY)' ...
1645 Returns an object (an instance of the object system) with
1646 operations. Invoking `(NAME OBJECT ARG ...' executes the BODY of
1647 the OBJECT with SELF bound to OBJECT and with argument(s) ARG....
1649 - Syntax: object-with-ancestors `(('ancestor1 init1`)' ...`)'
1651 A `let'-like form of `object' for multiple inheritance. It
1652 returns an object inheriting the behaviour of ANCESTOR1 etc. An
1653 operation will be invoked in an ancestor if the object itself does
1654 not provide such a method. In the case of multiple inherited
1655 operations with the same identity, the operation used is the one
1656 found in the first ancestor in the ancestor list.
1658 - Syntax: operate-as component operation self arg ...
1659 Used in an operation definition (of SELF) to invoke the OPERATION
1660 in an ancestor COMPONENT but maintain the object's identity. Also
1661 known as "send-to-super".
1663 - Procedure: print obj port
1664 A default `print' operation is provided which is just `(format
1665 PORT OBJ)' (*note Format::) for non-instances and prints OBJ
1666 preceded by `#<INSTANCE>' for instances.
1668 - Function: size obj
1669 The default method returns the number of elements in OBJ if it is
1670 a vector, string or list, `2' for a pair, `1' for a character and
1671 by default id an error otherwise. Objects such as collections
1672 (*note Collections::) may override the default in an obvious way.
1675 File: slib.info, Node: Setters, Next: Yasos examples, Prev: Yasos interface, Up: Yasos
1680 "Setters" implement "generalized locations" for objects associated
1681 with some sort of mutable state. A "getter" operation retrieves a
1682 value from a generalized location and the corresponding setter
1683 operation stores a value into the location. Only the getter is named -
1684 the setter is specified by a procedure call as below. (Dylan uses
1685 special syntax.) Typically, but not necessarily, getters are access
1686 operations to extract values from Yasos objects (*note Yasos::).
1687 Several setters are predefined, corresponding to getters `car', `cdr',
1688 `string-ref' and `vector-ref' e.g., `(setter car)' is equivalent to
1691 This implementation of setters is similar to that in Dylan(TM)
1692 (`Dylan: An object-oriented dynamic language', Apple Computer Eastern
1693 Research and Technology). Common LISP provides similar facilities
1696 - Function: setter getter
1697 Returns the setter for the procedure GETTER. E.g., since
1698 `string-ref' is the getter corresponding to a setter which is
1699 actually `string-set!':
1701 ((setter string-ref) foo 0 #\F) ; set element 0 of foo
1704 - Syntax: set place new-value
1705 If PLACE is a variable name, `set' is equivalent to `set!'.
1706 Otherwise, PLACE must have the form of a procedure call, where the
1707 procedure name refers to a getter and the call indicates an
1708 accessible generalized location, i.e., the call would return a
1709 value. The return value of `set' is usually unspecified unless
1710 used with a setter whose definition guarantees to return a useful
1712 (set (string-ref foo 2) #\O) ; generalized location with getter
1714 (set foo "foo") ; like set!
1717 - Procedure: add-setter getter setter
1718 Add procedures GETTER and SETTER to the (inaccessible) list of
1719 valid setter/getter pairs. SETTER implements the store operation
1720 corresponding to the GETTER access operation for the relevant
1721 state. The return value is unspecified.
1723 - Procedure: remove-setter-for getter
1724 Removes the setter corresponding to the specified GETTER from the
1725 list of valid setters. The return value is unspecified.
1727 - Syntax: define-access-operation getter-name
1728 Shorthand for a Yasos `define-operation' defining an operation
1729 GETTER-NAME that objects may support to return the value of some
1730 mutable state. The default operation is to signal an error. The
1731 return value is unspecified.
1734 File: slib.info, Node: Yasos examples, Prev: Setters, Up: Yasos
1739 ;;; These definitions for PRINT and SIZE are
1740 ;;; already supplied by
1743 (define-operation (print obj port)
1745 (if (instance? obj) "#<instance>" "~s")
1748 (define-operation (size obj)
1750 ((vector? obj) (vector-length obj))
1751 ((list? obj) (length obj))
1753 ((string? obj) (string-length obj))
1756 (error "Operation not supported: size" obj))))
1758 (define-predicate cell?)
1759 (define-operation (fetch obj))
1760 (define-operation (store! obj newValue))
1762 (define (make-cell value)
1765 ((fetch self) value)
1766 ((store! self newValue)
1767 (set! value newValue)
1771 (format port "#<Cell: ~s>" (fetch self)))))
1773 (define-operation (discard obj value)
1774 (format #t "Discarding ~s~%" value))
1776 (define (make-filtered-cell value filter)
1777 (object-with-ancestors
1778 ((cell (make-cell value)))
1779 ((store! self newValue)
1780 (if (filter newValue)
1781 (store! cell newValue)
1782 (discard self newValue)))))
1784 (define-predicate array?)
1785 (define-operation (array-ref array index))
1786 (define-operation (array-set! array index value))
1788 (define (make-array num-slots)
1789 (let ((anArray (make-vector num-slots)))
1792 ((size self) num-slots)
1793 ((array-ref self index)
1794 (vector-ref anArray index))
1795 ((array-set! self index newValue)
1796 (vector-set! anArray index newValue))
1798 (format port "#<Array ~s>" (size self))))))
1800 (define-operation (position obj))
1801 (define-operation (discarded-value obj))
1803 (define (make-cell-with-history value filter size)
1804 (let ((pos 0) (most-recent-discard #f))
1805 (object-with-ancestors
1806 ((cell (make-filtered-call value filter))
1807 (sequence (make-array size)))
1809 ((position self) pos)
1810 ((store! self newValue)
1811 (operate-as cell store! self newValue)
1812 (array-set! self pos newValue)
1813 (set! pos (+ pos 1)))
1814 ((discard self value)
1815 (set! most-recent-discard value))
1816 ((discarded-value self) most-recent-discard)
1818 (format port "#<Cell-with-history ~s>"
1821 (define-access-operation fetch)
1822 (add-setter fetch store!)
1823 (define foo (make-cell 1))
1834 File: slib.info, Node: Textual Conversion Packages, Next: Mathematical Packages, Prev: Scheme Syntax Extension Packages, Up: Top
1836 Textual Conversion Packages
1837 ***************************
1841 * Precedence Parsing::
1842 * Format:: Common-Lisp Format
1843 * Standard Formatted I/O:: Posix printf and scanf
1844 * Programs and Arguments::
1846 * HTML Tables:: Databases meet HTML
1847 * HTTP and CGI:: Serve WWW sites
1848 * URI:: Uniform Resource Identifier |
1849 * Printing Scheme:: Nicely
1852 * Schmooz:: Documentation markup for Scheme programs
1855 File: slib.info, Node: Precedence Parsing, Next: Format, Prev: Textual Conversion Packages, Up: Textual Conversion Packages
1860 `(require 'precedence-parse)' or `(require 'parse)'
1862 This package implements:
1864 * a Pratt style precedence parser;
1866 * a "tokenizer" which congeals tokens according to assigned classes
1867 of constituent characters;
1869 * procedures giving direct control of parser rulesets;
1871 * procedures for higher level specification of rulesets.
1875 * Precedence Parsing Overview::
1876 * Ruleset Definition and Use::
1877 * Token definition::
1878 * Nud and Led Definition::
1879 * Grammar Rule Definition::
1882 File: slib.info, Node: Precedence Parsing Overview, Next: Ruleset Definition and Use, Prev: Precedence Parsing, Up: Precedence Parsing
1884 Precedence Parsing Overview
1885 ---------------------------
1887 This package offers improvements over previous parsers.
1889 * Common computer language constructs are concisely specified.
1891 * Grammars can be changed dynamically. Operators can be assigned
1892 different meanings within a lexical context.
1894 * Rulesets don't need compilation. Grammars can be changed
1897 * Operator precedence is specified by integers.
1899 * All possibilities of bad input are handled (1) and return as much
1900 structure as was parsed when the error occured; The symbol `?' is
1901 substituted for missing input.
1903 Here are the higher-level syntax types and an example of each.
1904 Precedence considerations are omitted for clarity. See *Note Grammar
1905 Rule Definition:: for full details.
1907 - Grammar: nofix bye exit
1909 calls the function `exit' with no arguments.
1911 - Grammar: prefix - negate
1913 Calls the function `negate' with the argument `42'.
1915 - Grammar: infix - difference
1917 Calls the function `difference' with arguments `x' and `y'.
1919 - Grammar: nary + sum
1921 Calls the function `sum' with arguments `x', `y', and `y'.
1923 - Grammar: postfix ! factorial
1925 Calls the function `factorial' with the argument `5'.
1927 - Grammar: prestfix set set!
1929 Calls the function `set!' with the arguments `foo' and `bar'.
1931 - Grammar: commentfix /* */
1932 /* almost any text here */
1933 Ignores the comment delimited by `/*' and `*/'.
1935 - Grammar: matchfix { list }
1937 Calls the function `list' with the arguments `0', `1', and `2'.
1939 - Grammar: inmatchfix ( funcall )
1941 Calls the function `funcall' with the arguments `f', `x', and `y'.
1945 delimits the extent of the restfix operator `set'.
1947 ---------- Footnotes ----------
1949 (1) How do I know this? I parsed 250kbyte of random input (an e-mail
1950 file) with a non-trivial grammar utilizing all constructs.
1953 File: slib.info, Node: Ruleset Definition and Use, Next: Token definition, Prev: Precedence Parsing Overview, Up: Precedence Parsing
1955 Ruleset Definition and Use
1956 --------------------------
1958 - Variable: *syn-defs*
1959 A grammar is built by one or more calls to `prec:define-grammar'.
1960 The rules are appended to *SYN-DEFS*. The value of *SYN-DEFS* is
1961 the grammar suitable for passing as an argument to `prec:parse'.
1963 - Constant: *syn-ignore-whitespace*
1964 Is a nearly empty grammar with whitespace characters set to group
1965 0, which means they will not be made into tokens. Most rulesets
1966 will want to start with `*syn-ignore-whitespace*'
1968 In order to start defining a grammar, either
1970 (set! *syn-defs* '())
1974 (set! *syn-defs* *syn-ignore-whitespace*)
1976 - Function: prec:define-grammar rule1 ...
1977 Appends RULE1 ... to *SYN-DEFS*. `prec:define-grammar' is used to
1978 define both the character classes and rules for tokens.
1980 Once your grammar is defined, save the value of `*syn-defs*' in a
1981 variable (for use when calling `prec:parse').
1983 (define my-ruleset *syn-defs*)
1985 - Function: prec:parse ruleset delim
1986 - Function: prec:parse ruleset delim port
1987 The RULESET argument must be a list of rules as constructed by
1988 `prec:define-grammar' and extracted from *SYN-DEFS*.
1990 The token DELIM may be a character, symbol, or string. A
1991 character DELIM argument will match only a character token; i.e. a
1992 character for which no token-group is assigned. A symbols or
1993 string will match only a token string; i.e. a token resulting from
1996 `prec:parse' reads a RULESET grammar expression delimited by DELIM
1997 from the given input PORT. `prec:parse' returns the next object
1998 parsable from the given input PORT, updating PORT to point to the
1999 first character past the end of the external representation of the
2002 If an end of file is encountered in the input before any
2003 characters are found that can begin an object, then an end of file
2004 object is returned. If a delimiter (such as DELIM) is found
2005 before any characters are found that can begin an object, then
2008 The PORT argument may be omitted, in which case it defaults to the
2009 value returned by `current-input-port'. It is an error to parse
2013 File: slib.info, Node: Token definition, Next: Nud and Led Definition, Prev: Ruleset Definition and Use, Up: Precedence Parsing
2018 - Function: tok:char-group group chars chars-proc
2019 The argument CHARS may be a single character, a list of
2020 characters, or a string. Each character in CHARS is treated as
2021 though `tok:char-group' was called with that character alone.
2023 The argument CHARS-PROC must be a procedure of one argument, a
2024 list of characters. After `tokenize' has finished accumulating
2025 the characters for a token, it calls CHARS-PROC with the list of
2026 characters. The value returned is the token which `tokenize'
2029 The argument GROUP may be an exact integer or a procedure of one
2030 character argument. The following discussion concerns the
2031 treatment which the tokenizing routine, `tokenize', will accord to
2032 characters on the basis of their groups.
2034 When GROUP is a non-zero integer, characters whose group number is
2035 equal to or exactly one less than GROUP will continue to
2036 accumulate. Any other character causes the accumulation to stop
2037 (until a new token is to be read).
2039 The GROUP of zero is special. These characters are ignored when
2040 parsed pending a token, and stop the accumulation of token
2041 characters when the accumulation has already begun. Whitespace
2042 characters are usually put in group 0.
2044 If GROUP is a procedure, then, when triggerd by the occurence of
2045 an initial (no accumulation) CHARS character, this procedure will
2046 be repeatedly called with each successive character from the input
2047 stream until the GROUP procedure returns a non-false value.
2049 The following convenient constants are provided for use with
2052 - Constant: tok:decimal-digits
2053 Is the string `"0123456789"'.
2055 - Constant: tok:upper-case
2056 Is the string consisting of all upper-case letters
2057 ("ABCDEFGHIJKLMNOPQRSTUVWXYZ").
2059 - Constant: tok:lower-case
2060 Is the string consisting of all lower-case letters
2061 ("abcdefghijklmnopqrstuvwxyz").
2063 - Constant: tok:whitespaces
2064 Is the string consisting of all characters between 0 and 255 for
2065 which `char-whitespace?' returns true.
2068 File: slib.info, Node: Nud and Led Definition, Next: Grammar Rule Definition, Prev: Token definition, Up: Precedence Parsing
2070 Nud and Led Definition
2071 ----------------------
2073 This section describes advanced features. You can skip this section
2076 The "Null Denotation" (or "nud") of a token is the procedure and
2077 arguments applying for that token when "Left", an unclaimed parsed
2078 expression is not extant.
2080 The "Left Denotation" (or "led") of a token is the procedure,
2081 arguments, and lbp applying for that token when there is a "Left", an
2082 unclaimed parsed expression.
2086 Pratt, V. R. Top Down Operator Precendence. `SIGACT/SIGPLAN
2087 Symposium on Principles of Programming Languages', Boston, 1973,
2090 the "left binding power" (or "lbp") was an independent property of
2091 tokens. I think this was done in order to allow tokens with NUDs but
2092 not LEDs to also be used as delimiters, which was a problem for
2093 statically defined syntaxes. It turns out that _dynamically binding_
2094 NUDs and LEDs allows them independence.
2096 For the rule-defining procedures that follow, the variable TK may be a
2097 character, string, or symbol, or a list composed of characters,
2098 strings, and symbols. Each element of TK is treated as though the
2099 procedure were called for each element.
2101 Character TK arguments will match only character tokens; i.e.
2102 characters for which no token-group is assigned. Symbols and strings
2103 will both match token strings; i.e. tokens resulting from token groups.
2105 - Function: prec:make-nud tk sop arg1 ...
2106 Returns a rule specifying that SOP be called when TK is parsed.
2107 If SOP is a procedure, it is called with TK and ARG1 ... as its
2108 arguments; the resulting value is incorporated into the expression
2109 being built. Otherwise, `(list SOP ARG1 ...)' is incorporated.
2111 If no NUD has been defined for a token; then if that token is a string,
2112 it is converted to a symbol and returned; if not a string, the token is
2115 - Function: prec:make-led tk sop arg1 ...
2116 Returns a rule specifying that SOP be called when TK is parsed and
2117 LEFT has an unclaimed parsed expression. If SOP is a procedure,
2118 it is called with LEFT, TK, and ARG1 ... as its arguments; the
2119 resulting value is incorporated into the expression being built.
2120 Otherwise, LEFT is incorporated.
2122 If no LED has been defined for a token, and LEFT is set, the parser
2126 File: slib.info, Node: Grammar Rule Definition, Prev: Nud and Led Definition, Up: Precedence Parsing
2128 Grammar Rule Definition
2129 -----------------------
2131 Here are procedures for defining rules for the syntax types introduced
2132 in *Note Precedence Parsing Overview::.
2134 For the rule-defining procedures that follow, the variable TK may be a
2135 character, string, or symbol, or a list composed of characters,
2136 strings, and symbols. Each element of TK is treated as though the
2137 procedure were called for each element.
2139 For procedures prec:delim, ..., prec:prestfix, if the SOP argument is
2140 `#f', then the token which triggered this rule is converted to a symbol
2141 and returned. A false SOP argument to the procedures prec:commentfix,
2142 prec:matchfix, or prec:inmatchfix has a different meaning.
2144 Character TK arguments will match only character tokens; i.e.
2145 characters for which no token-group is assigned. Symbols and strings
2146 will both match token strings; i.e. tokens resulting from token groups.
2148 - Function: prec:delim tk
2149 Returns a rule specifying that TK should not be returned from
2150 parsing; i.e. TK's function is purely syntactic. The end-of-file
2151 is always treated as a delimiter.
2153 - Function: prec:nofix tk sop
2154 Returns a rule specifying the following actions take place when TK
2156 * If SOP is a procedure, it is called with no arguments; the
2157 resulting value is incorporated into the expression being
2158 built. Otherwise, the list of SOP is incorporated.
2160 - Function: prec:prefix tk sop bp rule1 ...
2161 Returns a rule specifying the following actions take place when TK
2163 * The rules RULE1 ... augment and, in case of conflict, override
2164 rules currently in effect.
2166 * `prec:parse1' is called with binding-power BP.
2168 * If SOP is a procedure, it is called with the expression
2169 returned from `prec:parse1'; the resulting value is
2170 incorporated into the expression being built. Otherwise, the
2171 list of SOP and the expression returned from `prec:parse1' is
2174 * The ruleset in effect before TK was parsed is restored; RULE1
2177 - Function: prec:infix tk sop lbp bp rule1 ...
2178 Returns a rule declaring the left-binding-precedence of the token
2179 TK is LBP and specifying the following actions take place when TK
2181 * The rules RULE1 ... augment and, in case of conflict, override
2182 rules currently in effect.
2184 * One expression is parsed with binding-power LBP. If instead a
2185 delimiter is encountered, a warning is issued.
2187 * If SOP is a procedure, it is applied to the list of LEFT and
2188 the parsed expression; the resulting value is incorporated
2189 into the expression being built. Otherwise, the list of SOP,
2190 the LEFT expression, and the parsed expression is
2193 * The ruleset in effect before TK was parsed is restored; RULE1
2196 - Function: prec:nary tk sop bp
2197 Returns a rule declaring the left-binding-precedence of the token
2198 TK is BP and specifying the following actions take place when TK
2200 * Expressions are parsed with binding-power BP as far as they
2201 are interleaved with the token TK.
2203 * If SOP is a procedure, it is applied to the list of LEFT and
2204 the parsed expressions; the resulting value is incorporated
2205 into the expression being built. Otherwise, the list of SOP,
2206 the LEFT expression, and the parsed expressions is
2209 - Function: prec:postfix tk sop lbp
2210 Returns a rule declaring the left-binding-precedence of the token
2211 TK is LBP and specifying the following actions take place when TK
2213 * If SOP is a procedure, it is called with the LEFT expression;
2214 the resulting value is incorporated into the expression being
2215 built. Otherwise, the list of SOP and the LEFT expression is
2218 - Function: prec:prestfix tk sop bp rule1 ...
2219 Returns a rule specifying the following actions take place when TK
2221 * The rules RULE1 ... augment and, in case of conflict, override
2222 rules currently in effect.
2224 * Expressions are parsed with binding-power BP until a
2225 delimiter is reached.
2227 * If SOP is a procedure, it is applied to the list of parsed
2228 expressions; the resulting value is incorporated into the
2229 expression being built. Otherwise, the list of SOP and the
2230 parsed expressions is incorporated.
2232 * The ruleset in effect before TK was parsed is restored; RULE1
2235 - Function: prec:commentfix tk stp match rule1 ...
2236 Returns rules specifying the following actions take place when TK
2238 * The rules RULE1 ... augment and, in case of conflict, override
2239 rules currently in effect.
2241 * Characters are read until and end-of-file or a sequence of
2242 characters is read which matches the _string_ MATCH.
2244 * If STP is a procedure, it is called with the string of all
2245 that was read between the TK and MATCH (exclusive).
2247 * The ruleset in effect before TK was parsed is restored; RULE1
2250 Parsing of commentfix syntax differs from the others in several
2251 ways. It reads directly from input without tokenizing; It calls
2252 STP but does not return its value; nay any value. I added the STP
2253 argument so that comment text could be echoed.
2255 - Function: prec:matchfix tk sop sep match rule1 ...
2256 Returns a rule specifying the following actions take place when TK
2258 * The rules RULE1 ... augment and, in case of conflict, override
2259 rules currently in effect.
2261 * A rule declaring the token MATCH a delimiter takes effect.
2263 * Expressions are parsed with binding-power `0' until the token
2264 MATCH is reached. If the token SEP does not appear between
2265 each pair of expressions parsed, a warning is issued.
2267 * If SOP is a procedure, it is applied to the list of parsed
2268 expressions; the resulting value is incorporated into the
2269 expression being built. Otherwise, the list of SOP and the
2270 parsed expressions is incorporated.
2272 * The ruleset in effect before TK was parsed is restored; RULE1
2275 - Function: prec:inmatchfix tk sop sep match lbp rule1 ...
2276 Returns a rule declaring the left-binding-precedence of the token
2277 TK is LBP and specifying the following actions take place when TK
2279 * The rules RULE1 ... augment and, in case of conflict, override
2280 rules currently in effect.
2282 * A rule declaring the token MATCH a delimiter takes effect.
2284 * Expressions are parsed with binding-power `0' until the token
2285 MATCH is reached. If the token SEP does not appear between
2286 each pair of expressions parsed, a warning is issued.
2288 * If SOP is a procedure, it is applied to the list of LEFT and
2289 the parsed expressions; the resulting value is incorporated
2290 into the expression being built. Otherwise, the list of SOP,
2291 the LEFT expression, and the parsed expressions is
2294 * The ruleset in effect before TK was parsed is restored; RULE1
2298 File: slib.info, Node: Format, Next: Standard Formatted I/O, Prev: Precedence Parsing, Up: Textual Conversion Packages
2300 Format (version 3.0)
2301 ====================
2307 * Format Interface::
2308 * Format Specification::
2311 File: slib.info, Node: Format Interface, Next: Format Specification, Prev: Format, Up: Format
2316 - Function: format destination format-string . arguments
2317 An almost complete implementation of Common LISP format description
2318 according to the CL reference book `Common LISP' from Guy L.
2319 Steele, Digital Press. Backward compatible to most of the
2320 available Scheme format implementations.
2322 Returns `#t', `#f' or a string; has side effect of printing
2323 according to FORMAT-STRING. If DESTINATION is `#t', the output is
2324 to the current output port and `#t' is returned. If DESTINATION
2325 is `#f', a formatted string is returned as the result of the call.
2326 NEW: If DESTINATION is a string, DESTINATION is regarded as the
2327 format string; FORMAT-STRING is then the first argument and the
2328 output is returned as a string. If DESTINATION is a number, the
2329 output is to the current error port if available by the
2330 implementation. Otherwise DESTINATION must be an output port and
2333 FORMAT-STRING must be a string. In case of a formatting error
2334 format returns `#f' and prints a message on the current output or
2335 error port. Characters are output as if the string were output by
2336 the `display' function with the exception of those prefixed by a
2337 tilde (~). For a detailed description of the FORMAT-STRING syntax
2338 please consult a Common LISP format reference manual. For a test
2339 suite to verify this format implementation load `formatst.scm'.
2340 Please send bug reports to `lutzeb@cs.tu-berlin.de'.
2342 Note: `format' is not reentrant, i.e. only one `format'-call may
2343 be executed at a time.
2347 File: slib.info, Node: Format Specification, Prev: Format Interface, Up: Format
2349 Format Specification (Format version 3.0)
2350 -----------------------------------------
2352 Please consult a Common LISP format reference manual for a detailed
2353 description of the format string syntax. For a demonstration of the
2354 implemented directives see `formatst.scm'.
2356 This implementation supports directive parameters and modifiers (`:'
2357 and `@' characters). Multiple parameters must be separated by a comma
2358 (`,'). Parameters can be numerical parameters (positive or negative),
2359 character parameters (prefixed by a quote character (`''), variable
2360 parameters (`v'), number of rest arguments parameter (`#'), empty and
2361 default parameters. Directive characters are case independent. The
2362 general form of a directive is:
2364 DIRECTIVE ::= ~{DIRECTIVE-PARAMETER,}[:][@]DIRECTIVE-CHARACTER
2366 DIRECTIVE-PARAMETER ::= [ [-|+]{0-9}+ | 'CHARACTER | v | # ]
2368 Implemented CL Format Control Directives
2369 ........................................
2371 Documentation syntax: Uppercase characters represent the corresponding
2372 control directive characters. Lowercase characters represent control
2373 directive parameter descriptions.
2376 Any (print as `display' does).
2380 `~MINCOL,COLINC,MINPAD,PADCHARA'
2384 S-expression (print as `write' does).
2388 `~MINCOL,COLINC,MINPAD,PADCHARS'
2394 print number sign always.
2397 print comma separated.
2399 `~MINCOL,PADCHAR,COMMACHARD'
2405 print number sign always.
2408 print comma separated.
2410 `~MINCOL,PADCHAR,COMMACHARX'
2416 print number sign always.
2419 print comma separated.
2421 `~MINCOL,PADCHAR,COMMACHARO'
2427 print number sign always.
2430 print comma separated.
2432 `~MINCOL,PADCHAR,COMMACHARB'
2437 `~N,MINCOL,PADCHAR,COMMACHARR'
2441 print a number as a Roman numeral.
2444 print a number as an "old fashioned" Roman numeral.
2447 print a number as an ordinal English number.
2450 print a number as a cardinal English number.
2455 prints `y' and `ies'.
2458 as `~P but jumps 1 argument backward.'
2461 as `~@P but jumps 1 argument backward.'
2466 prints a character as the reader can understand it (i.e. `#\'
2470 prints a character as emacs does (eg. `^C' for ASCII 03).
2473 Fixed-format floating-point (prints a flonum like MMM.NNN).
2474 `~WIDTH,DIGITS,SCALE,OVERFLOWCHAR,PADCHARF'
2477 If the number is positive a plus sign is printed.
2480 Exponential floating-point (prints a flonum like MMM.NNN`E'EE).
2481 `~WIDTH,DIGITS,EXPONENTDIGITS,SCALE,OVERFLOWCHAR,PADCHAR,EXPONENTCHARE'
2484 If the number is positive a plus sign is printed.
2487 General floating-point (prints a flonum either fixed or
2489 `~WIDTH,DIGITS,EXPONENTDIGITS,SCALE,OVERFLOWCHAR,PADCHAR,EXPONENTCHARG'
2492 If the number is positive a plus sign is printed.
2495 Dollars floating-point (prints a flonum in fixed with signs
2497 `~DIGITS,SCALE,WIDTH,PADCHAR$'
2500 If the number is positive a plus sign is printed.
2503 A sign is always printed and appears before the padding.
2506 The sign appears before the padding.
2514 print newline if not at the beginning of the output line.
2516 prints `~&' and then N-1 newlines.
2521 print N page separators.
2531 newline is ignored, white space left.
2534 newline is left, white space ignored.
2539 relative tabulation.
2545 Indirection (expects indirect arguments as a list).
2547 extracts indirect arguments from format arguments.
2550 Case conversion (converts by `string-downcase').
2552 converts by `string-capitalize'.
2555 converts by `string-capitalize-first'.
2558 converts by `string-upcase'.
2561 Argument Jumping (jumps 1 argument forward).
2563 jumps N arguments forward.
2566 jumps 1 argument backward.
2569 jumps N arguments backward.
2572 jumps to the 0th argument.
2575 jumps to the Nth argument (beginning from 0)
2577 `~[STR0~;STR1~;...~;STRN~]'
2578 Conditional Expression (numerical clause conditional).
2580 take argument from N.
2583 true test conditional.
2586 if-else-then conditional.
2592 default clause follows.
2595 Iteration (args come from the next argument (a list)).
2597 at most N iterations.
2600 args from next arg (a list of lists).
2603 args from the rest of arguments.
2606 args from the rest args (lists).
2617 aborts if N <= M <= K
2619 Not Implemented CL Format Control Directives
2620 ............................................
2623 print `#f' as an empty list (see below).
2626 print `#f' as an empty list (see below).
2632 (sorry I don't understand its semantics completely)
2634 Extended, Replaced and Additional Control Directives
2635 ....................................................
2637 `~MINCOL,PADCHAR,COMMACHAR,COMMAWIDTHD'
2639 `~MINCOL,PADCHAR,COMMACHAR,COMMAWIDTHX'
2641 `~MINCOL,PADCHAR,COMMACHAR,COMMAWIDTHO'
2643 `~MINCOL,PADCHAR,COMMACHAR,COMMAWIDTHB'
2645 `~N,MINCOL,PADCHAR,COMMACHAR,COMMAWIDTHR'
2646 COMMAWIDTH is the number of characters between two comma
2650 print a R4RS complex number as `~F~@Fi' with passed parameters for
2654 Pretty print formatting of an argument for scheme code lists.
2660 Flushes the output if format DESTINATION is a port.
2663 Print a `#\space' character
2665 print N `#\space' characters.
2668 Print a `#\tab' character
2670 print N `#\tab' characters.
2673 Takes N as an integer representation for a character. No arguments
2674 are consumed. N is converted to a character by `integer->char'. N
2675 must be a positive decimal number.
2678 Print out readproof. Prints out internal objects represented as
2679 `#<...>' as strings `"#<...>"' so that the format output can always
2680 be processed by `read'.
2683 Print out readproof. Prints out internal objects represented as
2684 `#<...>' as strings `"#<...>"' so that the format output can always
2685 be processed by `read'.
2688 Prints information and a copyright notice on the format
2691 prints format version.
2694 may also print number strings, i.e. passing a number as a string
2695 and format it accordingly.
2697 Configuration Variables
2698 .......................
2700 Format has some configuration variables at the beginning of
2701 `format.scm' to suit the systems and users needs. There should be no
2702 modification necessary for the configuration that comes with SLIB. If
2703 modification is desired the variable should be set after the format
2704 code is loaded. Format detects automatically if the running scheme
2705 system implements floating point numbers and complex numbers.
2707 FORMAT:SYMBOL-CASE-CONV
2708 Symbols are converted by `symbol->string' so the case type of the
2709 printed symbols is implementation dependent.
2710 `format:symbol-case-conv' is a one arg closure which is either
2711 `#f' (no conversion), `string-upcase', `string-downcase' or
2712 `string-capitalize'. (default `#f')
2714 FORMAT:IOBJ-CASE-CONV
2715 As FORMAT:SYMBOL-CASE-CONV but applies for the representation of
2716 implementation internal objects. (default `#f')
2719 The character prefixing the exponent value in `~E' printing.
2722 Compatibility With Other Format Implementations
2723 ...............................................
2729 Downward compatible except for padding support and `~A', `~S',
2730 `~P', `~X' uppercase printing. SLIB format 1.4 uses C-style
2731 `printf' padding support which is completely replaced by the CL
2732 `format' padding style.
2735 Downward compatible except for `~', which is not documented
2736 (ignores all characters inside the format string up to a newline
2737 character). (7.1 implements `~a', `~s', ~NEWLINE, `~~', `~%',
2738 numerical and variable parameters and `:/@' modifiers in the CL
2742 Downward compatible except for `~A' and `~S' which print in
2743 uppercase. (Elk implements `~a', `~s', `~~', and `~%' (no
2744 directive parameters or modifiers)).
2747 Downward compatible except for an optional destination parameter:
2748 S2C accepts a format call without a destination which returns a
2749 formatted string. This is equivalent to a #f destination in S2C.
2750 (S2C implements `~a', `~s', `~c', `~%', and `~~' (no directive
2751 parameters or modifiers)).
2753 This implementation of format is solely useful in the SLIB context
2754 because it requires other components provided by SLIB.
2757 File: slib.info, Node: Standard Formatted I/O, Next: Programs and Arguments, Prev: Format, Up: Textual Conversion Packages
2759 Standard Formatted I/O
2760 ======================
2764 * Standard Formatted Output:: 'printf
2765 * Standard Formatted Input:: 'scanf
2772 `require's `printf' and `scanf' and additionally defines the symbols:
2775 Defined to be `(current-input-port)'.
2778 Defined to be `(current-output-port)'.
2781 Defined to be `(current-error-port)'.
2784 File: slib.info, Node: Standard Formatted Output, Next: Standard Formatted Input, Prev: Standard Formatted I/O, Up: Standard Formatted I/O
2786 Standard Formatted Output
2787 -------------------------
2791 - Procedure: printf format arg1 ...
2792 - Procedure: fprintf port format arg1 ...
2793 - Procedure: sprintf str format arg1 ...
2794 - Procedure: sprintf #f format arg1 ...
2795 - Procedure: sprintf k format arg1 ...
2796 Each function converts, formats, and outputs its ARG1 ...
2797 arguments according to the control string FORMAT argument and
2798 returns the number of characters output.
2800 `printf' sends its output to the port `(current-output-port)'.
2801 `fprintf' sends its output to the port PORT. `sprintf'
2802 `string-set!'s locations of the non-constant string argument STR
2803 to the output characters.
2805 Two extensions of `sprintf' return new strings. If the first
2806 argument is `#f', then the returned string's length is as many
2807 characters as specified by the FORMAT and data; if the first
2808 argument is a non-negative integer K, then the length of the
2809 returned string is also bounded by K.
2811 The string FORMAT contains plain characters which are copied to
2812 the output stream, and conversion specifications, each of which
2813 results in fetching zero or more of the arguments ARG1 .... The
2814 results are undefined if there are an insufficient number of
2815 arguments for the format. If FORMAT is exhausted while some of the
2816 ARG1 ... arguments remain unused, the excess ARG1 ... arguments
2819 The conversion specifications in a format string have the form:
2821 % [ FLAGS ] [ WIDTH ] [ . PRECISION ] [ TYPE ] CONVERSION
2823 An output conversion specifications consist of an initial `%'
2824 character followed in sequence by:
2826 * Zero or more "flag characters" that modify the normal
2827 behavior of the conversion specification.
2830 Left-justify the result in the field. Normally the
2831 result is right-justified.
2834 For the signed `%d' and `%i' conversions and all inexact
2835 conversions, prefix a plus sign if the value is positive.
2838 For the signed `%d' and `%i' conversions, if the result
2839 doesn't start with a plus or minus sign, prefix it with
2840 a space character instead. Since the `+' flag ensures
2841 that the result includes a sign, this flag is ignored if
2845 For inexact conversions, `#' specifies that the result
2846 should always include a decimal point, even if no digits
2847 follow it. For the `%g' and `%G' conversions, this also
2848 forces trailing zeros after the decimal point to be
2849 printed where they would otherwise be elided.
2851 For the `%o' conversion, force the leading digit to be
2852 `0', as if by increasing the precision. For `%x' or
2853 `%X', prefix a leading `0x' or `0X' (respectively) to
2854 the result. This doesn't do anything useful for the
2855 `%d', `%i', or `%u' conversions. Using this flag
2856 produces output which can be parsed by the `scanf'
2857 functions with the `%i' conversion (*note Standard
2861 Pad the field with zeros instead of spaces. The zeros
2862 are placed after any indication of sign or base. This
2863 flag is ignored if the `-' flag is also specified, or if
2864 a precision is specified for an exact converson.
2866 * An optional decimal integer specifying the "minimum field
2867 width". If the normal conversion produces fewer characters
2868 than this, the field is padded (with spaces or zeros per the
2869 `0' flag) to the specified width. This is a _minimum_ width;
2870 if the normal conversion produces more characters than this,
2871 the field is _not_ truncated.
2873 Alternatively, if the field width is `*', the next argument
2874 in the argument list (before the actual value to be printed)
2875 is used as the field width. The width value must be an
2876 integer. If the value is negative it is as though the `-'
2877 flag is set (see above) and the absolute value is used as the
2880 * An optional "precision" to specify the number of digits to be
2881 written for numeric conversions and the maximum field width
2882 for string conversions. The precision is specified by a
2883 period (`.') followed optionally by a decimal integer (which
2884 defaults to zero if omitted).
2886 Alternatively, if the precision is `.*', the next argument in
2887 the argument list (before the actual value to be printed) is
2888 used as the precision. The value must be an integer, and is
2889 ignored if negative. If you specify `*' for both the field
2890 width and precision, the field width argument precedes the
2891 precision argument. The `.*' precision is an enhancement. C
2892 library versions may not accept this syntax.
2894 For the `%f', `%e', and `%E' conversions, the precision
2895 specifies how many digits follow the decimal-point character.
2896 The default precision is `6'. If the precision is
2897 explicitly `0', the decimal point character is suppressed.
2899 For the `%g' and `%G' conversions, the precision specifies how
2900 many significant digits to print. Significant digits are the
2901 first digit before the decimal point, and all the digits
2902 after it. If the precision is `0' or not specified for `%g'
2903 or `%G', it is treated like a value of `1'. If the value
2904 being printed cannot be expressed accurately in the specified
2905 number of digits, the value is rounded to the nearest number
2908 For exact conversions, if a precision is supplied it
2909 specifies the minimum number of digits to appear; leading
2910 zeros are produced if necessary. If a precision is not
2911 supplied, the number is printed with as many digits as
2912 necessary. Converting an exact `0' with an explicit
2913 precision of zero produces no characters.
2915 * An optional one of `l', `h' or `L', which is ignored for
2916 numeric conversions. It is an error to specify these
2917 modifiers for non-numeric conversions.
2919 * A character that specifies the conversion to be applied.
2925 Print an integer as a signed decimal number. `%d' and `%i'
2926 are synonymous for output, but are different when used with
2927 `scanf' for input (*note Standard Formatted Input::).
2930 Print an integer as an unsigned octal number.
2933 Print an integer as an unsigned decimal number.
2936 Print an integer as an unsigned hexadecimal number. `%x'
2937 prints using the digits `0123456789abcdef'. `%X' prints
2938 using the digits `0123456789ABCDEF'.
2944 Print a floating-point number in fixed-point notation.
2947 Print a floating-point number in exponential notation. `%e'
2948 prints `e' between mantissa and exponont. `%E' prints `E'
2949 between mantissa and exponont.
2952 Print a floating-point number in either fixed or exponential
2953 notation, whichever is more appropriate for its magnitude.
2954 Unless an `#' flag has been supplied, trailing zeros after a
2955 decimal point will be stripped off. `%g' prints `e' between
2956 mantissa and exponont. `%G' prints `E' between mantissa and
2960 Print a number like `%g', except that an SI prefix is output
2961 after the number, which is scaled accordingly. `%K' outputs
2962 a space between number and prefix, `%k' does not.
2968 Print a single character. The `-' flag is the only one which
2969 can be specified. It is an error to specify a precision.
2972 Print a string. The `-' flag is the only one which can be
2973 specified. A precision specifies the maximum number of
2974 characters to output; otherwise all characters in the string
2978 Print a scheme expression. The `-' flag left-justifies the
2979 output. The `#' flag specifies that strings and characters
2980 should be quoted as by `write' (which can be read using
2981 `read'); otherwise, output is as `display' prints. A
2982 precision specifies the maximum number of characters to
2983 output; otherwise as many characters as needed are output.
2985 _Note:_ `%a' and `%A' are SLIB extensions.
2988 Print a literal `%' character. No argument is consumed. It
2989 is an error to specifiy flags, field width, precision, or
2990 type modifiers with `%%'.
2993 File: slib.info, Node: Standard Formatted Input, Prev: Standard Formatted Output, Up: Standard Formatted I/O
2995 Standard Formatted Input
2996 ------------------------
3000 - Function: scanf-read-list format
3001 - Function: scanf-read-list format port
3002 - Function: scanf-read-list format string
3004 - Macro: scanf format arg1 ...
3005 - Macro: fscanf port format arg1 ...
3006 - Macro: sscanf str format arg1 ...
3007 Each function reads characters, interpreting them according to the
3008 control string FORMAT argument.
3010 `scanf-read-list' returns a list of the items specified as far as
3011 the input matches FORMAT. `scanf', `fscanf', and `sscanf' return
3012 the number of items successfully matched and stored. `scanf',
3013 `fscanf', and `sscanf' also set the location corresponding to ARG1
3014 ... using the methods:
3025 vector-ref expression
3028 substring expression
3029 `substring-move-left!'
3031 The argument to a `substring' expression in ARG1 ... must be a
3032 non-constant string. Characters will be stored starting at the
3033 position specified by the second argument to `substring'. The
3034 number of characters stored will be limited by either the position
3035 specified by the third argument to `substring' or the length of the
3036 matched string, whichever is less.
3038 The control string, FORMAT, contains conversion specifications and
3039 other characters used to direct interpretation of input sequences.
3040 The control string contains:
3042 * White-space characters (blanks, tabs, newlines, or formfeeds)
3043 that cause input to be read (and discarded) up to the next
3044 non-white-space character.
3046 * An ordinary character (not `%') that must match the next
3047 character of the input stream.
3049 * Conversion specifications, consisting of the character `%', an
3050 optional assignment suppressing character `*', an optional
3051 numerical maximum-field width, an optional `l', `h' or `L'
3052 which is ignored, and a conversion code.
3055 Unless the specification contains the `n' conversion character
3056 (described below), a conversion specification directs the
3057 conversion of the next input field. The result of a conversion
3058 specification is returned in the position of the corresponding
3059 argument points, unless `*' indicates assignment suppression.
3060 Assignment suppression provides a way to describe an input field
3061 to be skipped. An input field is defined as a string of
3062 characters; it extends to the next inappropriate character or
3063 until the field width, if specified, is exhausted.
3065 _Note:_ This specification of format strings differs from the
3066 `ANSI C' and `POSIX' specifications. In SLIB, white space
3067 before an input field is not skipped unless white space
3068 appears before the conversion specification in the format
3069 string. In order to write format strings which work
3070 identically with `ANSI C' and SLIB, prepend whitespace to all
3071 conversion specifications except `[' and `c'.
3073 The conversion code indicates the interpretation of the input
3074 field; For a suppressed field, no value is returned. The
3075 following conversion codes are legal:
3078 A single % is expected in the input at this point; no value
3082 A decimal integer is expected.
3085 An unsigned decimal integer is expected.
3088 An octal integer is expected.
3091 A hexadecimal integer is expected.
3094 An integer is expected. Returns the value of the next input
3095 item, interpreted according to C conventions; a leading `0'
3096 implies octal, a leading `0x' implies hexadecimal; otherwise,
3100 Returns the total number of bytes (including white space)
3101 read by `scanf'. No input is consumed by `%n'.
3103 `f', `F', `e', `E', `g', `G'
3104 A floating-point number is expected. The input format for
3105 floating-point numbers is an optionally signed string of
3106 digits, possibly containing a radix character `.', followed
3107 by an optional exponent field consisting of an `E' or an `e',
3108 followed by an optional `+', `-', or space, followed by an
3112 WIDTH characters are expected. The normal
3113 skip-over-white-space is suppressed in this case; to read the
3114 next non-space character, use `%1s'. If a field width is
3115 given, a string is returned; up to the indicated number of
3119 A character string is expected The input field is terminated
3120 by a white-space character. `scanf' cannot read a null
3124 Indicates string data and the normal
3125 skip-over-leading-white-space is suppressed. The left
3126 bracket is followed by a set of characters, called the
3127 scanset, and a right bracket; the input field is the maximal
3128 sequence of input characters consisting entirely of
3129 characters in the scanset. `^', when it appears as the first
3130 character in the scanset, serves as a complement operator and
3131 redefines the scanset as the set of all characters not
3132 contained in the remainder of the scanset string.
3133 Construction of the scanset follows certain conventions. A
3134 range of characters may be represented by the construct
3135 first-last, enabling `[0123456789]' to be expressed `[0-9]'.
3136 Using this convention, first must be lexically less than or
3137 equal to last; otherwise, the dash stands for itself. The
3138 dash also stands for itself when it is the first or the last
3139 character in the scanset. To include the right square
3140 bracket as an element of the scanset, it must appear as the
3141 first character (possibly preceded by a `^') of the scanset,
3142 in which case it will not be interpreted syntactically as the
3143 closing bracket. At least one character must match for this
3144 conversion to succeed.
3146 The `scanf' functions terminate their conversions at end-of-file,
3147 at the end of the control string, or when an input character
3148 conflicts with the control string. In the latter case, the
3149 offending character is left unread in the input stream.
3152 File: slib.info, Node: Programs and Arguments, Next: HTML, Prev: Standard Formatted I/O, Up: Textual Conversion Packages
3154 Program and Arguments
3155 =====================
3159 * Getopt:: Command Line option parsing
3160 * Command Line:: A command line reader for Scheme shells
3161 * Parameter lists:: 'parameters
3162 * Getopt Parameter lists:: 'getopt-parameters
3163 * Filenames:: 'glob or 'filename
3167 File: slib.info, Node: Getopt, Next: Command Line, Prev: Programs and Arguments, Up: Programs and Arguments
3174 This routine implements Posix command line argument parsing. Notice
3175 that returning values through global variables means that `getopt' is
3178 - Variable: *optind*
3179 Is the index of the current element of the command line. It is
3180 initially one. In order to parse a new command line or reparse an
3181 old one, *OPTING* must be reset.
3183 - Variable: *optarg*
3184 Is set by getopt to the (string) option-argument of the current
3187 - Procedure: getopt argc argv optstring
3188 Returns the next option letter in ARGV (starting from `(vector-ref
3189 argv *optind*)') that matches a letter in OPTSTRING. ARGV is a
3190 vector or list of strings, the 0th of which getopt usually
3191 ignores. ARGC is the argument count, usually the length of ARGV.
3192 OPTSTRING is a string of recognized option characters; if a
3193 character is followed by a colon, the option takes an argument
3194 which may be immediately following it in the string or in the next
3197 *OPTIND* is the index of the next element of the ARGV vector to be
3198 processed. It is initialized to 1 by `getopt.scm', and `getopt'
3199 updates it when it finishes with each element of ARGV.
3201 `getopt' returns the next option character from ARGV that matches
3202 a character in OPTSTRING, if there is one that matches. If the
3203 option takes an argument, `getopt' sets the variable *OPTARG* to
3204 the option-argument as follows:
3206 * If the option was the last character in the string pointed to
3207 by an element of ARGV, then *OPTARG* contains the next
3208 element of ARGV, and *OPTIND* is incremented by 2. If the
3209 resulting value of *OPTIND* is greater than or equal to ARGC,
3210 this indicates a missing option argument, and `getopt'
3211 returns an error indication.
3213 * Otherwise, *OPTARG* is set to the string following the option
3214 character in that element of ARGV, and *OPTIND* is
3217 If, when `getopt' is called, the string `(vector-ref argv
3218 *optind*)' either does not begin with the character `#\-' or is
3219 just `"-"', `getopt' returns `#f' without changing *OPTIND*. If
3220 `(vector-ref argv *optind*)' is the string `"--"', `getopt'
3221 returns `#f' after incrementing *OPTIND*.
3223 If `getopt' encounters an option character that is not contained in
3224 OPTSTRING, it returns the question-mark `#\?' character. If it
3225 detects a missing option argument, it returns the colon character
3226 `#\:' if the first character of OPTSTRING was a colon, or a
3227 question-mark character otherwise. In either case, `getopt' sets
3228 the variable GETOPT:OPT to the option character that caused the
3231 The special option `"--"' can be used to delimit the end of the
3232 options; `#f' is returned, and `"--"' is skipped.
3236 `getopt' returns the next option character specified on the command
3237 line. A colon `#\:' is returned if `getopt' detects a missing
3238 argument and the first character of OPTSTRING was a colon `#\:'.
3240 A question-mark `#\?' is returned if `getopt' encounters an option
3241 character not in OPTSTRING or detects a missing argument and the
3242 first character of OPTSTRING was not a colon `#\:'.
3244 Otherwise, `getopt' returns `#f' when all command line options
3248 #! /usr/local/bin/scm
3249 ;;;This code is SCM specific.
3250 (define argv (program-arguments))
3253 (define opts ":a:b:cd")
3254 (let loop ((opt (getopt (length argv) argv opts)))
3256 ((#\a) (print "option a: " *optarg*))
3257 ((#\b) (print "option b: " *optarg*))
3258 ((#\c) (print "option c"))
3259 ((#\d) (print "option d"))
3260 ((#\?) (print "error" getopt:opt))
3261 ((#\:) (print "missing arg" getopt:opt))
3262 ((#f) (if (< *optind* (length argv))
3263 (print "argv[" *optind* "]="
3264 (list-ref argv *optind*)))
3265 (set! *optind* (+ *optind* 1))))
3266 (if (< *optind* (length argv))
3267 (loop (getopt (length argv) argv opts))))
3274 - Function: getopt- argc argv optstring
3275 The procedure `getopt--' is an extended version of `getopt' which
3276 parses "long option names" of the form `--hold-the-onions' and
3277 `--verbosity-level=extreme'. `Getopt--' behaves as `getopt'
3278 except for non-empty options beginning with `--'.
3280 Options beginning with `--' are returned as strings rather than
3281 characters. If a value is assigned (using `=') to a long option,
3282 `*optarg*' is set to the value. The `=' and value are not
3283 returned as part of the option string.
3285 No information is passed to `getopt--' concerning which long
3286 options should be accepted or whether such options can take
3287 arguments. If a long option did not have an argument, `*optarg'
3288 will be set to `#f'. The caller is responsible for detecting and
3291 (define opts ":-:b:")
3293 (define argv '("foo" "-b9" "--f1" "--2=" "--g3=35234.342" "--"))
3295 (define *optarg* #f)
3297 (do ((i 5 (+ -1 i)))
3299 (define opt (getopt-- argc argv opts))
3300 (print *optind* opt *optarg*)))
3309 File: slib.info, Node: Command Line, Next: Parameter lists, Prev: Getopt, Up: Programs and Arguments
3314 `(require 'read-command)'
3316 - Function: read-command port
3317 - Function: read-command
3318 `read-command' converts a "command line" into a list of strings
3319 suitable for parsing by `getopt'. The syntax of command lines
3320 supported resembles that of popular "shell"s. `read-command'
3321 updates PORT to point to the first character past the command
3324 If an end of file is encountered in the input before any
3325 characters are found that can begin an object or comment, then an
3326 end of file object is returned.
3328 The PORT argument may be omitted, in which case it defaults to the
3329 value returned by `current-input-port'.
3331 The fields into which the command line is split are delimited by
3332 whitespace as defined by `char-whitespace?'. The end of a command
3333 is delimited by end-of-file or unescaped semicolon (<;>) or
3334 <newline>. Any character can be literally included in a field by
3335 escaping it with a backslach (<\>).
3337 The initial character and types of fields recognized are:
3339 The next character has is taken literally and not interpreted
3340 as a field delimiter. If <\> is the last character before a
3341 <newline>, that <newline> is just ignored. Processing
3342 continues from the characters after the <newline> as though
3343 the backslash and <newline> were not there.
3346 The characters up to the next unescaped <"> are taken
3347 literally, according to [R4RS] rules for literal strings
3348 (*note Strings: (r4rs)Strings.).
3351 One scheme expression is `read' starting with this character.
3352 The `read' expression is evaluated, converted to a string
3353 (using `display'), and replaces the expression in the returned
3357 Semicolon delimits a command. Using semicolons more than one
3358 command can appear on a line. Escaped semicolons and
3359 semicolons inside strings do not delimit commands.
3361 The comment field differs from the previous fields in that it must
3362 be the first character of a command or appear after whitespace in
3363 order to be recognized. <#> can be part of fields if these
3364 conditions are not met. For instance, `ab#c' is just the field
3368 Introduces a comment. The comment continues to the end of
3369 the line on which the semicolon appears. Comments are
3370 treated as whitespace by `read-dommand-line' and backslashes
3371 before <newline>s in comments are also ignored.
3373 - Function: read-options-file filename
3374 `read-options-file' converts an "options file" into a list of
3375 strings suitable for parsing by `getopt'. The syntax of options
3376 files is the same as the syntax for command lines, except that
3377 <newline>s do not terminate reading (only <;> or end of file).
3379 If an end of file is encountered before any characters are found
3380 that can begin an object or comment, then an end of file object is
3384 File: slib.info, Node: Parameter lists, Next: Getopt Parameter lists, Prev: Command Line, Up: Programs and Arguments
3389 `(require 'parameters)'
3391 Arguments to procedures in scheme are distinguished from each other by
3392 their position in the procedure call. This can be confusing when a
3393 procedure takes many arguments, many of which are not often used.
3395 A "parameter-list" is a way of passing named information to a
3396 procedure. Procedures are also defined to set unused parameters to
3397 default values, check parameters, and combine parameter lists.
3399 A PARAMETER has the form `(parameter-name value1 ...)'. This format
3400 allows for more than one value per parameter-name.
3402 A PARAMETER-LIST is a list of PARAMETERs, each with a different
3405 - Function: make-parameter-list parameter-names
3406 Returns an empty parameter-list with slots for PARAMETER-NAMES.
3408 - Function: parameter-list-ref parameter-list parameter-name
3409 PARAMETER-NAME must name a valid slot of PARAMETER-LIST.
3410 `parameter-list-ref' returns the value of parameter PARAMETER-NAME
3413 - Function: remove-parameter parameter-name parameter-list
3414 Removes the parameter PARAMETER-NAME from PARAMETER-LIST.
3415 `remove-parameter' does not alter the argument PARAMETER-LIST.
3417 If there are more than one PARAMETER-NAME parameters, an error is
3420 - Procedure: adjoin-parameters! parameter-list parameter1 ...
3421 Returns PARAMETER-LIST with PARAMETER1 ... merged in.
3423 - Procedure: parameter-list-expand expanders parameter-list
3424 EXPANDERS is a list of procedures whose order matches the order of
3425 the PARAMETER-NAMEs in the call to `make-parameter-list' which
3426 created PARAMETER-LIST. For each non-false element of EXPANDERS
3427 that procedure is mapped over the corresponding parameter value
3428 and the returned parameter lists are merged into PARAMETER-LIST.
3430 This process is repeated until PARAMETER-LIST stops growing. The
3431 value returned from `parameter-list-expand' is unspecified.
3433 - Function: fill-empty-parameters defaulters parameter-list
3434 DEFAULTERS is a list of procedures whose order matches the order
3435 of the PARAMETER-NAMEs in the call to `make-parameter-list' which
3436 created PARAMETER-LIST. `fill-empty-parameters' returns a new
3437 parameter-list with each empty parameter replaced with the list
3438 returned by calling the corresponding DEFAULTER with
3439 PARAMETER-LIST as its argument.
3441 - Function: check-parameters checks parameter-list
3442 CHECKS is a list of procedures whose order matches the order of
3443 the PARAMETER-NAMEs in the call to `make-parameter-list' which
3444 created PARAMETER-LIST.
3446 `check-parameters' returns PARAMETER-LIST if each CHECK of the
3447 corresponding PARAMETER-LIST returns non-false. If some CHECK
3448 returns `#f' a warning is signaled. |
3450 In the following procedures ARITIES is a list of symbols. The elements
3451 of `arities' can be:
3454 Requires a single parameter.
3457 A single parameter or no parameter is acceptable.
3460 A single boolean parameter or zero parameters is acceptable.
3463 Any number of parameters are acceptable.
3466 One or more of parameters are acceptable.
3468 - Function: parameter-list->arglist positions arities parameter-list |
3469 Returns PARAMETER-LIST converted to an argument list. Parameters
3470 of ARITY type `single' and `boolean' are converted to the single
3471 value associated with them. The other ARITY types are converted
3472 to lists of the value(s). |
3474 POSITIONS is a list of positive integers whose order matches the
3475 order of the PARAMETER-NAMEs in the call to `make-parameter-list'
3476 which created PARAMETER-LIST. The integers specify in which
3477 argument position the corresponding parameter should appear.
3480 File: slib.info, Node: Getopt Parameter lists, Next: Filenames, Prev: Parameter lists, Up: Programs and Arguments
3482 Getopt Parameter lists
3483 ----------------------
3485 `(require 'getopt-parameters)'
3487 - Function: getopt->parameter-list argc argv optnames arities types
3489 Returns ARGV converted to a parameter-list. OPTNAMES are the
3490 parameter-names. ARITIES and TYPES are lists of symbols |
3491 corresponding to OPTNAMES. |
3493 ALIASES is a list of lists of strings or integers paired with |
3494 elements of OPTNAMES. Each one-character string will be treated |
3495 as a single `-' option by `getopt'. Longer strings will be |
3496 treated as long-named options (*note getopt-: Getopt.). |
3498 If the ALIASES association list has only strings as its `car's, |
3499 then all the option-arguments after an option (and before the next |
3500 option) are adjoined to that option. |
3502 If the ALIASES association list has integers, then each (string) |
3503 option will take at most one option-argument. Unoptioned |
3504 arguments are collected in a list. A `-1' alias will take the |
3505 last argument in this list; `+1' will take the first argument in |
3506 the list. The aliases -2 then +2; -3 then +3; ... are tried so |
3507 long as a positive or negative consecutive alias is found and |
3508 arguments remain in the list. Finally a `0' alias, if found, |
3509 absorbs any remaining arguments. |
3511 In all cases, if unclaimed arguments remain after processing, a |
3512 warning is signaled and #f is returned. |
3514 - Function: getopt->arglist argc argv optnames positions arities types
3515 defaulters checks aliases desc ... |
3516 Like `getopt->parameter-list', but converts ARGV to an
3517 argument-list as specified by OPTNAMES, POSITIONS, ARITIES, TYPES,
3518 DEFAULTERS, CHECKS, and ALIASES. If the options supplied violate |
3519 the ARITIES or CHECKS constraints, then a warning is signaled and |
3522 These `getopt' functions can be used with SLIB relational databases.
3523 For an example, *Note make-command-server: Database Utilities.
3525 If errors are encountered while processing options, directions for using
3526 the options (and argument strings DESC ...) are printed to |
3527 `current-error-port'. |
3531 (getopt->parameter-list
3534 '(flag number symbols symbols string flag2 flag3 num2 num3)
3535 '(boolean optional nary1 nary single boolean boolean nary nary)
3536 '(boolean integer symbol symbol string boolean boolean integer integer)
3552 Usage: cmd [OPTION ARGUMENT ...] ...
3555 -o, --optional=<number>
3556 -n, --nary=<symbols> ...
3557 -N, --nary1=<symbols> ...
3558 -s, --single=<string>
3564 ERROR: getopt->parameter-list "unrecognized option" "-?"
3567 File: slib.info, Node: Filenames, Next: Batch, Prev: Getopt Parameter lists, Up: Programs and Arguments
3572 `(require 'filename)' or `(require 'glob)'
3574 - Function: filename:match?? pattern
3575 - Function: filename:match-ci?? pattern
3576 Returns a predicate which returns a non-false value if its string
3577 argument matches (the string) PATTERN, false otherwise. Filename
3578 matching is like "glob" expansion described the bash manpage,
3579 except that names beginning with `.' are matched and `/'
3580 characters are not treated specially.
3582 These functions interpret the following characters specially in
3585 Matches any string, including the null string.
3588 Matches any single character.
3591 Matches any one of the enclosed characters. A pair of
3592 characters separated by a minus sign (-) denotes a range; any
3593 character lexically between those two characters, inclusive,
3594 is matched. If the first character following the `[' is a
3595 `!' or a `^' then any character not enclosed is matched. A
3596 `-' or `]' may be matched by including it as the first or
3597 last character in the set.
3600 - Function: filename:substitute?? pattern template
3601 - Function: filename:substitute-ci?? pattern template
3602 Returns a function transforming a single string argument according
3603 to glob patterns PATTERN and TEMPLATE. PATTERN and TEMPLATE must
3604 have the same number of wildcard specifications, which need not be
3605 identical. PATTERN and TEMPLATE may have a different number of
3606 literal sections. If an argument to the function matches PATTERN
3607 in the sense of `filename:match??' then it returns a copy of
3608 TEMPLATE in which each wildcard specification is replaced by the
3609 part of the argument matched by the corresponding wildcard
3610 specification in PATTERN. A `*' wildcard matches the longest
3611 leftmost string possible. If the argument does not match PATTERN
3612 then false is returned.
3614 TEMPLATE may be a function accepting the same number of string
3615 arguments as there are wildcard specifications in PATTERN. In the
3616 case of a match the result of applying TEMPLATE to a list of the
3617 substrings matched by wildcard specifications will be returned,
3618 otherwise TEMPLATE will not be called and `#f' will be returned.
3620 ((filename:substitute?? "scm_[0-9]*.html" "scm5c4_??.htm")
3623 ((filename:substitute?? "??" "beg?mid?end") "AZ")
3625 ((filename:substitute?? "*na*" "?NA?") "banana")
3627 ((filename:substitute?? "?*?" (lambda (s1 s2 s3) (string-append s3 s1))) "ABZ")
3630 - Function: replace-suffix str old new
3631 STR can be a string or a list of strings. Returns a new string
3632 (or strings) similar to `str' but with the suffix string OLD
3633 removed and the suffix string NEW appended. If the end of STR
3634 does not match OLD, an error is signaled.
3636 (replace-suffix "/usr/local/lib/slib/batch.scm" ".scm" ".c")
3637 => "/usr/local/lib/slib/batch.c"
3640 File: slib.info, Node: Batch, Prev: Filenames, Up: Programs and Arguments
3647 The batch procedures provide a way to write and execute portable scripts
3648 for a variety of operating systems. Each `batch:' procedure takes as
3649 its first argument a parameter-list (*note Parameter lists::). This
3650 parameter-list argument PARMS contains named associations. Batch
3651 currently uses 2 of these:
3654 The port on which to write lines of the batch file.
3657 The syntax of batch file to generate. Currently supported are:
3670 `batch.scm' uses 2 enhanced relational tables (*note Database
3671 Utilities::) to store information linking the names of
3672 `operating-system's to `batch-dialect'es.
3674 - Function: batch:initialize! database
3675 Defines `operating-system' and `batch-dialect' tables and adds the
3676 domain `operating-system' to the enhanced relational database
3679 - Variable: batch:platform
3680 Is batch's best guess as to which operating-system it is running
3681 under. `batch:platform' is set to `(software-type)' (*note
3682 Configuration::) unless `(software-type)' is `unix', in which case
3683 finer distinctions are made.
3685 - Function: batch:call-with-output-script parms file proc
3686 PROC should be a procedure of one argument. If FILE is an
3687 output-port, `batch:call-with-output-script' writes an appropriate
3688 header to FILE and then calls PROC with FILE as the only argument.
3689 If FILE is a string, `batch:call-with-output-script' opens a
3690 output-file of name FILE, writes an appropriate header to FILE,
3691 and then calls PROC with the newly opened port as the only
3692 argument. Otherwise, `batch:call-with-output-script' acts as if
3693 it was called with the result of `(current-output-port)' as its
3696 The rest of the `batch:' procedures write (or execute if
3697 `batch-dialect' is `system') commands to the batch port which has been
3698 added to PARMS or `(copy-tree PARMS)' by the code:
3700 (adjoin-parameters! PARMS (list 'batch-port PORT))
3702 - Function: batch:command parms string1 string2 ...
3703 Calls `batch:try-command' (below) with arguments, but signals an
3704 error if `batch:try-command' returns `#f'.
3706 These functions return a non-false value if the command was successfully
3707 translated into the batch dialect and `#f' if not. In the case of the
3708 `system' dialect, the value is non-false if the operation suceeded.
3710 - Function: batch:try-command parms string1 string2 ...
3711 Writes a command to the `batch-port' in PARMS which executes the
3712 program named STRING1 with arguments STRING2 ....
3714 - Function: batch:try-chopped-command parms arg1 arg2 ... list
3715 breaks the last argument LIST into chunks small enough so that the
3720 fits withing the platform's maximum command-line length.
3722 `batch:try-chopped-command' calls `batch:try-command' with the
3723 command and returns non-false only if the commands all fit and
3724 `batch:try-command' of each command line returned non-false.
3726 - Function: batch:run-script parms string1 string2 ...
3727 Writes a command to the `batch-port' in PARMS which executes the
3728 batch script named STRING1 with arguments STRING2 ....
3730 _Note:_ `batch:run-script' and `batch:try-command' are not the
3731 same for some operating systems (VMS).
3733 - Function: batch:comment parms line1 ...
3734 Writes comment lines LINE1 ... to the `batch-port' in PARMS.
3736 - Function: batch:lines->file parms file line1 ...
3737 Writes commands to the `batch-port' in PARMS which create a file
3738 named FILE with contents LINE1 ....
3740 - Function: batch:delete-file parms file
3741 Writes a command to the `batch-port' in PARMS which deletes the
3744 - Function: batch:rename-file parms old-name new-name
3745 Writes a command to the `batch-port' in PARMS which renames the
3746 file OLD-NAME to NEW-NAME.
3748 In addition, batch provides some small utilities very useful for writing
3751 - Function: truncate-up-to path char
3752 - Function: truncate-up-to path string
3753 - Function: truncate-up-to path charlist
3754 PATH can be a string or a list of strings. Returns PATH sans any
3755 prefixes ending with a character of the second argument. This can
3756 be used to derive a filename moved locally from elsewhere.
3758 (truncate-up-to "/usr/local/lib/slib/batch.scm" "/")
3761 - Function: string-join joiner string1 ...
3762 Returns a new string consisting of all the strings STRING1 ... in
3763 order appended together with the string JOINER between each
3766 - Function: must-be-first list1 list2
3767 Returns a new list consisting of the elements of LIST2 ordered so
3768 that if some elements of LIST1 are `equal?' to elements of LIST2,
3769 then those elements will appear first and in the order of LIST1.
3771 - Function: must-be-last list1 list2
3772 Returns a new list consisting of the elements of LIST1 ordered so
3773 that if some elements of LIST2 are `equal?' to elements of LIST1,
3774 then those elements will appear last and in the order of LIST2.
3776 - Function: os->batch-dialect osname
3777 Returns its best guess for the `batch-dialect' to be used for the
3778 operating-system named OSNAME. `os->batch-dialect' uses the
3779 tables added to DATABASE by `batch:initialize!'.
3781 Here is an example of the use of most of batch's procedures:
3783 (require 'database-utilities)
3784 (require 'parameters)
3788 (define batch (create-database #f 'alist-table))
3789 (batch:initialize! batch)
3791 (define my-parameters
3792 (list (list 'batch-dialect (os->batch-dialect batch:platform))
3793 (list 'platform batch:platform)
3794 (list 'batch-port (current-output-port)))) ;gets filled in later
3796 (batch:call-with-output-script
3799 (lambda (batch-port)
3800 (adjoin-parameters! my-parameters (list 'batch-port batch-port))
3802 (batch:comment my-parameters
3803 "================ Write file with C program.")
3804 (batch:rename-file my-parameters "hello.c" "hello.c~")
3805 (batch:lines->file my-parameters "hello.c"
3806 "#include <stdio.h>"
3807 "int main(int argc, char **argv)"
3809 " printf(\"hello world\\n\");"
3812 (batch:command my-parameters "cc" "-c" "hello.c")
3813 (batch:command my-parameters "cc" "-o" "hello"
3814 (replace-suffix "hello.c" ".c" ".o"))
3815 (batch:command my-parameters "hello")
3816 (batch:delete-file my-parameters "hello")
3817 (batch:delete-file my-parameters "hello.c")
3818 (batch:delete-file my-parameters "hello.o")
3819 (batch:delete-file my-parameters "my-batch")
3822 Produces the file `my-batch':
3825 # "my-batch" script created by SLIB/batch Sun Oct 31 18:24:10 1999
3826 # ================ Write file with C program.
3827 mv -f hello.c hello.c~
3829 echo '#include <stdio.h>'>>hello.c
3830 echo 'int main(int argc, char **argv)'>>hello.c
3832 echo ' printf("hello world\n");'>>hello.c
3833 echo ' return 0;'>>hello.c
3843 When run, `my-batch' prints:
3846 mv: hello.c: No such file or directory
3850 File: slib.info, Node: HTML, Next: HTML Tables, Prev: Programs and Arguments, Up: Textual Conversion Packages
3855 `(require 'html-form)'
3857 - Function: html:atval txt
3858 Returns a string with character substitutions appropriate to send
3859 TXT as an "attribute-value".
3861 - Function: html:plain txt
3862 Returns a string with character substitutions appropriate to send
3863 TXT as an "plain-text".
3865 - Function: html:meta name content |
3866 Returns a tag of meta-information suitable for passing as the |
3867 third argument to `html:head'. The tag produced is `<META |
3868 NAME="NAME" CONTENT="CONTENT">'. The string or symbol NAME can be |
3869 `author', `copyright', `keywords', `description', `date', |
3872 - Function: html:http-equiv name content |
3873 Returns a tag of HTTP information suitable for passing as the |
3874 third argument to `html:head'. The tag produced is `<META |
3875 HTTP-EQUIV="NAME" CONTENT="CONTENT">'. The string or symbol NAME |
3876 can be `Expires', `PICS-Label', `Content-Type', `Refresh', .... |
3878 - Function: html:meta-refresh delay uri |
3879 - Function: html:meta-refresh delay |
3880 Returns a tag suitable for passing as the third argument to |
3881 `html:head'. If URI argument is supplied, then DELAY seconds after |
3882 displaying the page with this tag, Netscape or IE browsers will |
3883 fetch and display URI. Otherwise, DELAY seconds after displaying |
3884 the page with this tag, Netscape or IE browsers will fetch and |
3885 redisplay this page. |
3887 - Function: html:head title backlink tags ...
3888 - Function: html:head title backlink
3889 - Function: html:head title
3890 Returns header string for an HTML page named TITLE. If BACKLINK |
3891 is a string, it is used verbatim between the `H1' tags; otherwise |
3892 TITLE is used. If string arguments TAGS ... are supplied, then |
3893 they are included verbatim within the <HEAD> section. |
3895 - Function: html:body body ...
3896 Returns HTML string to end a page.
3898 - Function: html:pre line1 line ...
3899 Returns the strings LINE1, LINES as "PRE"formmated plain text
3900 (rendered in fixed-width font). Newlines are inserted between
3901 LINE1, LINES. HTML tags (`<tag>') within LINES will be visible
3904 - Function: html:comment line1 line ...
3905 Returns the strings LINE1 as HTML comments.
3910 - Function: html:form method action body ... |
3911 The symbol METHOD is either `get', `head', `post', `put', or
3912 `delete'. The strings BODY form the body of the form. |
3913 `html:form' returns the HTML "form".
3915 - Function: html:hidden name value |
3916 Returns HTML string which will cause NAME=VALUE in form. |
3918 - Function: html:checkbox pname default |
3919 Returns HTML string for check box. |
3921 - Function: html:text pname default size ... |
3922 Returns HTML string for one-line text box. |
3924 - Function: html:text-area pname default-list |
3925 Returns HTML string for multi-line text box. |
3927 - Function: html:select pname arity default-list foreign-values |
3928 Returns HTML string for pull-down menu selector. |
3930 - Function: html:buttons pname arity default-list foreign-values |
3931 Returns HTML string for any-of selector. |
3933 - Function: form:submit submit-label command |
3934 - Function: form:submit submit-label |
3935 The string or symbol SUBMIT-LABEL appears on the button which |
3936 submits the form. If the optional second argument COMMAND is |
3937 given, then `*command*=COMMAND' and `*button*=SUBMIT-LABEL' are |
3938 set in the query. Otherwise, `*command*=SUBMIT-LABEL' is set in |
3941 - Function: form:image submit-label image-src |
3942 The IMAGE-SRC appears on the button which submits the form. |
3944 - Function: form:reset |
3945 Returns a string which generates a "reset" button. |
3947 - Function: form:element pname arity default-list foreign-values |
3948 Returns a string which generates an INPUT element for the field |
3949 named PNAME. The element appears in the created form with its |
3950 representation determined by its ARITY and domain. For domains |
3951 which are foreign-keys: |
3965 If the foreign-key table has a field named `visible-name', then |
3966 the contents of that field are the names visible to the user for |
3967 those choices. Otherwise, the foreign-key itself is visible. |
3969 For other types of domains: |
3986 - Function: form:delimited pname doc aliat arity default-list |
3988 Returns a HTML string for a form element embedded in a line of a |
3989 delimited list. Apply map `form:delimited' to the list returned by |
3990 `command->p-specs'. |
3992 - Function: command->p-specs rdb command-table command |
3993 The symbol COMMAND-TABLE names a command table in the RDB
3994 relational database. The symbol COMMAND names a key in |
3997 `command->p-specs' returns a list of lists of PNAME, DOC, ALIAT, |
3998 ARITY, DEFAULT-LIST, and FOREIGN-VALUES. The returned list has |
3999 one element for each parameter of command COMMAND. |
4001 This example demonstrates how to create a HTML-form for the `build'
4004 (require (in-vicinity (implementation-vicinity) "build.scm"))
4005 (call-with-output-file "buildscm.html"
4009 (html:head 'commands)
4011 (sprintf #f "<H2>%s:</H2><BLOCKQUOTE>%s</BLOCKQUOTE>\\n" |
4012 (html:plain 'build) |
4013 (html:plain ((comtab 'get 'documentation) 'build))) |
4016 (or "http://localhost:8081/buildscm" "/cgi-bin/build.cgi") |
4017 (apply html:delimited-list |
4018 (apply map form:delimited |
4019 (command->p-specs build '*commands* 'build))) |
4020 (form:submit 'build) |
4025 File: slib.info, Node: HTML Tables, Next: HTTP and CGI, Prev: HTML, Up: Textual Conversion Packages
4030 `(require 'db->html)'
4032 - Function: html:table options row ... |
4034 - Function: html:caption caption align |
4035 - Function: html:caption caption |
4036 ALIGN can be `top' or `bottom'. |
4038 - Function: html:heading columns
4039 Outputs a heading row for the currently-started table.
4041 - Function: html:href-heading columns uris |
4042 Outputs a heading row with column-names COLUMNS linked to URIs |
4045 - Function: html:linked-row-converter k foreigns |
4046 The positive integer K is the primary-key-limit (number of
4047 primary-keys) of the table. FOREIGNS is a list of the filenames of
4048 foreign-key field pages and #f for non foreign-key fields.
4050 `html:linked-row-converter' returns a procedure taking a row for |
4051 its single argument. This returned procedure returns the html |
4052 string for that table row. |
4054 - Function: table-name->filename table-name
4055 Returns the symbol TABLE-NAME converted to a filename.
4057 - Function: table->linked-html caption db table-name match-key1 ... |
4058 Returns HTML string for DB table TABLE-NAME. Every foreign-key |
4059 value is linked to the page (of the table) defining that key. |
4061 The optional MATCH-KEY1 ... arguments restrict actions to a subset
4062 of the table. *Note match-key: Table Operations.
4064 - Function: table->linked-page db table-name index-filename arg ... |
4065 Returns a complete HTML page. The string INDEX-FILENAME names the
4066 page which refers to this one.
4068 The optional ARGS ... arguments restrict actions to a subset of
4069 the table. *Note match-key: Table Operations.
4071 - Function: catalog->html db caption arg ...
4072 Returns HTML string for the catalog table of DB.
4074 HTML editing tables |
4075 ------------------- |
4077 A client can modify one row of an editable table at a time. For any |
4078 change submitted, these routines check if that row has been modified |
4079 during the time the user has been editing the form. If so, an error |
4082 The behavior of edited rows is: |
4084 * If no fields are changed, then no change is made to the table. |
4086 * If the primary keys equal null-keys (parameter defaults), and no |
4087 other user has modified that row, then that row is deleted. |
4089 * If only primary keys are changed, there are non-key fields, and no |
4090 row with the new keys is in the table, then the old row is deleted |
4091 and one with the new keys is inserted. |
4093 * If only non-key fields are changed, and that row has not been |
4094 modified by another user, then the row is changed to reflect the |
4097 * If both keys and non-key fields are changed, and no row with the |
4098 new keys is in the table, then a row is created with the new keys |
4101 * If fields are changed, all fields are primary keys, and no row with |
4102 the new keys is in the table, then a row is created with the new |
4105 After any change to the table, a `sync-database' of the database is |
4108 - Function: command:modify-table table-name null-keys update delete |
4110 - Function: command:modify-table table-name null-keys update delete |
4111 - Function: command:modify-table table-name null-keys update |
4112 - Function: command:modify-table table-name null-keys |
4113 Returns procedure (of DB) which returns procedure to modify row of |
4114 TABLE-NAME. NULL-KEYS is the list of "null" keys which indicate |
4115 that the row is to be deleted. Optional arguments UPDATE, DELETE, |
4116 and RETRIEVE default to the `row:update', `row:delete', and |
4117 `row:retrieve' of TABLE-NAME in DB. |
4119 - Function: command:make-editable-table rdb table-name arg ... |
4120 Given TABLE-NAME in RDB, creates parameter and `*command*' tables |
4121 for editing one row of TABLE-NAME at a time. |
4122 `command:make-editable-table' returns a procedure taking a row |
4123 argument which returns the HTML string for editing that row. |
4125 Optional ARGS are expressions (lists) added to the call to |
4126 `command:modify-table'. |
4128 The domain name of a column determines the expected arity of the |
4129 data stored in that column. Domain names ending in: |
4132 have arity `nary'; |
4135 have arity `nary1'. |
4137 - Function: html:editable-row-converter k names edit-point |
4139 The positive integer K is the primary-key-limit (number of |
4140 primary-keys) of the table. NAMES is a list of the field-names. |
4141 EDIT-POINT is the list of primary-keys denoting the row to edit |
4142 (or #f). EDIT-CONVERTER is the procedure called with K, NAMES, |
4143 and the row to edit. |
4145 `html:editable-row-converter' returns a procedure taking a row for |
4146 its single argument. This returned procedure returns the html |
4147 string for that table row. |
4149 Each HTML table constructed using `html:editable-row-converter' |
4150 has first K fields (typically the primary key fields) of each row |
4151 linked to a text encoding of these fields (the result of calling |
4152 `row->anchor'). The page so referenced typically allows the user |
4153 to edit fields of that row. |
4158 - Function: db->html-files db dir index-filename caption |
4159 DB must be a relational database. DIR must be #f or a non-empty
4160 string naming an existing sub-directory of the current directory.
4162 `db->html-files' creates an html page for each table in the |
4163 database DB in the sub-directory named DIR, or the current |
4164 directory if DIR is #f. The top level page with the catalog of |
4165 tables (captioned CAPTION) is written to a file named |
4168 - Function: db->html-directory db dir index-filename |
4169 - Function: db->html-directory db dir |
4170 DB must be a relational database. DIR must be a non-empty string
4171 naming an existing sub-directory of the current directory or one
4172 to be created. The optional string INDEX-FILENAME names the
4173 filename of the top page, which defaults to `index.html'.
4175 `db->html-directory' creates sub-directory DIR if neccessary, and |
4176 calls `(db->html-files DB DIR INDEX-FILENAME DIR)'. The `file:' |
4177 URI of INDEX-FILENAME is returned. |
4179 - Function: db->netscape db dir index-filename
4180 - Function: db->netscape db dir
4181 `db->netscape' is just like `db->html-directory', but calls |
4182 `browse-url-netscape' with the uri for the top page after the |
4186 File: slib.info, Node: HTTP and CGI, Next: URI, Prev: HTML Tables, Up: Textual Conversion Packages
4191 `(require 'http)' or `(require 'cgi)'
4193 - Function: http:header alist
4194 Returns a string containing lines for each element of ALIST; the
4195 `car' of which is followed by `: ', then the `cdr'.
4197 - Function: http:content alist body ...
4198 Returns the concatenation of strings BODY with the `(http:header
4199 ALIST)' and the `Content-Length' prepended.
4201 - Variable: *http:byline*
4202 String appearing at the bottom of error pages.
4204 - Function: http:error-page status-code reason-phrase html-string ...
4205 STATUS-CODE and REASON-PHRASE should be an integer and string as
4206 specified in `RFC 2068'. The returned page (string) will show the
4207 STATUS-CODE and REASON-PHRASE and any additional HTML-STRINGS ...;
4208 with *HTTP:BYLINE* or SLIB's default at the bottom.
4210 - Function: http:forwarding-page title delay uri html-string ... |
4211 The string or symbol TITLE is the page title. DELAY is a |
4212 non-negative integer. The HTML-STRINGS ... are typically used to |
4213 explain to the user why this page is being forwarded. |
4215 `http:forwarding-page' returns an HTML string for a page which |
4216 automatically forwards to URI after DELAY seconds. The returned |
4217 page (string) contains any HTML-STRINGS ... followed by a manual |
4218 link to URI, in case the browser does not forward automatically. |
4220 - Function: http:serve-query serve-proc input-port output-port
4221 reads the "URI" and "query-string" from INPUT-PORT. If the query
4222 is a valid `"POST"' or `"GET"' query, then `http:serve-query' calls
4223 SERVE-PROC with three arguments, the REQUEST-LINE, QUERY-STRING,
4224 and HEADER-ALIST. Otherwise, `http:serve-query' calls SERVE-PROC
4225 with the REQUEST-LINE, #f, and HEADER-ALIST.
4227 If SERVE-PROC returns a string, it is sent to OUTPUT-PORT. If
4228 SERVE-PROC returns a list, then an error page with number 525 and
4229 strings from the list. If SERVE-PROC returns #f, then a `Bad
4230 Request' (400) page is sent to OUTPUT-PORT.
4232 Otherwise, `http:serve-query' replies (to OUTPUT-PORT) with
4233 appropriate HTML describing the problem.
4235 This example services HTTP queries from PORT-NUMBER:
4237 (define socket (make-stream-socket AF_INET 0))
4238 (and (socket:bind socket port-number) ; AF_INET INADDR_ANY
4239 (socket:listen socket 10) ; Queue up to 10 requests.
4243 (do ((port (socket:accept socket) (socket:accept socket)))
4245 (let ((iport (duplicate-port port "r"))
4246 (oport (duplicate-port port "w")))
4247 (http:serve-query build:serve iport oport)
4251 (lambda () (close-port socket))))
4253 - Function: cgi:serve-query serve-proc
4254 reads the "URI" and "query-string" from `(current-input-port)'.
4255 If the query is a valid `"POST"' or `"GET"' query, then
4256 `cgi:serve-query' calls SERVE-PROC with three arguments, the
4257 REQUEST-LINE, QUERY-STRING, and HEADER-ALIST. Otherwise,
4258 `cgi:serve-query' calls SERVE-PROC with the REQUEST-LINE, #f, and
4261 If SERVE-PROC returns a string, it is sent to
4262 `(current-input-port)'. If SERVE-PROC returns a list, then an
4263 error page with number 525 and strings from the list. If
4264 SERVE-PROC returns #f, then a `Bad Request' (400) page is sent to
4265 `(current-input-port)'.
4267 Otherwise, `cgi:serve-query' replies (to `(current-input-port)')
4268 with appropriate HTML describing the problem.
4270 - Function: make-query-alist-command-server rdb command-table |
4271 - Function: make-query-alist-command-server rdb command-table #t |
4272 Returns a procedure of one argument. When that procedure is called
4273 with a QUERY-ALIST (as returned by `uri:decode-query', the value |
4274 of the `*command*' association will be the command invoked in |
4275 COMMAND-TABLE. If `*command*' is not in the QUERY-ALIST then the |
4276 value of `*suggest*' is tried. If neither name is in the |
4277 QUERY-ALIST, then the literal value `*default*' is tried in |
4280 If optional third argument is non-false, then the command is called |
4281 with just the parameter-list; otherwise, command is called with the |
4282 arguments described in its table. |
4285 File: slib.info, Node: URI, Next: Printing Scheme, Prev: HTTP and CGI, Up: Textual Conversion Packages
4292 Implements "Uniform Resource Identifiers" (URI) as described in RFC |
4295 - Function: make-uri |
4296 - Function: make-uri fragment |
4297 - Function: make-uri query fragment |
4298 - Function: make-uri path query fragment |
4299 - Function: make-uri authority path query fragment |
4300 - Function: make-uri scheme authority path query fragment |
4301 Returns a Uniform Resource Identifier string from component |
4304 - Function: html:anchor name |
4305 Returns a string which defines this location in the (HTML) file as |
4306 NAME. The hypertext `<A HREF="#NAME">' will link to this point. |
4308 (html:anchor "(section 7)") |
4310 "<A NAME=\"(section%207)\"></A>" |
4312 - Function: html:link uri highlighted |
4313 Returns a string which links the HIGHLIGHTED text to URI. |
4315 (html:link (make-uri "(section 7)") "section 7") |
4317 "<A HREF=\"#(section%207)\">section 7</A>" |
4319 - Function: html:base uri |
4320 Returns a string specifying the "base" URI of a document, for |
4321 inclusion in the HEAD of the document (*note head: HTML.). |
4323 - Function: html:isindex prompt |
4324 Returns a string specifying the search PROMPT of a document, for |
4325 inclusion in the HEAD of the document (*note head: HTML.). |
4327 - Function: uri->tree uri-reference base-tree ... |
4328 Returns a list of 5 elements corresponding to the parts (SCHEME |
4329 AUTHORITY PATH QUERY FRAGMENT) of string URI-REFERENCE. Elements |
4330 corresponding to absent parts are #f. |
4332 The PATH is a list of strings. If the first string is empty, then |
4333 the path is absolute; otherwise relative. |
4335 If the AUTHORITY component is a "Server-based Naming Authority", |
4336 then it is a list of the USERINFO, HOST, and PORT strings (or #f). |
4337 For other types of AUTHORITY components the AUTHORITY will be a |
4340 (uri->tree "http://www.ics.uci.edu/pub/ietf/uri/#Related") |
4342 (http "www.ics.uci.edu" ("" "pub" "ietf" "uri" "") #f "Related") |
4344 `uric:' prefixes indicate procedures dealing with URI-components. |
4346 - Function: uric:encode uri-component allows |
4347 Returns a copy of the string URI-COMPONENT in which all "unsafe" |
4348 octets (as defined in RFC 2396) have been `%' "escaped". |
4349 `uric:decode' decodes strings encoded by `uric:encode'. |
4351 - Function: uric:decode uri-component |
4352 Returns a copy of the string URI-COMPONENT in which each `%' |
4353 escaped characters in URI-COMPONENT is replaced with the character |
4354 it encodes. This routine is useful for showing URI contents on |
4358 File: slib.info, Node: Printing Scheme, Next: Time and Date, Prev: URI, Up: Textual Conversion Packages
4365 * Generic-Write:: 'generic-write
4366 * Object-To-String:: 'object->string
4367 * Pretty-Print:: 'pretty-print, 'pprint-file
4370 File: slib.info, Node: Generic-Write, Next: Object-To-String, Prev: Printing Scheme, Up: Printing Scheme
4375 `(require 'generic-write)'
4377 `generic-write' is a procedure that transforms a Scheme data value
4378 (or Scheme program expression) into its textual representation and
4379 prints it. The interface to the procedure is sufficiently general to
4380 easily implement other useful formatting procedures such as pretty
4381 printing, output to a string and truncated output.
4383 - Procedure: generic-write obj display? width output
4385 Scheme data value to transform.
4388 Boolean, controls whether characters and strings are quoted.
4391 Extended boolean, selects format:
4396 pretty-print (value = max nb of chars per line)
4399 Procedure of 1 argument of string type, called repeatedly with
4400 successive substrings of the textual representation. This
4401 procedure can return `#f' to stop the transformation.
4403 The value returned by `generic-write' is undefined.
4406 (write obj) == (generic-write obj #f #f DISPLAY-STRING)
4407 (display obj) == (generic-write obj #t #f DISPLAY-STRING)
4411 (lambda (s) (for-each write-char (string->list s)) #t)
4414 File: slib.info, Node: Object-To-String, Next: Pretty-Print, Prev: Generic-Write, Up: Printing Scheme
4419 `(require 'object->string)'
4421 - Function: object->string obj
4422 Returns the textual representation of OBJ as a string.
4424 - Function: object->limited-string obj limit
4425 Returns the textual representation of OBJ as a string of length at
4429 File: slib.info, Node: Pretty-Print, Prev: Object-To-String, Up: Printing Scheme
4434 `(require 'pretty-print)'
4436 - Procedure: pretty-print obj
4437 - Procedure: pretty-print obj port
4438 `pretty-print's OBJ on PORT. If PORT is not specified,
4439 `current-output-port' is used.
4442 (pretty-print '((1 2 3 4 5) (6 7 8 9 10) (11 12 13 14 15)
4443 (16 17 18 19 20) (21 22 23 24 25)))
4448 -| (21 22 23 24 25))
4450 - Procedure: pretty-print->string obj |
4451 - Procedure: pretty-print->string obj width |
4452 Returns the string of OBJ `pretty-print'ed in WIDTH columns. If |
4453 WIDTH is not specified, `(output-port-width)' is used. |
4456 (pretty-print->string '((1 2 3 4 5) (6 7 8 9 10) (11 12 13 14 15) |
4457 (16 17 18 19 20) (21 22 23 24 25))) |
4465 (pretty-print->string '((1 2 3 4 5) (6 7 8 9 10) (11 12 13 14 15) |
4466 (16 17 18 19 20) (21 22 23 24 25)) |
4488 `(require 'pprint-file)'
4490 - Procedure: pprint-file infile
4491 - Procedure: pprint-file infile outfile
4492 Pretty-prints all the code in INFILE. If OUTFILE is specified,
4493 the output goes to OUTFILE, otherwise it goes to
4494 `(current-output-port)'.
4496 - Function: pprint-filter-file infile proc outfile
4497 - Function: pprint-filter-file infile proc
4498 INFILE is a port or a string naming an existing file. Scheme
4499 source code expressions and definitions are read from the port (or
4500 file) and PROC is applied to them sequentially.
4502 OUTFILE is a port or a string. If no OUTFILE is specified then
4503 `current-output-port' is assumed. These expanded expressions are
4504 then `pretty-print'ed to this port.
4506 Whitepsace and comments (introduced by `;') which are not part of
4507 scheme expressions are reproduced in the output. This procedure
4508 does not affect the values returned by `current-input-port' and
4509 `current-output-port'.
4511 `pprint-filter-file' can be used to pre-compile macro-expansion and
4512 thus can reduce loading time. The following will write into
4513 `exp-code.scm' the result of expanding all defmacros in `code.scm'.
4514 (require 'pprint-file)
4515 (require 'defmacroexpand)
4516 (defmacro:load "my-macros.scm")
4517 (pprint-filter-file "code.scm" defmacro:expand* "exp-code.scm")
4520 File: slib.info, Node: Time and Date, Next: Vector Graphics, Prev: Printing Scheme, Up: Textual Conversion Packages
4528 * Posix Time:: 'posix-time
4529 * Common-Lisp Time:: 'common-lisp-time
4531 If `(provided? 'current-time)':
4533 The procedures `current-time', `difftime', and `offset-time' deal with
4534 a "calendar time" datatype which may or may not be disjoint from other
4537 - Function: current-time
4538 Returns the time since 00:00:00 GMT, January 1, 1970, measured in
4539 seconds. Note that the reference time is different from the
4540 reference time for `get-universal-time' in *Note Common-Lisp
4543 - Function: difftime caltime1 caltime0
4544 Returns the difference (number of seconds) between twe calendar
4545 times: CALTIME1 - CALTIME0. CALTIME0 may also be a number.
4547 - Function: offset-time caltime offset
4548 Returns the calendar time of CALTIME offset by OFFSET number of
4549 seconds `(+ caltime offset)'.
4552 File: slib.info, Node: Time Zone, Next: Posix Time, Prev: Time and Date, Up: Time and Date
4557 (require 'time-zone)
4559 - Data Format: TZ-string
4560 POSIX standards specify several formats for encoding time-zone
4564 If the first character of <pathname> is `/', then <pathname>
4565 specifies the absolute pathname of a tzfile(5) format
4566 time-zone file. Otherwise, <pathname> is interpreted as a
4567 pathname within TZFILE:VICINITY (/usr/lib/zoneinfo/) naming a
4568 tzfile(5) format time-zone file.
4571 The string <std> consists of 3 or more alphabetic characters.
4572 <offset> specifies the time difference from GMT. The <offset>
4573 is positive if the local time zone is west of the Prime
4574 Meridian and negative if it is east. <offset> can be the
4575 number of hours or hours and minutes (and optionally seconds)
4576 separated by `:'. For example, `-4:30'.
4579 <dst> is the at least 3 alphabetic characters naming the local
4580 daylight-savings-time.
4582 <std><offset><dst><doffset>
4583 <doffset> specifies the offset from the Prime Meridian when
4584 daylight-savings-time is in effect.
4586 The non-tzfile formats can optionally be followed by transition
4587 times specifying the day and time when a zone changes from
4588 standard to daylight-savings and back again.
4590 ,<date>/<time>,<date>/<time>
4591 The <time>s are specified like the <offset>s above, except
4592 that leading `+' and `-' are not allowed.
4594 Each <date> has one of the formats:
4597 specifies the Julian day with <day> between 1 and 365.
4598 February 29 is never counted and cannot be referenced.
4601 This specifies the Julian day with n between 0 and 365.
4602 February 29 is counted in leap years and can be
4605 M<month>.<week>.<day>
4606 This specifies day <day> (0 <= <day> <= 6) of week
4607 <week> (1 <= <week> <= 5) of month <month> (1 <= <month>
4608 <= 12). Week 1 is the first week in which day d occurs
4609 and week 5 is the last week in which day <day> occurs.
4613 - Data Type: time-zone
4614 is a datatype encoding how many hours from Greenwich Mean Time the
4615 local time is, and the "Daylight Savings Time" rules for changing
4618 - Function: time-zone TZ-string
4619 Creates and returns a time-zone object specified by the string
4620 TZ-STRING. If `time-zone' cannot interpret TZ-STRING, `#f' is
4623 - Function: tz:params caltime tz
4624 TZ is a time-zone object. `tz:params' returns a list of three
4626 0. An integer. 0 if standard time is in effect for timezone TZ
4627 at CALTIME; 1 if daylight savings time is in effect for
4628 timezone TZ at CALTIME.
4630 1. The number of seconds west of the Prime Meridian timezone TZ
4633 2. The name for timezone TZ at CALTIME.
4635 `tz:params' is unaffected by the default timezone; inquiries can be
4636 made of any timezone at any calendar time.
4639 The rest of these procedures and variables are provided for POSIX
4640 compatability. Because of shared state they are not thread-safe.
4643 Returns the default time-zone.
4645 - Function: tzset tz
4646 Sets (and returns) the default time-zone to TZ.
4648 - Function: tzset TZ-string
4649 Sets (and returns) the default time-zone to that specified by
4652 `tzset' also sets the variables *TIMEZONE*, DAYLIGHT?, and TZNAME.
4653 This function is automatically called by the time conversion
4654 procedures which depend on the time zone (*note Time and Date::).
4656 - Variable: *timezone*
4657 Contains the difference, in seconds, between Greenwich Mean Time
4658 and local standard time (for example, in the U.S. Eastern time
4659 zone (EST), timezone is 5*60*60). `*timezone*' is initialized by
4662 - Variable: daylight?
4663 is `#t' if the default timezone has rules for "Daylight Savings
4664 Time". _Note:_ DAYLIGHT? does not tell you when Daylight Savings
4665 Time is in effect, just that the default zone sometimes has
4666 Daylight Savings Time.
4669 is a vector of strings. Index 0 has the abbreviation for the
4670 standard timezone; If DAYLIGHT?, then index 1 has the abbreviation
4671 for the Daylight Savings timezone.
4674 File: slib.info, Node: Posix Time, Next: Common-Lisp Time, Prev: Time Zone, Up: Time and Date
4679 (require 'posix-time)
4681 - Data Type: Calendar-Time
4682 is a datatype encapsulating time.
4684 - Data Type: Coordinated Universal Time
4685 (abbreviated "UTC") is a vector of integers representing time:
4691 2. hours since midnight (0 - 23)
4693 3. day of month (1 - 31)
4695 4. month (0 - 11). Note difference from
4696 `decode-universal-time'.
4698 5. the number of years since 1900. Note difference from
4699 `decode-universal-time'.
4701 6. day of week (0 - 6)
4703 7. day of year (0 - 365)
4705 8. 1 for daylight savings, 0 for regular time
4707 - Function: gmtime caltime
4708 Converts the calendar time CALTIME to UTC and returns it.
4710 - Function: localtime caltime tz
4711 Returns CALTIME converted to UTC relative to timezone TZ.
4713 - Function: localtime caltime
4714 converts the calendar time CALTIME to a vector of integers
4715 expressed relative to the user's time zone. `localtime' sets the
4716 variable *TIMEZONE* with the difference between Coordinated
4717 Universal Time (UTC) and local standard time in seconds (*note
4721 - Function: gmktime univtime
4722 Converts a vector of integers in GMT Coordinated Universal Time
4723 (UTC) format to a calendar time.
4725 - Function: mktime univtime
4726 Converts a vector of integers in local Coordinated Universal Time
4727 (UTC) format to a calendar time.
4729 - Function: mktime univtime tz
4730 Converts a vector of integers in Coordinated Universal Time (UTC)
4731 format (relative to time-zone TZ) to calendar time.
4733 - Function: asctime univtime
4734 Converts the vector of integers CALTIME in Coordinated Universal
4735 Time (UTC) format into a string of the form `"Wed Jun 30 21:49:08
4738 - Function: gtime caltime
4739 - Function: ctime caltime
4740 - Function: ctime caltime tz
4741 Equivalent to `(asctime (gmtime CALTIME))', `(asctime (localtime
4742 CALTIME))', and `(asctime (localtime CALTIME TZ))', respectively.
4745 File: slib.info, Node: Common-Lisp Time, Prev: Posix Time, Up: Time and Date
4750 - Function: get-decoded-time
4751 Equivalent to `(decode-universal-time (get-universal-time))'.
4753 - Function: get-universal-time
4754 Returns the current time as "Universal Time", number of seconds
4755 since 00:00:00 Jan 1, 1900 GMT. Note that the reference time is
4756 different from `current-time'.
4758 - Function: decode-universal-time univtime
4759 Converts UNIVTIME to "Decoded Time" format. Nine values are
4765 2. hours since midnight
4769 4. month (1 - 12). Note difference from `gmtime' and
4772 5. year (A.D.). Note difference from `gmtime' and `localtime'.
4774 6. day of week (0 - 6)
4776 7. #t for daylight savings, #f otherwise
4778 8. hours west of GMT (-24 - +24)
4780 Notice that the values returned by `decode-universal-time' do not
4781 match the arguments to `encode-universal-time'.
4783 - Function: encode-universal-time second minute hour date month year
4784 - Function: encode-universal-time second minute hour date month year
4786 Converts the arguments in Decoded Time format to Universal Time
4787 format. If TIME-ZONE is not specified, the returned time is
4788 adjusted for daylight saving time. Otherwise, no adjustment is
4791 Notice that the values returned by `decode-universal-time' do not
4792 match the arguments to `encode-universal-time'.
4795 File: slib.info, Node: Vector Graphics, Next: Schmooz, Prev: Time and Date, Up: Textual Conversion Packages
4802 * Tektronix Graphics Support::
4805 File: slib.info, Node: Tektronix Graphics Support, Prev: Vector Graphics, Up: Vector Graphics
4807 Tektronix Graphics Support
4808 --------------------------
4810 _Note:_ The Tektronix graphics support files need more work, and are
4813 Tektronix 4000 Series Graphics
4814 ..............................
4816 The Tektronix 4000 series graphics protocol gives the user a 1024 by
4817 1024 square drawing area. The origin is in the lower left corner of the
4818 screen. Increasing y is up and increasing x is to the right.
4820 The graphics control codes are sent over the current-output-port and
4821 can be mixed with regular text and ANSI or other terminal control
4824 - Procedure: tek40:init
4826 - Procedure: tek40:graphics
4828 - Procedure: tek40:text
4830 - Procedure: tek40:linetype linetype
4832 - Procedure: tek40:move x y
4834 - Procedure: tek40:draw x y
4836 - Procedure: tek40:put-text x y str
4838 - Procedure: tek40:reset
4840 Tektronix 4100 Series Graphics
4841 ..............................
4843 The graphics control codes are sent over the current-output-port and
4844 can be mixed with regular text and ANSI or other terminal control
4847 - Procedure: tek41:init
4849 - Procedure: tek41:reset
4851 - Procedure: tek41:graphics
4853 - Procedure: tek41:move x y
4855 - Procedure: tek41:draw x y
4857 - Procedure: tek41:point x y number
4859 - Procedure: tek41:encode-x-y x y
4861 - Procedure: tek41:encode-int number
4864 File: slib.info, Node: Schmooz, Prev: Vector Graphics, Up: Textual Conversion Packages
4869 "Schmooz" is a simple, lightweight markup language for interspersing
4870 Texinfo documentation with Scheme source code. Schmooz does not create
4871 the top level Texinfo file; it creates `txi' files which can be
4872 imported into the documentation using the Texinfo command `@include'.
4874 `(require 'schmooz)' defines the function `schmooz', which is used to
4875 process files. Files containing schmooz documentation should not
4876 contain `(require 'schmooz)'.
4878 - Procedure: schmooz filenamescm ...
4879 FILENAMEscm should be a string ending with `scm' naming an
4880 existing file containing Scheme source code. `schmooz' extracts
4881 top-level comments containing schmooz commands from FILENAMEscm
4882 and writes the converted Texinfo source to a file named
4885 - Procedure: schmooz filenametexi ...
4886 - Procedure: schmooz filenametex ...
4887 - Procedure: schmooz filenametxi ...
4888 FILENAME should be a string naming an existing file containing
4889 Texinfo source code. For every occurrence of the string `@include
4890 FILENAMEtxi' within that file, `schmooz' calls itself with the
4891 argument `FILENAMEscm'.
4893 Schmooz comments are distinguished (from non-schmooz comments) by
4894 their first line, which must start with an at-sign (@) preceded by one
4895 or more semicolons (;). A schmooz comment ends at the first subsequent
4896 line which does _not_ start with a semicolon. Currently schmooz
4897 comments are recognized only at top level.
4899 Schmooz comments are copied to the Texinfo output file with the
4900 leading contiguous semicolons removed. Certain character sequences
4901 starting with at-sign are treated specially. Others are copied
4904 A schmooz comment starting with `@body' must be followed by a Scheme
4905 definition. All comments between the `@body' line and the definition
4906 will be included in a Texinfo definition, either a `@defun' or a
4907 `@defvar', depending on whether a procedure or a variable is being
4910 Within the text of that schmooz comment, at-sign followed by `0' will
4911 be replaced by `@code{procedure-name}' if the following definition is
4912 of a procedure; or `@var{variable}' if defining a variable.
4914 An at-sign followed by a non-zero digit will expand to the variable
4915 citation of that numbered argument: `@var{argument-name}'.
4917 If more than one definition follows a `@body' comment line without an
4918 intervening blank or comment line, then those definitions will be
4919 included in the same Texinfo definition using `@defvarx' or `@defunx',
4920 depending on whether the first definition is of a variable or of a
4923 Schmooz can figure out whether a definition is of a procedure if it
4926 `(define (<identifier> <arg> ...) <expression>)'
4928 or if the left hand side of the definition is some form ending in a
4929 lambda expression. Obviously, it can be fooled. In order to force
4930 recognition of a procedure definition, start the documentation with
4931 `@args' instead of `@body'. `@args' should be followed by the argument
4932 list of the function being defined, which may be enclosed in
4933 parentheses and delimited by whitespace, (as in Scheme), enclosed in
4934 braces and separated by commas, (as in Texinfo), or consist of the
4935 remainder of the line, separated by whitespace.
4939 ;;@args arg1 args ...
4940 ;;@0 takes argument @1 and any number of @2
4941 (define myfun (some-function-returning-magic))
4945 @defun myfun arg1 args @dots{}
4947 @code{myfun} takes argument @var{arg1} and any number of @var{args}
4950 `@args' may also be useful for indicating optional arguments by name.
4951 If `@args' occurs inside a schmooz comment section, rather than at the
4952 beginning, then it will generate a `@defunx' line with the arguments
4955 If the first at-sign in a schmooz comment is immediately followed by
4956 whitespace, then the comment will be expanded to whatever follows that
4957 whitespace. If the at-sign is followed by a non-whitespace character
4958 then the at-sign will be included as the first character of the
4959 expansion. This feature is intended to make it easy to include Texinfo
4960 directives in schmooz comments.
4963 File: slib.info, Node: Mathematical Packages, Next: Database Packages, Prev: Textual Conversion Packages, Up: Top
4965 Mathematical Packages
4966 *********************
4970 * Bit-Twiddling:: 'logical
4971 * Modular Arithmetic:: 'modular
4972 * Prime Numbers:: 'factor
4973 * Random Numbers:: 'random
4974 * Fast Fourier Transform:: 'fft
4975 * Cyclic Checksum:: 'make-crc
4976 * Plotting:: 'charplot
4977 * Root Finding:: 'root
4978 * Minimizing:: 'minimize
4979 * Commutative Rings:: 'commutative-ring
4980 * Determinant:: 'determinant
4983 File: slib.info, Node: Bit-Twiddling, Next: Modular Arithmetic, Prev: Mathematical Packages, Up: Mathematical Packages
4988 `(require 'logical)'
4990 The bit-twiddling functions are made available through the use of the
4991 `logical' package. `logical' is loaded by inserting `(require
4992 'logical)' before the code that uses these functions. These functions
4993 behave as though operating on integers in two's-complement
4999 - Function: logand n1 n1
5000 Returns the integer which is the bit-wise AND of the two integer
5004 (number->string (logand #b1100 #b1010) 2)
5007 - Function: logior n1 n2
5008 Returns the integer which is the bit-wise OR of the two integer
5012 (number->string (logior #b1100 #b1010) 2)
5015 - Function: logxor n1 n2
5016 Returns the integer which is the bit-wise XOR of the two integer
5020 (number->string (logxor #b1100 #b1010) 2)
5023 - Function: lognot n
5024 Returns the integer which is the 2s-complement of the integer
5028 (number->string (lognot #b10000000) 2)
5030 (number->string (lognot #b0) 2)
5033 - Function: bitwise-if mask n0 n1
5034 Returns an integer composed of some bits from integer N0 and some
5035 from integer N1. A bit of the result is taken from N0 if the
5036 corresponding bit of integer MASK is 1 and from N1 if that bit of
5039 - Function: logtest j k
5040 (logtest j k) == (not (zero? (logand j k)))
5042 (logtest #b0100 #b1011) => #f
5043 (logtest #b0100 #b0111) => #t
5045 - Function: logcount n
5046 Returns the number of bits in integer N. If integer is positive,
5047 the 1-bits in its binary representation are counted. If negative,
5048 the 0-bits in its two's-complement binary representation are
5049 counted. If 0, 0 is returned.
5052 (logcount #b10101010)
5062 - Function: logbit? index j
5063 (logbit? index j) == (logtest (integer-expt 2 index) j)
5065 (logbit? 0 #b1101) => #t
5066 (logbit? 1 #b1101) => #f
5067 (logbit? 2 #b1101) => #t
5068 (logbit? 3 #b1101) => #t
5069 (logbit? 4 #b1101) => #f
5071 - Function: copy-bit index from bit
5072 Returns an integer the same as FROM except in the INDEXth bit,
5073 which is 1 if BIT is `#t' and 0 if BIT is `#f'.
5076 (number->string (copy-bit 0 0 #t) 2) => "1"
5077 (number->string (copy-bit 2 0 #t) 2) => "100"
5078 (number->string (copy-bit 2 #b1111 #f) 2) => "1011"
5083 - Function: bit-field n start end
5084 Returns the integer composed of the START (inclusive) through END
5085 (exclusive) bits of N. The STARTth bit becomes the 0-th bit in
5088 This function was called `bit-extract' in previous versions of
5092 (number->string (bit-field #b1101101010 0 4) 2)
5094 (number->string (bit-field #b1101101010 4 9) 2)
5097 - Function: copy-bit-field to start end from
5098 Returns an integer the same as TO except possibly in the START
5099 (inclusive) through END (exclusive) bits, which are the same as
5100 those of FROM. The 0-th bit of FROM becomes the STARTth bit of
5104 (number->string (copy-bit-field #b1101101010 0 4 0) 2)
5106 (number->string (copy-bit-field #b1101101010 0 4 -1) 2)
5109 - Function: ash int count
5110 Returns an integer equivalent to `(inexact->exact (floor (* INT
5114 (number->string (ash #b1 3) 2)
5116 (number->string (ash #b1010 -1) 2)
5119 - Function: integer-length n
5120 Returns the number of bits neccessary to represent N.
5123 (integer-length #b10101010)
5127 (integer-length #b1111)
5130 - Function: integer-expt n k
5131 Returns N raised to the non-negative integer exponent K.
5140 File: slib.info, Node: Modular Arithmetic, Next: Prime Numbers, Prev: Bit-Twiddling, Up: Mathematical Packages
5145 `(require 'modular)'
5147 - Function: extended-euclid n1 n2
5148 Returns a list of 3 integers `(d x y)' such that d = gcd(N1, N2) =
5151 - Function: symmetric:modulus n
5152 Returns `(quotient (+ -1 n) -2)' for positive odd integer N.
5154 - Function: modulus->integer modulus
5155 Returns the non-negative integer characteristic of the ring formed
5156 when MODULUS is used with `modular:' procedures.
5158 - Function: modular:normalize modulus n
5159 Returns the integer `(modulo N (modulus->integer MODULUS))' in the
5160 representation specified by MODULUS.
5162 The rest of these functions assume normalized arguments; That is, the
5163 arguments are constrained by the following table:
5165 For all of these functions, if the first argument (MODULUS) is:
5167 Work as before. The result is between 0 and MODULUS.
5170 The arguments are treated as integers. An integer is returned.
5173 The arguments and result are treated as members of the integers
5174 modulo `(+ 1 (* -2 MODULUS))', but with "symmetric"
5175 representation; i.e. `(<= (- MODULUS) N MODULUS)'.
5177 If all the arguments are fixnums the computation will use only fixnums.
5179 - Function: modular:invertable? modulus k
5180 Returns `#t' if there exists an integer n such that K * n == 1 mod
5181 MODULUS, and `#f' otherwise.
5183 - Function: modular:invert modulus k2
5184 Returns an integer n such that 1 = (n * K2) mod MODULUS. If K2
5185 has no inverse mod MODULUS an error is signaled.
5187 - Function: modular:negate modulus k2
5188 Returns (-K2) mod MODULUS.
5190 - Function: modular:+ modulus k2 k3
5191 Returns (K2 + K3) mod MODULUS.
5193 - Function: modular:- modulus k2 k3
5194 Returns (K2 - K3) mod MODULUS.
5196 - Function: modular:* modulus k2 k3
5197 Returns (K2 * K3) mod MODULUS.
5199 The Scheme code for `modular:*' with negative MODULUS is not
5200 completed for fixnum-only implementations.
5202 - Function: modular:expt modulus k2 k3
5203 Returns (K2 ^ K3) mod MODULUS.
5206 File: slib.info, Node: Prime Numbers, Next: Random Numbers, Prev: Modular Arithmetic, Up: Mathematical Packages
5213 - Variable: prime:prngs
5214 PRIME:PRNGS is the random-state (*note Random Numbers::) used by
5215 these procedures. If you call these procedures from more than one
5216 thread (or from interrupt), `random' may complain about reentrant
5218 _Note:_ The prime test and generation procedures implement (or use)
5219 the Solovay-Strassen primality test. See
5221 * Robert Solovay and Volker Strassen, `A Fast Monte-Carlo Test for
5222 Primality', SIAM Journal on Computing, 1977, pp 84-85.
5224 - Function: jacobi-symbol p q
5225 Returns the value (+1, -1, or 0) of the Jacobi-Symbol of exact
5226 non-negative integer P and exact positive odd integer Q.
5228 - Variable: prime:trials
5229 PRIME:TRIALS the maxinum number of iterations of Solovay-Strassen
5230 that will be done to test a number for primality.
5232 - Function: prime? n
5233 Returns `#f' if N is composite; `#t' if N is prime. There is a
5234 slight chance `(expt 2 (- prime:trials))' that a composite will
5237 - Function: primes< start count
5238 Returns a list of the first COUNT prime numbers less than START.
5239 If there are fewer than COUNT prime numbers less than START, then
5240 the returned list will have fewer than START elements.
5242 - Function: primes> start count
5243 Returns a list of the first COUNT prime numbers greater than START.
5245 - Function: factor k
5246 Returns a list of the prime factors of K. The order of the
5247 factors is unspecified. In order to obtain a sorted list do
5248 `(sort! (factor K) <)'.
5251 File: slib.info, Node: Random Numbers, Next: Fast Fourier Transform, Prev: Prime Numbers, Up: Mathematical Packages
5258 A pseudo-random number generator is only as good as the tests it
5259 passes. George Marsaglia of Florida State University developed a
5260 battery of tests named "DIEHARD"
5261 (<http://stat.fsu.edu/~geo/diehard.html>). `diehard.c' has a bug which
5263 <http://swissnet.ai.mit.edu/ftpdir/users/jaffer/diehard.c.pat> corrects.
5265 SLIB's new PRNG generates 8 bits at a time. With the degenerate seed
5266 `0', the numbers generated pass DIEHARD; but when bits are combined
5267 from sequential bytes, tests fail. With the seed
5268 `http://swissnet.ai.mit.edu/~jaffer/SLIB.html', all of those tests pass.
5270 - Function: random n
5271 - Function: random n state
5272 Accepts a positive integer or real N and returns a number of the
5273 same type between zero (inclusive) and N (exclusive). The values
5274 returned by `random' are uniformly distributed from 0 to N.
5276 The optional argument STATE must be of the type returned by
5277 `(seed->random-state)' or `(make-random-state)'. It defaults to
5278 the value of the variable `*random-state*'. This object is used
5279 to maintain the state of the pseudo-random-number generator and is
5280 altered as a side effect of calls to `random'.
5282 - Variable: *random-state*
5283 Holds a data structure that encodes the internal state of the
5284 random-number generator that `random' uses by default. The nature
5285 of this data structure is implementation-dependent. It may be
5286 printed out and successfully read back in, but may or may not
5287 function correctly as a random-number state object in another
5290 - Function: copy-random-state state
5291 Returns a new copy of argument STATE.
5293 - Function: copy-random-state
5294 Returns a new copy of `*random-state*'.
5296 - Function: seed->random-state seed
5297 Returns a new object of type suitable for use as the value of the
5298 variable `*random-state*' or as a second argument to `random'.
5299 The number or string SEED is used to initialize the state. If
5300 `seed->random-state' is called twice with arguments which are
5301 `equal?', then the returned data structures will be `equal?'.
5302 Calling `seed->random-state' with unequal arguments will nearly
5303 always return unequal states.
5305 - Function: make-random-state
5306 - Function: make-random-state obj
5307 Returns a new object of type suitable for use as the value of the
5308 variable `*random-state*' or as a second argument to `random'. If
5309 the optional argument OBJ is given, it should be a printable
5310 Scheme object; the first 50 characters of its printed
5311 representation will be used as the seed. Otherwise the value of
5312 `*random-state*' is used as the seed.
5314 If inexact numbers are supported by the Scheme implementation,
5315 `randinex.scm' will be loaded as well. `randinex.scm' contains
5316 procedures for generating inexact distributions.
5318 - Function: random:uniform
5319 - Function: random:uniform state
5320 Returns an uniformly distributed inexact real random number in the
5321 range between 0 and 1.
5323 - Function: random:exp
5324 - Function: random:exp state
5325 Returns an inexact real in an exponential distribution with mean
5326 1. For an exponential distribution with mean U use
5327 `(* U (random:exp))'.
5329 - Function: random:normal
5330 - Function: random:normal state
5331 Returns an inexact real in a normal distribution with mean 0 and
5332 standard deviation 1. For a normal distribution with mean M and
5333 standard deviation D use `(+ M (* D (random:normal)))'.
5335 - Function: random:normal-vector! vect
5336 - Function: random:normal-vector! vect state
5337 Fills VECT with inexact real random numbers which are independent
5338 and standard normally distributed (i.e., with mean 0 and variance
5341 - Function: random:hollow-sphere! vect
5342 - Function: random:hollow-sphere! vect state
5343 Fills VECT with inexact real random numbers the sum of whose
5344 squares is equal to 1.0. Thinking of VECT as coordinates in space
5345 of dimension n = `(vector-length VECT)', the coordinates are
5346 uniformly distributed over the surface of the unit n-shere.
5348 - Function: random:solid-sphere! vect
5349 - Function: random:solid-sphere! vect state
5350 Fills VECT with inexact real random numbers the sum of whose
5351 squares is less than 1.0. Thinking of VECT as coordinates in
5352 space of dimension N = `(vector-length VECT)', the coordinates are
5353 uniformly distributed within the unit N-shere. The sum of the
5354 squares of the numbers is returned.
5357 File: slib.info, Node: Fast Fourier Transform, Next: Cyclic Checksum, Prev: Random Numbers, Up: Mathematical Packages
5359 Fast Fourier Transform
5360 ======================
5364 - Function: fft array
5365 ARRAY is an array of `(expt 2 n)' numbers. `fft' returns an array
5366 of complex numbers comprising the "Discrete Fourier Transform" of
5369 - Function: fft-1 array
5370 `fft-1' returns an array of complex numbers comprising the inverse
5371 Discrete Fourier Transform of ARRAY.
5373 `(fft-1 (fft ARRAY))' will return an array of values close to ARRAY.
5375 (fft '#(1 0+i -1 0-i 1 0+i -1 0-i)) =>
5377 #(0.0 0.0 0.0+628.0783185208527e-18i 0.0
5378 0.0 0.0 8.0-628.0783185208527e-18i 0.0)
5380 (fft-1 '#(0 0 0 0 0 0 8 0)) =>
5382 #(1.0 -61.23031769111886e-18+1.0i -1.0 61.23031769111886e-18-1.0i
5383 1.0 -61.23031769111886e-18+1.0i -1.0 61.23031769111886e-18-1.0i)
5386 File: slib.info, Node: Cyclic Checksum, Next: Plotting, Prev: Fast Fourier Transform, Up: Mathematical Packages
5391 `(require 'make-crc)'
5393 - Function: make-port-crc
5394 - Function: make-port-crc degree |
5395 Returns an expression for a procedure of one argument, a port.
5396 This procedure reads characters from the port until the end of
5397 file and returns the integer checksum of the bytes read.
5399 The integer DEGREE, if given, specifies the degree of the
5400 polynomial being computed - which is also the number of bits
5401 computed in the checksums. The default value is 32.
5403 - Function: make-port-crc generator |
5404 The integer GENERATOR specifies the polynomial being computed. |
5405 The power of 2 generating each 1 bit is the exponent of a term of |
5406 the polynomial. The value of GENERATOR must be larger than 127. |
5408 - Function: make-port-crc degree generator |
5409 The integer GENERATOR specifies the polynomial being computed.
5410 The power of 2 generating each 1 bit is the exponent of a term of
5411 the polynomial. The bit at position DEGREE is implicit and should
5412 not be part of GENERATOR. This allows systems with numbers
5413 limited to 32 bits to calculate 32 bit checksums. The default
5414 value of GENERATOR when DEGREE is 32 (its default) is:
5416 (make-port-crc 32 #b00000100110000010001110110110111)
5418 Creates a procedure to calculate the P1003.2/D11.2 (POSIX.2) 32-bit
5419 checksum from the polynomial:
5421 32 26 23 22 16 12 11
5422 ( x + x + x + x + x + x + x +
5425 x + x + x + x + x + x + x + 1 ) mod 2
5428 (define crc32 (slib:eval (make-port-crc)))
5429 (define (file-check-sum file) (call-with-input-file file crc32))
5430 (file-check-sum (in-vicinity (library-vicinity) "ratize.scm"))
5435 File: slib.info, Node: Plotting, Next: Root Finding, Prev: Cyclic Checksum, Up: Mathematical Packages
5437 Plotting on Character Devices
5438 =============================
5440 `(require 'charplot)'
5442 The plotting procedure is made available through the use of the
5443 `charplot' package. `charplot' is loaded by inserting `(require
5444 'charplot)' before the code that uses this procedure.
5446 - Variable: charplot:height
5447 The number of rows to make the plot vertically.
5449 - Variable: charplot:width
5450 The number of columns to make the plot horizontally.
5452 - Procedure: plot! coords x-label y-label
5453 COORDS is a list of pairs of x and y coordinates. X-LABEL and
5454 Y-LABEL are strings with which to label the x and y axes.
5458 (set! charplot:height 19)
5459 (set! charplot:width 45)
5461 (define (make-points n)
5464 (cons (cons (/ n 6) (sin (/ n 6))) (make-points (1- n)))))
5466 (plot! (make-points 37) "x" "Sin(x)")
5468 Sin(x) ______________________________________________
5479 0|-------------------*--------------------------|
5488 |____________:_____._____:_____._____:_________|
5491 - Procedure: plot-function! func x1 x2
5492 - Procedure: plot-function! func x1 x2 npts
5493 Plots the function of one argument FUNC over the range X1 to X2.
5494 If the optional integer argument NPTS is supplied, it specifies
5495 the number of points to evaluate FUNC at.
5498 File: slib.info, Node: Root Finding, Next: Minimizing, Prev: Plotting, Up: Mathematical Packages
5505 - Function: newtown:find-integer-root f df/dx x0
5506 Given integer valued procedure F, its derivative (with respect to
5507 its argument) DF/DX, and initial integer value X0 for which
5508 DF/DX(X0) is non-zero, returns an integer X for which F(X) is
5509 closer to zero than either of the integers adjacent to X; or
5510 returns `#f' if such an integer can't be found.
5512 To find the closest integer to a given integers square root:
5514 (define (integer-sqrt y)
5515 (newton:find-integer-root
5516 (lambda (x) (- (* x x) y))
5517 (lambda (x) (* 2 x))
5518 (ash 1 (quotient (integer-length y) 2))))
5520 (integer-sqrt 15) => 4
5522 - Function: integer-sqrt y
5523 Given a non-negative integer Y, returns the rounded square-root of
5526 - Function: newton:find-root f df/dx x0 prec
5527 Given real valued procedures F, DF/DX of one (real) argument,
5528 initial real value X0 for which DF/DX(X0) is non-zero, and
5529 positive real number PREC, returns a real X for which `abs'(F(X))
5530 is less than PREC; or returns `#f' if such a real can't be found.
5532 If PREC is instead a negative integer, `newton:find-root' returns
5533 the result of -PREC iterations.
5535 H. J. Orchard, `The Laguerre Method for Finding the Zeros of
5536 Polynomials', IEEE Transactions on Circuits and Systems, Vol. 36, No.
5537 11, November 1989, pp 1377-1381.
5539 There are 2 errors in Orchard's Table II. Line k=2 for starting
5540 value of 1000+j0 should have Z_k of 1.0475 + j4.1036 and line k=2
5541 for starting value of 0+j1000 should have Z_k of 1.0988 + j4.0833.
5543 - Function: laguerre:find-root f df/dz ddf/dz^2 z0 prec
5544 Given complex valued procedure F of one (complex) argument, its
5545 derivative (with respect to its argument) DF/DX, its second
5546 derivative DDF/DZ^2, initial complex value Z0, and positive real
5547 number PREC, returns a complex number Z for which
5548 `magnitude'(F(Z)) is less than PREC; or returns `#f' if such a
5549 number can't be found.
5551 If PREC is instead a negative integer, `laguerre:find-root'
5552 returns the result of -PREC iterations.
5554 - Function: laguerre:find-polynomial-root deg f df/dz ddf/dz^2 z0 prec
5555 Given polynomial procedure F of integer degree DEG of one
5556 argument, its derivative (with respect to its argument) DF/DX, its
5557 second derivative DDF/DZ^2, initial complex value Z0, and positive
5558 real number PREC, returns a complex number Z for which
5559 `magnitude'(F(Z)) is less than PREC; or returns `#f' if such a
5560 number can't be found.
5562 If PREC is instead a negative integer,
5563 `laguerre:find-polynomial-root' returns the result of -PREC
5566 - Function: secant:find-root f x0 x1 prec
5567 - Function: secant:find-bracketed-root f x0 x1 prec
5568 Given a real valued procedure F and two real valued starting
5569 points X0 and X1, returns a real X for which `(abs (f x))' is less
5570 than PREC; or returns `#f' if such a real can't be found.
5572 If X0 and X1 are chosen such that they bracket a root, that is
5573 (or (< (f x0) 0 (f x1))
5574 (< (f x1) 0 (f x0)))
5575 then the root returned will be between X0 and X1, and F will not
5576 be passed an argument outside of that interval.
5578 `secant:find-bracketed-root' will return `#f' unless X0 and X1
5581 The secant method is used until a bracketing interval is found, at
5582 which point a modified regula falsi method is used.
5584 If PREC is instead a negative integer, `secant:find-root' returns
5585 the result of -PREC iterations.
5587 If PREC is a procedure it should accept 5 arguments: X0 F0 X1 F1
5588 and COUNT, where F0 will be `(f x0)', F1 `(f x1)', and COUNT the
5589 number of iterations performed so far. PREC should return
5590 non-false if the iteration should be stopped.
5593 File: slib.info, Node: Minimizing, Next: Commutative Rings, Prev: Root Finding, Up: Mathematical Packages
5598 `(require 'minimize)'
5600 The Golden Section Search (1) algorithm finds minima of functions which
5601 are expensive to compute or for which derivatives are not available.
5602 Although optimum for the general case, convergence is slow, requiring
5603 nearly 100 iterations for the example (x^3-2x-5).
5605 If the derivative is available, Newton-Raphson is probably a better
5606 choice. If the function is inexpensive to compute, consider
5607 approximating the derivative.
5609 - Function: golden-section-search f x0 x1 prec
5610 X_0 are X_1 real numbers. The (single argument) procedure F is
5611 unimodal over the open interval (X_0, X_1). That is, there is
5612 exactly one point in the interval for which the derivative of F is
5615 `golden-section-search' returns a pair (X . F(X)) where F(X) is
5616 the minimum. The PREC parameter is the stop criterion. If PREC
5617 is a positive number, then the iteration continues until X is
5618 within PREC from the true value. If PREC is a negative integer,
5619 then the procedure will iterate -PREC times or until convergence.
5620 If PREC is a procedure of seven arguments, X0, X1, A, B, FA, FB,
5621 and COUNT, then the iterations will stop when the procedure
5624 Analytically, the minimum of x^3-2x-5 is 0.816497.
5625 (define func (lambda (x) (+ (* x (+ (* x x) -2)) -5)))
5626 (golden-section-search func 0 1 (/ 10000))
5627 ==> (816.4883855245578e-3 . -6.0886621077391165)
5628 (golden-section-search func 0 1 -5)
5629 ==> (819.6601125010515e-3 . -6.088637561916407)
5630 (golden-section-search func 0 1
5631 (lambda (a b c d e f g ) (= g 500)))
5632 ==> (816.4965933140557e-3 . -6.088662107903635)
5634 ---------- Footnotes ----------
5636 (1) David Kahaner, Cleve Moler, and Stephen Nash `Numerical Methods
5637 and Software' Prentice-Hall, 1989, ISBN 0-13-627258-4
5640 File: slib.info, Node: Commutative Rings, Next: Determinant, Prev: Minimizing, Up: Mathematical Packages
5645 Scheme provides a consistent and capable set of numeric functions.
5646 Inexacts implement a field; integers a commutative ring (and Euclidean
5647 domain). This package allows one to use basic Scheme numeric functions
5648 with symbols and non-numeric elements of commutative rings.
5650 `(require 'commutative-ring)'
5652 The "commutative-ring" package makes the procedures `+', `-', `*',
5653 `/', and `^' "careful" in the sense that any non-numeric arguments they
5654 do not reduce appear in the expression output. In order to see what
5655 working with this package is like, self-set all the single letter
5656 identifiers (to their corresponding symbols).
5662 Or just `(require 'self-set)'. Now try some sample expressions:
5664 (+ (+ a b) (- a b)) => (* a 2)
5665 (* (+ a b) (+ a b)) => (^ (+ a b) 2)
5666 (* (+ a b) (- a b)) => (* (+ a b) (- a b))
5667 (* (- a b) (- a b)) => (^ (- a b) 2)
5668 (* (- a b) (+ a b)) => (* (+ a b) (- a b))
5669 (/ (+ a b) (+ c d)) => (/ (+ a b) (+ c d))
5670 (^ (+ a b) 3) => (^ (+ a b) 3)
5671 (^ (+ a 2) 3) => (^ (+ 2 a) 3)
5673 Associative rules have been applied and repeated addition and
5674 multiplication converted to multiplication and exponentiation.
5676 We can enable distributive rules, thus expanding to sum of products
5678 (set! *ruleset* (combined-rulesets distribute* distribute/))
5680 (* (+ a b) (+ a b)) => (+ (* 2 a b) (^ a 2) (^ b 2))
5681 (* (+ a b) (- a b)) => (- (^ a 2) (^ b 2))
5682 (* (- a b) (- a b)) => (- (+ (^ a 2) (^ b 2)) (* 2 a b))
5683 (* (- a b) (+ a b)) => (- (^ a 2) (^ b 2))
5684 (/ (+ a b) (+ c d)) => (+ (/ a (+ c d)) (/ b (+ c d)))
5685 (/ (+ a b) (- c d)) => (+ (/ a (- c d)) (/ b (- c d)))
5686 (/ (- a b) (- c d)) => (- (/ a (- c d)) (/ b (- c d)))
5687 (/ (- a b) (+ c d)) => (- (/ a (+ c d)) (/ b (+ c d)))
5688 (^ (+ a b) 3) => (+ (* 3 a (^ b 2)) (* 3 b (^ a 2)) (^ a 3) (^ b 3))
5689 (^ (+ a 2) 3) => (+ 8 (* a 12) (* (^ a 2) 6) (^ a 3))
5691 Use of this package is not restricted to simple arithmetic
5694 (require 'determinant)
5696 (determinant '((a b c) (d e f) (g h i))) =>
5697 (- (+ (* a e i) (* b f g) (* c d h)) (* a f h) (* b d i) (* c e g))
5699 Currently, only `+', `-', `*', `/', and `^' support non-numeric
5700 elements. Expressions with `-' are converted to equivalent expressions
5701 without `-', so behavior for `-' is not defined separately. `/'
5702 expressions are handled similarly.
5704 This list might be extended to include `quotient', `modulo',
5705 `remainder', `lcm', and `gcd'; but these work only for the more
5706 restrictive Euclidean (Unique Factorization) Domain.
5711 The "commutative-ring" package allows control of ring properties
5712 through the use of "rulesets".
5714 - Variable: *ruleset*
5715 Contains the set of rules currently in effect. Rules defined by
5716 `cring:define-rule' are stored within the value of *ruleset* at the
5717 time `cring:define-rule' is called. If *RULESET* is `#f', then no
5720 - Function: make-ruleset rule1 ...
5721 - Function: make-ruleset name rule1 ...
5722 Returns a new ruleset containing the rules formed by applying
5723 `cring:define-rule' to each 4-element list argument RULE. If the
5724 first argument to `make-ruleset' is a symbol, then the database
5725 table created for the new ruleset will be named NAME. Calling
5726 `make-ruleset' with no rule arguments creates an empty ruleset.
5728 - Function: combined-rulesets ruleset1 ...
5729 - Function: combined-rulesets name ruleset1 ...
5730 Returns a new ruleset containing the rules contained in each
5731 ruleset argument RULESET. If the first argument to
5732 `combined-ruleset' is a symbol, then the database table created for
5733 the new ruleset will be named NAME. Calling `combined-ruleset'
5734 with no ruleset arguments creates an empty ruleset.
5736 Two rulesets are defined by this package.
5738 - Constant: distribute*
5739 Contain the ruleset to distribute multiplication over addition and
5742 - Constant: distribute/
5743 Contain the ruleset to distribute division over addition and
5746 Take care when using both DISTRIBUTE* and DISTRIBUTE/
5747 simultaneously. It is possible to put `/' into an infinite loop.
5749 You can specify how sum and product expressions containing non-numeric
5750 elements simplify by specifying the rules for `+' or `*' for cases
5751 where expressions involving objects reduce to numbers or to expressions
5752 involving different non-numeric elements.
5754 - Function: cring:define-rule op sub-op1 sub-op2 reduction
5755 Defines a rule for the case when the operation represented by
5756 symbol OP is applied to lists whose `car's are SUB-OP1 and
5757 SUB-OP2, respectively. The argument REDUCTION is a procedure
5758 accepting 2 arguments which will be lists whose `car's are SUB-OP1
5761 - Function: cring:define-rule op sub-op1 'identity reduction
5762 Defines a rule for the case when the operation represented by
5763 symbol OP is applied to a list whose `car' is SUB-OP1, and some
5764 other argument. REDUCTION will be called with the list whose
5765 `car' is SUB-OP1 and some other argument.
5767 If REDUCTION returns `#f', the reduction has failed and other
5768 reductions will be tried. If REDUCTION returns a non-false value,
5769 that value will replace the two arguments in arithmetic (`+', `-',
5770 and `*') calculations involving non-numeric elements.
5772 The operations `+' and `*' are assumed commutative; hence both
5773 orders of arguments to REDUCTION will be tried if necessary.
5775 The following rule is the definition for distributing `*' over `+'.
5780 (apply + (map (lambda (trm) (* trm exp2)) (cdr exp1))))))
5782 How to Create a Commutative Ring
5783 ================================
5785 The first step in creating your commutative ring is to write
5786 procedures to create elements of the ring. A non-numeric element of
5787 the ring must be represented as a list whose first element is a symbol
5788 or string. This first element identifies the type of the object. A
5789 convenient and clear convention is to make the type-identifying element
5790 be the same symbol whose top-level value is the procedure to create it.
5793 (cond ((and (= 2 (length list1))
5794 (eq? (car list1) (cadr list1)))
5796 ((not (term< (first list1) (last1 list1)))
5797 (apply n (reverse list1)))
5798 (else (cons 'n list1))))
5800 (define (s x y) (n x y))
5803 (cond ((neq? (first list1) (term_min list1))
5804 (apply m (cyclicrotate list1)))
5805 ((term< (last1 list1) (cadr list1))
5806 (apply m (reverse (cyclicrotate list1))))
5807 (else (cons 'm list1))))
5809 Define a procedure to multiply 2 non-numeric elements of the ring.
5810 Other multiplicatons are handled automatically. Objects for which rules
5811 have _not_ been defined are not changed.
5814 (let ((list1 (cdr ni)) (list2 (cdr nj)))
5815 (cond ((null? (intersection list1 list2)) #f)
5816 ((and (eq? (last1 list1) (first list2))
5817 (neq? (first list1) (last1 list2)))
5818 (apply n (splice list1 list2)))
5819 ((and (eq? (first list1) (first list2))
5820 (neq? (last1 list1) (last1 list2)))
5821 (apply n (splice (reverse list1) list2)))
5822 ((and (eq? (last1 list1) (last1 list2))
5823 (neq? (first list1) (first list2)))
5824 (apply n (splice list1 (reverse list2))))
5825 ((and (eq? (last1 list1) (first list2))
5826 (eq? (first list1) (last1 list2)))
5827 (apply m (cyclicsplice list1 list2)))
5828 ((and (eq? (first list1) (first list2))
5829 (eq? (last1 list1) (last1 list2)))
5830 (apply m (cyclicsplice (reverse list1) list2)))
5833 Test the procedures to see if they work.
5835 ;;; where cyclicrotate(list) is cyclic rotation of the list one step
5836 ;;; by putting the first element at the end
5837 (define (cyclicrotate list1)
5838 (append (rest list1) (list (first list1))))
5839 ;;; and where term_min(list) is the element of the list which is
5840 ;;; first in the term ordering.
5841 (define (term_min list1)
5842 (car (sort list1 term<)))
5843 (define (term< sym1 sym2)
5844 (string<? (symbol->string sym1) (symbol->string sym2)))
5847 (define (last1 list1) (car (last-pair list1)))
5848 (define (neq? obj1 obj2) (not (eq? obj1 obj2)))
5849 ;;; where splice is the concatenation of list1 and list2 except that their
5850 ;;; common element is not repeated.
5851 (define (splice list1 list2)
5852 (cond ((eq? (last1 list1) (first list2))
5853 (append list1 (cdr list2)))
5854 (else (error 'splice list1 list2))))
5855 ;;; where cyclicsplice is the result of leaving off the last element of
5856 ;;; splice(list1,list2).
5857 (define (cyclicsplice list1 list2)
5858 (cond ((and (eq? (last1 list1) (first list2))
5859 (eq? (first list1) (last1 list2)))
5860 (butlast (splice list1 list2) 1))
5861 (else (error 'cyclicsplice list1 list2))))
5863 (N*N (S a b) (S a b)) => (m a b)
5865 Then register the rule for multiplying type N objects by type N
5868 (cring:define-rule '* 'N 'N N*N))
5870 Now we are ready to compute!
5876 (- (* (S a f) (S d g)) (* (S a g) (S d f))))
5878 (- (* (S a g) (S d d)) (* (S a d) (S d g))))
5880 (- (* (S a d) (S d f)) (* (S a f) (S d d))))))
5883 (- (* (S a g) (S d f)) (* (S a f) (S d g))))
5885 (- (* (S a b) (S d g)) (* (S a g) (S d b))))
5887 (- (* (S a f) (S d b)) (* (S a b) (S d f))))))
5890 (- (* (S a d) (S d g)) (* (S a g) (S d d))))
5892 (- (* (S a g) (S d b)) (* (S a b) (S d g))))
5894 (- (* (S a b) (S d d)) (* (S a d) (S d b))))))
5897 (- (* (S a f) (S d d)) (* (S a d) (S d f))))
5899 (- (* (S a b) (S d f)) (* (S a f) (S d b))))
5901 (- (* (S a d) (S d b)) (* (S a b) (S d d))))))))
5902 (* (S b e) (S c a) (S e c)
5907 (- (+ (m a c e b d f g)
5913 (* 2 (m a b e c) (m d f g))
5914 (* (m a c e b d) (m f g))
5915 (* (m a c e b f) (m d g))
5916 (* (m a c e b g) (m d f)))
5919 File: slib.info, Node: Determinant, Prev: Commutative Rings, Up: Mathematical Packages
5924 - Function: determinant square-matrix |
5925 Returns the determinant of SQUARE-MATRIX. |
5927 (require 'determinant)
5928 (determinant '((1 2) (3 4))) => -2
5929 (determinant '((1 2 3) (4 5 6) (7 8 9))) => 0
5930 (determinant '((1 2 3 4) (5 6 7 8) (9 10 11 12))) => 0
5933 File: slib.info, Node: Database Packages, Next: Other Packages, Prev: Mathematical Packages, Up: Top
5941 * Relational Database:: 'relational-database
5942 * Weight-Balanced Trees:: 'wt-tree
5945 File: slib.info, Node: Base Table, Next: Relational Database, Prev: Database Packages, Up: Database Packages
5950 A base table implementation using Scheme association lists is
5951 available as the value of the identifier `alist-table' after doing:
5953 `(require 'alist-table)'
5955 Association list base tables are suitable for small databases and
5956 support all Scheme types when temporary and readable/writeable Scheme
5957 types when saved. I hope support for other base table implementations
5958 will be added in the future.
5960 This rest of this section documents the interface for a base table
5961 implementation from which the *Note Relational Database:: package
5962 constructs a Relational system. It will be of interest primarily to
5963 those wishing to port or write new base-table implementations.
5965 All of these functions are accessed through a single procedure by
5966 calling that procedure with the symbol name of the operation. A
5967 procedure will be returned if that operation is supported and `#f'
5968 otherwise. For example:
5970 (require 'alist-table)
5971 (define open-base (alist-table 'make-base))
5972 make-base => *a procedure*
5973 (define foo (alist-table 'foo))
5976 - Function: make-base filename key-dimension column-types
5977 Returns a new, open, low-level database (collection of tables)
5978 associated with FILENAME. This returned database has an empty
5979 table associated with CATALOG-ID. The positive integer
5980 KEY-DIMENSION is the number of keys composed to make a PRIMARY-KEY
5981 for the catalog table. The list of symbols COLUMN-TYPES describes
5982 the types of each column for that table. If the database cannot
5983 be created as specified, `#f' is returned.
5985 Calling the `close-base' method on this database and possibly other
5986 operations will cause FILENAME to be written to. If FILENAME is
5987 `#f' a temporary, non-disk based database will be created if such
5988 can be supported by the base table implelentation.
5990 - Function: open-base filename mutable
5991 Returns an open low-level database associated with FILENAME. If
5992 MUTABLE? is `#t', this database will have methods capable of
5993 effecting change to the database. If MUTABLE? is `#f', only
5994 methods for inquiring the database will be available. If the
5995 database cannot be opened as specified `#f' is returned.
5997 Calling the `close-base' (and possibly other) method on a MUTABLE?
5998 database will cause FILENAME to be written to.
6000 - Function: write-base lldb filename
6001 Causes the low-level database LLDB to be written to FILENAME. If
6002 the write is successful, also causes LLDB to henceforth be
6003 associated with FILENAME. Calling the `close-database' (and
6004 possibly other) method on LLDB may cause FILENAME to be written
6005 to. If FILENAME is `#f' this database will be changed to a
6006 temporary, non-disk based database if such can be supported by the
6007 underlying base table implelentation. If the operations completed
6008 successfully, `#t' is returned. Otherwise, `#f' is returned.
6010 - Function: sync-base lldb
6011 Causes the file associated with the low-level database LLDB to be
6012 updated to reflect its current state. If the associated filename
6013 is `#f', no action is taken and `#f' is returned. If this
6014 operation completes successfully, `#t' is returned. Otherwise,
6017 - Function: close-base lldb
6018 Causes the low-level database LLDB to be written to its associated
6019 file (if any). If the write is successful, subsequent operations
6020 to LLDB will signal an error. If the operations complete
6021 successfully, `#t' is returned. Otherwise, `#f' is returned.
6023 - Function: make-table lldb key-dimension column-types
6024 Returns the BASE-ID for a new base table, otherwise returns `#f'.
6025 The base table can then be opened using `(open-table LLDB
6026 BASE-ID)'. The positive integer KEY-DIMENSION is the number of
6027 keys composed to make a PRIMARY-KEY for this table. The list of
6028 symbols COLUMN-TYPES describes the types of each column.
6030 - Constant: catalog-id
6031 A constant BASE-ID suitable for passing as a parameter to
6032 `open-table'. CATALOG-ID will be used as the base table for the
6035 - Function: open-table lldb base-id key-dimension column-types
6036 Returns a HANDLE for an existing base table in the low-level
6037 database LLDB if that table exists and can be opened in the mode
6038 indicated by MUTABLE?, otherwise returns `#f'.
6040 As with `make-table', the positive integer KEY-DIMENSION is the
6041 number of keys composed to make a PRIMARY-KEY for this table. The
6042 list of symbols COLUMN-TYPES describes the types of each column.
6044 - Function: kill-table lldb base-id key-dimension column-types
6045 Returns `#t' if the base table associated with BASE-ID was removed
6046 from the low level database LLDB, and `#f' otherwise.
6048 - Function: make-keyifier-1 type
6049 Returns a procedure which accepts a single argument which must be
6050 of type TYPE. This returned procedure returns an object suitable
6051 for being a KEY argument in the functions whose descriptions
6054 Any 2 arguments of the supported type passed to the returned
6055 function which are not `equal?' must result in returned values
6056 which are not `equal?'.
6058 - Function: make-list-keyifier key-dimension types
6059 The list of symbols TYPES must have at least KEY-DIMENSION
6060 elements. Returns a procedure which accepts a list of length
6061 KEY-DIMENSION and whose types must corresopond to the types named
6062 by TYPES. This returned procedure combines the elements of its
6063 list argument into an object suitable for being a KEY argument in
6064 the functions whose descriptions follow.
6066 Any 2 lists of supported types (which must at least include
6067 symbols and non-negative integers) passed to the returned function
6068 which are not `equal?' must result in returned values which are not
6071 - Function: make-key-extractor key-dimension types column-number
6072 Returns a procedure which accepts objects produced by application
6073 of the result of `(make-list-keyifier KEY-DIMENSION TYPES)'. This
6074 procedure returns a KEY which is `equal?' to the COLUMN-NUMBERth
6075 element of the list which was passed to create COMBINED-KEY. The
6076 list TYPES must have at least KEY-DIMENSION elements.
6078 - Function: make-key->list key-dimension types
6079 Returns a procedure which accepts objects produced by application
6080 of the result of `(make-list-keyifier KEY-DIMENSION TYPES)'. This
6081 procedure returns a list of KEYs which are elementwise `equal?' to
6082 the list which was passed to create COMBINED-KEY.
6084 In the following functions, the KEY argument can always be assumed to
6085 be the value returned by a call to a _keyify_ routine.
6087 In contrast, a MATCH-KEYS argument is a list of length equal to the
6088 number of primary keys. The MATCH-KEYS restrict the actions of the
6089 table command to those records whose primary keys all satisfy the
6090 corresponding element of the MATCH-KEYS list. The elements and their
6094 The false value matches any key in the corresponding position.
6096 an object of type procedure
6097 This procedure must take a single argument, the key in the
6098 corresponding position. Any key for which the procedure
6099 returns a non-false value is a match; Any key for which the
6100 procedure returns a `#f' is not.
6103 Any other value matches only those keys `equal?' to it.
6105 The KEY-DIMENSION and COLUMN-TYPES arguments are needed to decode the
6106 combined-keys for matching with MATCH-KEYS.
6108 - Function: for-each-key handle procedure key-dimension column-types
6110 Calls PROCEDURE once with each KEY in the table opened in HANDLE
6111 which satisfy MATCH-KEYS in an unspecified order. An unspecified
6114 - Function: map-key handle procedure key-dimension column-types
6116 Returns a list of the values returned by calling PROCEDURE once
6117 with each KEY in the table opened in HANDLE which satisfy
6118 MATCH-KEYS in an unspecified order.
6120 - Function: ordered-for-each-key handle procedure key-dimension
6121 column-types match-keys
6122 Calls PROCEDURE once with each KEY in the table opened in HANDLE
6123 which satisfy MATCH-KEYS in the natural order for the types of the
6124 primary key fields of that table. An unspecified value is
6127 - Function: delete* handle key-dimension column-types match-keys
6128 Removes all rows which satisfy MATCH-KEYS from the table opened in
6129 HANDLE. An unspecified value is returned.
6131 - Function: present? handle key
6132 Returns a non-`#f' value if there is a row associated with KEY in
6133 the table opened in HANDLE and `#f' otherwise.
6135 - Function: delete handle key
6136 Removes the row associated with KEY from the table opened in
6137 HANDLE. An unspecified value is returned.
6139 - Function: make-getter key-dimension types
6140 Returns a procedure which takes arguments HANDLE and KEY. This
6141 procedure returns a list of the non-primary values of the relation
6142 (in the base table opened in HANDLE) whose primary key is KEY if
6143 it exists, and `#f' otherwise.
6145 - Function: make-putter key-dimension types
6146 Returns a procedure which takes arguments HANDLE and KEY and
6147 VALUE-LIST. This procedure associates the primary key KEY with
6148 the values in VALUE-LIST (in the base table opened in HANDLE) and
6149 returns an unspecified value.
6151 - Function: supported-type? symbol
6152 Returns `#t' if SYMBOL names a type allowed as a column value by
6153 the implementation, and `#f' otherwise. At a minimum, an
6154 implementation must support the types `integer', `symbol',
6155 `string', `boolean', and `base-id'.
6157 - Function: supported-key-type? symbol
6158 Returns `#t' if SYMBOL names a type allowed as a key value by the
6159 implementation, and `#f' otherwise. At a minimum, an
6160 implementation must support the types `integer', and `symbol'.
6163 Scheme exact integer.
6172 Objects suitable for passing as the BASE-ID parameter to
6173 `open-table'. The value of CATALOG-ID must be an acceptable
6177 File: slib.info, Node: Relational Database, Next: Weight-Balanced Trees, Prev: Base Table, Up: Database Packages
6182 `(require 'relational-database)'
6184 This package implements a database system inspired by the Relational
6185 Model (`E. F. Codd, A Relational Model of Data for Large Shared Data
6186 Banks'). An SLIB relational database implementation can be created
6187 from any *Note Base Table:: implementation.
6191 * Motivations:: Database Manifesto
6192 * Creating and Opening Relational Databases::
6193 * Relational Database Operations::
6194 * Table Operations::
6195 * Catalog Representation::
6196 * Unresolved Issues::
6197 * Database Utilities:: 'database-utilities
6198 * Database Reports::
6199 * Database Browser:: 'database-browse
6202 File: slib.info, Node: Motivations, Next: Creating and Opening Relational Databases, Prev: Relational Database, Up: Relational Database
6207 Most nontrivial programs contain databases: Makefiles, configure
6208 scripts, file backup, calendars, editors, source revision control, CAD
6209 systems, display managers, menu GUIs, games, parsers, debuggers,
6210 profilers, and even error reporting are all rife with databases. Coding
6211 databases is such a common activity in programming that many may not be
6212 aware of how often they do it.
6214 A database often starts as a dispatch in a program. The author,
6215 perhaps because of the need to make the dispatch configurable, the need
6216 for correlating dispatch in other routines, or because of changes or
6217 growth, devises a data structure to contain the information, a routine
6218 for interpreting that data structure, and perhaps routines for
6219 augmenting and modifying the stored data. The dispatch must be
6220 converted into this form and tested.
6222 The programmer may need to devise an interactive program for enabling
6223 easy examination and modification of the information contained in this
6224 database. Often, in an attempt to foster modularity and avoid delays in
6225 release, intermediate file formats for the database information are
6226 devised. It often turns out that users prefer modifying these
6227 intermediate files with a text editor to using the interactive program
6228 in order to do operations (such as global changes) not forseen by the
6231 In order to address this need, the conscientious software engineer may
6232 even provide a scripting language to allow users to make repetitive
6233 database changes. Users will grumble that they need to read a large
6234 manual and learn yet another programming language (even if it _almost_
6235 has language "xyz" syntax) in order to do simple configuration.
6237 All of these facilities need to be designed, coded, debugged,
6238 documented, and supported; often causing what was very simple in concept
6239 to become a major developement project.
6241 This view of databases just outlined is somewhat the reverse of the
6242 view of the originators of the "Relational Model" of database
6243 abstraction. The relational model was devised to unify and allow
6244 interoperation of large multi-user databases running on diverse
6245 platforms. A fairly general purpose "Comprehensive Language" for
6246 database manipulations is mandated (but not specified) as part of the
6247 relational model for databases.
6249 One aspect of the Relational Model of some importance is that the
6250 "Comprehensive Language" must be expressible in some form which can be
6251 stored in the database. This frees the programmer from having to make
6252 programs data-driven in order to use a database.
6254 This package includes as one of its basic supported types Scheme
6255 "expression"s. This type allows expressions as defined by the Scheme
6256 standards to be stored in the database. Using `slib:eval' retrieved
6257 expressions can be evaluated (in the top-level environment). Scheme's
6258 `lambda' facilitates closure of environments, modularity, etc. so that
6259 procedures (which could not be stored directly most databases) can
6260 still be effectively retrieved. Since `slib:eval' evaluates
6261 expressions in the top-level environment, built-in and user defined
6262 procedures can be easily accessed by name.
6264 This package's purpose is to standardize (through a common interface)
6265 database creation and usage in Scheme programs. The relational model's
6266 provision for inclusion of language expressions as data as well as the
6267 description (in tables, of course) of all of its tables assures that
6268 relational databases are powerful enough to assume the roles currently
6269 played by thousands of ad-hoc routines and data formats.
6271 Such standardization to a relational-like model brings many benefits:
6273 * Tables, fields, domains, and types can be dealt with by name in
6276 * The underlying database implementation can be changed (for
6277 performance or other reasons) by changing a single line of code.
6279 * The formats of tables can be easily extended or changed without
6282 * Consistency checks are specified as part of the table descriptions.
6283 Changes in checks need only occur in one place.
6285 * All the configuration information which the developer wishes to
6286 group together is easily grouped, without needing to change
6287 programs aware of only some of these tables.
6289 * Generalized report generators, interactive entry programs, and
6290 other database utilities can be part of a shared library. The
6291 burden of adding configurability to a program is greatly reduced.
6293 * Scheme is the "comprehensive language" for these databases.
6294 Scripting for configuration no longer needs to be in a separate
6295 language with additional documentation.
6297 * Scheme's latent types mesh well with the strict typing and logical
6298 requirements of the relational model.
6300 * Portable formats allow easy interchange of data. The included
6301 table descriptions help prevent misinterpretation of format.
6304 File: slib.info, Node: Creating and Opening Relational Databases, Next: Relational Database Operations, Prev: Motivations, Up: Relational Database
6306 Creating and Opening Relational Databases
6307 -----------------------------------------
6309 - Function: make-relational-system base-table-implementation
6310 Returns a procedure implementing a relational database using the
6311 BASE-TABLE-IMPLEMENTATION.
6313 All of the operations of a base table implementation are accessed
6314 through a procedure defined by `require'ing that implementation.
6315 Similarly, all of the operations of the relational database
6316 implementation are accessed through the procedure returned by
6317 `make-relational-system'. For instance, a new relational database
6318 could be created from the procedure returned by
6319 `make-relational-system' by:
6321 (require 'alist-table)
6322 (define relational-alist-system
6323 (make-relational-system alist-table))
6324 (define create-alist-database
6325 (relational-alist-system 'create-database))
6327 (create-alist-database "mydata.db"))
6329 What follows are the descriptions of the methods available from
6330 relational system returned by a call to `make-relational-system'.
6332 - Function: create-database filename
6333 Returns an open, nearly empty relational database associated with
6334 FILENAME. The only tables defined are the system catalog and
6335 domain table. Calling the `close-database' method on this database
6336 and possibly other operations will cause FILENAME to be written
6337 to. If FILENAME is `#f' a temporary, non-disk based database will
6338 be created if such can be supported by the underlying base table
6339 implelentation. If the database cannot be created as specified
6340 `#f' is returned. For the fields and layout of descriptor tables,
6341 *Note Catalog Representation::
6343 - Function: open-database filename mutable?
6344 Returns an open relational database associated with FILENAME. If
6345 MUTABLE? is `#t', this database will have methods capable of
6346 effecting change to the database. If MUTABLE? is `#f', only
6347 methods for inquiring the database will be available. Calling the
6348 `close-database' (and possibly other) method on a MUTABLE?
6349 database will cause FILENAME to be written to. If the database
6350 cannot be opened as specified `#f' is returned.
6353 File: slib.info, Node: Relational Database Operations, Next: Table Operations, Prev: Creating and Opening Relational Databases, Up: Relational Database
6355 Relational Database Operations
6356 ------------------------------
6358 These are the descriptions of the methods available from an open
6359 relational database. A method is retrieved from a database by calling
6360 the database with the symbol name of the operation. For example:
6363 (create-alist-database "mydata.db"))
6364 (define telephone-table-desc
6365 ((my-database 'create-table) 'telephone-table-desc))
6367 - Function: close-database
6368 Causes the relational database to be written to its associated
6369 file (if any). If the write is successful, subsequent operations
6370 to this database will signal an error. If the operations completed
6371 successfully, `#t' is returned. Otherwise, `#f' is returned.
6373 - Function: write-database filename
6374 Causes the relational database to be written to FILENAME. If the
6375 write is successful, also causes the database to henceforth be
6376 associated with FILENAME. Calling the `close-database' (and
6377 possibly other) method on this database will cause FILENAME to be
6378 written to. If FILENAME is `#f' this database will be changed to
6379 a temporary, non-disk based database if such can be supported by
6380 the underlying base table implelentation. If the operations
6381 completed successfully, `#t' is returned. Otherwise, `#f' is
6384 - Function: sync-database |
6385 Causes any pending updates to the database file to be written out. |
6386 If the operations completed successfully, `#t' is returned. |
6387 Otherwise, `#f' is returned. |
6389 - Function: table-exists? table-name
6390 Returns `#t' if TABLE-NAME exists in the system catalog, otherwise
6393 - Function: open-table table-name mutable?
6394 Returns a "methods" procedure for an existing relational table in
6395 this database if it exists and can be opened in the mode indicated
6396 by MUTABLE?, otherwise returns `#f'.
6398 These methods will be present only in databases which are MUTABLE?.
6400 - Function: delete-table table-name
6401 Removes and returns the TABLE-NAME row from the system catalog if
6402 the table or view associated with TABLE-NAME gets removed from the
6403 database, and `#f' otherwise.
6405 - Function: create-table table-desc-name
6406 Returns a methods procedure for a new (open) relational table for
6407 describing the columns of a new base table in this database,
6408 otherwise returns `#f'. For the fields and layout of descriptor
6409 tables, *Note Catalog Representation::.
6411 - Function: create-table table-name table-desc-name
6412 Returns a methods procedure for a new (open) relational table with
6413 columns as described by TABLE-DESC-NAME, otherwise returns `#f'.
6415 - Function: create-view ??
6416 - Function: project-table ??
6417 - Function: restrict-table ??
6418 - Function: cart-prod-tables ??
6419 Not yet implemented.
6422 File: slib.info, Node: Table Operations, Next: Catalog Representation, Prev: Relational Database Operations, Up: Relational Database
6427 These are the descriptions of the methods available from an open
6428 relational table. A method is retrieved from a table by calling the
6429 table with the symbol name of the operation. For example:
6431 (define telephone-table-desc
6432 ((my-database 'create-table) 'telephone-table-desc))
6433 (require 'common-list-functions)
6434 (define ndrp (telephone-table-desc 'row:insert))
6435 (ndrp '(1 #t name #f string))
6436 (ndrp '(2 #f telephone
6438 (and (string? d) (> (string-length d) 2)
6441 (memv c '(#\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9
6442 #\+ #\( #\ #\) #\-)))
6446 Some operations described below require primary key arguments. Primary
6447 keys arguments are denoted KEY1 KEY2 .... It is an error to call an
6448 operation for a table which takes primary key arguments with the wrong
6449 number of primary keys for that table.
6451 The term "row" used below refers to a Scheme list of values (one for
6452 each column) in the order specified in the descriptor (table) for this
6453 table. Missing values appear as `#f'. Primary keys must not be
6456 - Function: get column-name
6457 Returns a procedure of arguments KEY1 KEY2 ... which returns the
6458 value for the COLUMN-NAME column of the row associated with
6459 primary keys KEY1, KEY2 ... if that row exists in the table, or
6462 ((plat 'get 'processor) 'djgpp) => i386
6463 ((plat 'get 'processor) 'be-os) => #f
6465 - Function: get* column-name
6466 Returns a procedure of optional arguments MATCH-KEY1 ... which
6467 returns a list of the values for the specified column for all rows
6468 in this table. The optional MATCH-KEY1 ... arguments restrict
6469 actions to a subset of the table. See the match-key description
6472 ((plat 'get* 'processor)) =>
6473 (i386 8086 i386 8086 i386 i386 8086 m68000
6474 m68000 m68000 m68000 m68000 powerpc)
6476 ((plat 'get* 'processor) #f) =>
6477 (i386 8086 i386 8086 i386 i386 8086 m68000
6478 m68000 m68000 m68000 m68000 powerpc)
6480 (define (a-key? key)
6481 (char=? #\a (string-ref (symbol->string key) 0)))
6483 ((plat 'get* 'processor) a-key?) =>
6484 (m68000 m68000 m68000 m68000 m68000 powerpc)
6486 ((plat 'get* 'name) a-key?) =>
6487 (atari-st-turbo-c atari-st-gcc amiga-sas/c-5.10
6488 amiga-aztec amiga-dice-c aix)
6490 - Function: row:retrieve
6491 Returns a procedure of arguments KEY1 KEY2 ... which returns the
6492 row associated with primary keys KEY1, KEY2 ... if it exists, or
6495 ((plat 'row:retrieve) 'linux) => (linux i386 linux gcc)
6496 ((plat 'row:retrieve) 'multics) => #f
6498 - Function: row:retrieve*
6499 Returns a procedure of optional arguments MATCH-KEY1 ... which
6500 returns a list of all rows in this table. The optional MATCH-KEY1
6501 ... arguments restrict actions to a subset of the table. See the
6502 match-key description below for details.
6504 ((plat 'row:retrieve*) a-key?) =>
6505 ((atari-st-turbo-c m68000 atari turbo-c)
6506 (atari-st-gcc m68000 atari gcc)
6507 (amiga-sas/c-5.10 m68000 amiga sas/c)
6508 (amiga-aztec m68000 amiga aztec)
6509 (amiga-dice-c m68000 amiga dice-c)
6510 (aix powerpc aix -))
6512 - Function: row:remove
6513 Returns a procedure of arguments KEY1 KEY2 ... which removes and
6514 returns the row associated with primary keys KEY1, KEY2 ... if it
6515 exists, or `#f' otherwise.
6517 - Function: row:remove*
6518 Returns a procedure of optional arguments MATCH-KEY1 ... which
6519 removes and returns a list of all rows in this table. The optional
6520 MATCH-KEY1 ... arguments restrict actions to a subset of the
6521 table. See the match-key description below for details.
6523 - Function: row:delete
6524 Returns a procedure of arguments KEY1 KEY2 ... which deletes the
6525 row associated with primary keys KEY1, KEY2 ... if it exists. The
6526 value returned is unspecified.
6528 - Function: row:delete*
6529 Returns a procedure of optional arguments MATCH-KEY1 ... which
6530 Deletes all rows from this table. The optional MATCH-KEY1 ...
6531 arguments restrict deletions to a subset of the table. See the
6532 match-key description below for details. The value returned is
6533 unspecified. The descriptor table and catalog entry for this
6534 table are not affected.
6536 - Function: row:update
6537 Returns a procedure of one argument, ROW, which adds the row, ROW,
6538 to this table. If a row for the primary key(s) specified by ROW
6539 already exists in this table, it will be overwritten. The value
6540 returned is unspecified.
6542 - Function: row:update*
6543 Returns a procedure of one argument, ROWS, which adds each row in
6544 the list of rows, ROWS, to this table. If a row for the primary
6545 key specified by an element of ROWS already exists in this table,
6546 it will be overwritten. The value returned is unspecified.
6548 - Function: row:insert
6549 Adds the row ROW to this table. If a row for the primary key(s)
6550 specified by ROW already exists in this table an error is
6551 signaled. The value returned is unspecified.
6553 - Function: row:insert*
6554 Returns a procedure of one argument, ROWS, which adds each row in
6555 the list of rows, ROWS, to this table. If a row for the primary
6556 key specified by an element of ROWS already exists in this table,
6557 an error is signaled. The value returned is unspecified.
6559 - Function: for-each-row
6560 Returns a procedure of arguments PROC MATCH-KEY1 ... which calls
6561 PROC with each ROW in this table in the (implementation-dependent)
6562 natural ordering for rows. The optional MATCH-KEY1 ... arguments
6563 restrict actions to a subset of the table. See the match-key
6564 description below for details.
6566 _Real_ relational programmers would use some least-upper-bound join
6567 for every row to get them in order; But we don't have joins yet.
6569 The (optional) MATCH-KEY1 ... arguments are used to restrict actions of
6570 a whole-table operation to a subset of that table. Those procedures
6571 (returned by methods) which accept match-key arguments will accept any
6572 number of match-key arguments between zero and the number of primary
6573 keys in the table. Any unspecified MATCH-KEY arguments default to `#f'.
6575 The MATCH-KEY1 ... restrict the actions of the table command to those
6576 records whose primary keys each satisfy the corresponding MATCH-KEY
6577 argument. The arguments and their actions are:
6580 The false value matches any key in the corresponding position.
6582 an object of type procedure
6583 This procedure must take a single argument, the key in the
6584 corresponding position. Any key for which the procedure
6585 returns a non-false value is a match; Any key for which the
6586 procedure returns a `#f' is not.
6589 Any other value matches only those keys `equal?' to it.
6591 - Function: close-table
6592 Subsequent operations to this table will signal an error.
6594 - Constant: column-names
6595 - Constant: column-foreigns
6596 - Constant: column-domains
6597 - Constant: column-types
6598 Return a list of the column names, foreign-key table names, domain
6599 names, or type names respectively for this table. These 4 methods
6600 are different from the others in that the list is returned, rather
6601 than a procedure to obtain the list.
6603 - Constant: primary-limit
6604 Returns the number of primary keys fields in the relations in this
6608 File: slib.info, Node: Catalog Representation, Next: Unresolved Issues, Prev: Table Operations, Up: Relational Database
6610 Catalog Representation
6611 ----------------------
6613 Each database (in an implementation) has a "system catalog" which
6614 describes all the user accessible tables in that database (including
6617 The system catalog base table has the following fields. `PRI'
6618 indicates a primary key for that table.
6621 column-limit the highest column number
6622 coltab-name descriptor table name
6623 bastab-id data base table identifier
6625 view-procedure A scheme thunk which, when called,
6626 produces a handle for the view. coltab
6627 and bastab are specified if and only if
6628 view-procedure is not.
6630 Descriptors for base tables (not views) are tables (pointed to by
6631 system catalog). Descriptor (base) tables have the fields:
6633 PRI column-number sequential integers from 1
6634 primary-key? boolean TRUE for primary key components
6636 column-integrity-rule
6639 A "primary key" is any column marked as `primary-key?' in the
6640 corresponding descriptor table. All the `primary-key?' columns must
6641 have lower column numbers than any non-`primary-key?' columns. Every
6642 table must have at least one primary key. Primary keys must be
6643 sufficient to distinguish all rows from each other in the table. All of
6644 the system defined tables have a single primary key.
6646 This package currently supports tables having from 1 to 4 primary keys
6647 if there are non-primary columns, and any (natural) number if _all_
6648 columns are primary keys. If you need more than 4 primary keys, I would
6649 like to hear what you are doing!
6651 A "domain" is a category describing the allowable values to occur in a
6652 column. It is described by a (base) table with the fields:
6656 domain-integrity-rule
6660 The "type-id" field value is a symbol. This symbol may be used by the
6661 underlying base table implementation in storing that field.
6663 If the `foreign-table' field is non-`#f' then that field names a table
6664 from the catalog. The values for that domain must match a primary key
6665 of the table referenced by the TYPE-PARAM (or `#f', if allowed). This
6666 package currently does not support composite foreign-keys.
6668 The types for which support is planned are:
6677 foreign-key <table-name>
6679 virtual <expression>
6682 File: slib.info, Node: Unresolved Issues, Next: Database Utilities, Prev: Catalog Representation, Up: Relational Database
6687 Although `rdms.scm' is not large, I found it very difficult to write
6688 (six rewrites). I am not aware of any other examples of a generalized
6689 relational system (although there is little new in CS). I left out
6690 several aspects of the Relational model in order to simplify the job.
6691 The major features lacking (which might be addressed portably) are
6692 views, transaction boundaries, and protection.
6694 Protection needs a model for specifying priveledges. Given how
6695 operations are accessed from handles it should not be difficult to
6696 restrict table accesses to those allowed for that user.
6698 The system catalog has a field called `view-procedure'. This should
6699 allow a purely functional implementation of views. This will work but
6700 is unsatisfying for views resulting from a "select"ion (subset of
6701 rows); for whole table operations it will not be possible to reduce the
6702 number of keys scanned over when the selection is specified only by an
6705 Transaction boundaries present the most intriguing area. Transaction
6706 boundaries are actually a feature of the "Comprehensive Language" of the
6707 Relational database and not of the database. Scheme would seem to
6708 provide the opportunity for an extremely clean semantics for transaction
6709 boundaries since the builtin procedures with side effects are small in
6710 number and easily identified.
6712 These side-effect builtin procedures might all be portably redefined
6713 to versions which properly handled transactions. Compiled library
6714 routines would need to be recompiled as well. Many system extensions
6715 (delete-file, system, etc.) would also need to be redefined.
6717 There are 2 scope issues that must be resolved for multiprocess
6718 transaction boundaries:
6721 The actions captured by a transaction should be only for the
6722 process which invoked the start of transaction. Although standard
6723 Scheme does not provide process primitives as such, `dynamic-wind'
6724 would provide a workable hook into process switching for many
6727 Shared utilities with state
6728 Some shared utilities have state which should _not_ be part of a
6729 transaction. An example would be calling a pseudo-random number
6730 generator. If the success of a transaction depended on the
6731 pseudo-random number and failed, the state of the generator would
6732 be set back. Subsequent calls would keep returning the same
6733 number and keep failing.
6735 Pseudo-random number generators are not reentrant; thus they would
6736 require locks in order to operate properly in a multiprocess
6737 environment. Are all examples of utilities whose state should not
6738 be part of transactions also non-reentrant? If so, perhaps
6739 suspending transaction capture for the duration of locks would
6743 File: slib.info, Node: Database Utilities, Next: Database Reports, Prev: Unresolved Issues, Up: Relational Database
6748 `(require 'database-utilities)'
6750 This enhancement wraps a utility layer on `relational-database' which
6752 * Automatic loading of the appropriate base-table package when
6755 * Automatic execution of initialization commands stored in database.
6757 * Transparent execution of database commands stored in `*commands*'
6760 Also included are utilities which provide:
6761 * Data definition from Scheme lists and
6765 for any SLIB relational database.
6767 - Function: create-database filename base-table-type
6768 Returns an open, nearly empty enhanced (with `*commands*' table)
6769 relational database (with base-table type BASE-TABLE-TYPE)
6770 associated with FILENAME.
6772 - Function: open-database filename
6773 - Function: open-database filename base-table-type
6774 Returns an open enchanced relational database associated with
6775 FILENAME. The database will be opened with base-table type
6776 BASE-TABLE-TYPE) if supplied. If BASE-TABLE-TYPE is not supplied,
6777 `open-database' will attempt to deduce the correct
6778 base-table-type. If the database can not be opened or if it lacks
6779 the `*commands*' table, `#f' is returned.
6781 - Function: open-database! filename
6782 - Function: open-database! filename base-table-type
6783 Returns _mutable_ open enchanced relational database ...
6785 The table `*commands*' in an "enhanced" relational-database has the
6786 fields (with domains):
6788 parameters parameter-list
6789 procedure expression
6790 documentation string
6792 The `parameters' field is a foreign key (domain `parameter-list') of
6793 the `*catalog-data*' table and should have the value of a table
6794 described by `*parameter-columns*'. This `parameter-list' table
6795 describes the arguments suitable for passing to the associated command.
6796 The intent of this table is to be of a form such that different
6797 user-interfaces (for instance, pull-down menus or plain-text queries)
6798 can operate from the same table. A `parameter-list' table has the
6802 arity parameter-arity
6804 defaulter expression
6806 documentation string
6808 The `arity' field can take the values:
6811 Requires a single parameter of the specified domain.
6814 A single parameter of the specified domain or zero parameters is
6818 A single boolean parameter or zero parameters (in which case `#f'
6819 is substituted) is acceptable.
6822 Any number of parameters of the specified domain are acceptable.
6823 The argument passed to the command function is always a list of the
6827 One or more of parameters of the specified domain are acceptable.
6828 The argument passed to the command function is always a list of the
6831 The `domain' field specifies the domain which a parameter or
6832 parameters in the `index'th field must satisfy.
6834 The `defaulter' field is an expression whose value is either `#f' or
6835 a procedure of one argument (the parameter-list) which returns a _list_
6836 of the default value or values as appropriate. Note that since the
6837 `defaulter' procedure is called every time a default parameter is
6838 needed for this column, "sticky" defaults can be implemented using
6839 shared state with the domain-integrity-rule.
6844 When an enhanced relational-database is called with a symbol which
6845 matches a NAME in the `*commands*' table, the associated procedure
6846 expression is evaluated and applied to the enhanced
6847 relational-database. A procedure should then be returned which the user
6848 can invoke on (optional) arguments.
6850 The command `*initialize*' is special. If present in the
6851 `*commands*' table, `open-database' or `open-database!' will return the
6852 value of the `*initialize*' command. Notice that arbitrary code can be
6853 run when the `*initialize*' procedure is automatically applied to the
6854 enhanced relational-database.
6856 Note also that if you wish to shadow or hide from the user
6857 relational-database methods described in *Note Relational Database
6858 Operations::, this can be done by a dispatch in the closure returned by
6859 the `*initialize*' expression rather than by entries in the
6860 `*commands*' table if it is desired that the underlying methods remain
6861 accessible to code in the `*commands*' table.
6863 - Function: make-command-server rdb table-name
6864 Returns a procedure of 2 arguments, a (symbol) command and a
6865 call-back procedure. When this returned procedure is called, it
6866 looks up COMMAND in table TABLE-NAME and calls the call-back
6867 procedure with arguments:
6872 The result of evaluating the expression in the PROCEDURE
6873 field of TABLE-NAME and calling it with RDB.
6876 A list of the "official" name of each parameter. Corresponds
6877 to the `name' field of the COMMAND's parameter-table.
6880 A list of the positive integer index of each parameter.
6881 Corresponds to the `index' field of the COMMAND's
6885 A list of the arities of each parameter. Corresponds to the
6886 `arity' field of the COMMAND's parameter-table. For a
6887 description of `arity' see table above.
6890 A list of the type name of each parameter. Correspnds to the
6891 `type-id' field of the contents of the `domain' of the
6892 COMMAND's parameter-table.
6895 A list of the defaulters for each parameter. Corresponds to
6896 the `defaulters' field of the COMMAND's parameter-table.
6898 DOMAIN-INTEGRITY-RULES
6899 A list of procedures (one for each parameter) which tests
6900 whether a value for a parameter is acceptable for that
6901 parameter. The procedure should be called with each datum in
6902 the list for `nary' arity parameters.
6905 A list of lists of `(alias parameter-name)'. There can be
6906 more than one alias per PARAMETER-NAME.
6908 For information about parameters, *Note Parameter lists::. Here is an
6909 example of setting up a command with arguments and parsing those
6910 arguments from a `getopt' style argument list (*note Getopt::).
6912 (require 'database-utilities)
6913 (require 'fluid-let)
6914 (require 'parameters)
6917 (define my-rdb (create-database #f 'alist-table))
6919 (define-tables my-rdb
6923 ((1 single-string single string
6924 (lambda (pl) '("str")) #f "single string")
6925 (2 nary-symbols nary symbol
6926 (lambda (pl) '()) #f "zero or more symbols")
6927 (3 nary1-symbols nary1 symbol
6928 (lambda (pl) '(symb)) #f "one or more symbols")
6929 (4 optional-number optional uint
6930 (lambda (pl) '()) #f "zero or one number")
6931 (5 flag boolean boolean
6932 (lambda (pl) '(#f)) #f "a boolean flag")))
6935 ((parameter-index uint))
6943 ("optional-number" 4)
6948 ((parameters parameter-list)
6949 (parameter-names parameter-name-translation)
6950 (procedure expression)
6951 (documentation string))
6955 (lambda (rdb) (lambda args (print args)))
6956 "test command arguments"))))
6958 (define (dbutil:serve-command-line rdb command-table
6960 (set! argv (if (vector? argv) (vector->list argv) argv))
6961 ((make-command-server rdb command-table)
6963 (lambda (comname comval options positions
6964 arities types defaulters dirs aliases)
6965 (apply comval (getopt->arglist
6966 argc argv options positions
6967 arities types defaulters dirs aliases)))))
6969 (define (cmd . opts)
6970 (fluid-let ((*optind* 1))
6972 (call-with-output-string
6973 (lambda (pt) (write (cons 'cmd opts) pt))))
6974 (set! opts (cons "cmd" opts))
6976 (dbutil:serve-command-line
6977 my-rdb 'my-commands 'foo (length opts) opts)))
6979 (cmd) => ("str" () (symb) () #f)
6980 (cmd "-f") => ("str" () (symb) () #t)
6981 (cmd "--flag") => ("str" () (symb) () #t)
6982 (cmd "-o177") => ("str" () (symb) (177) #f)
6983 (cmd "-o" "177") => ("str" () (symb) (177) #f)
6984 (cmd "--optional" "621") => ("str" () (symb) (621) #f)
6985 (cmd "--optional=621") => ("str" () (symb) (621) #f)
6986 (cmd "-s" "speciality") => ("speciality" () (symb) () #f)
6987 (cmd "-sspeciality") => ("speciality" () (symb) () #f)
6988 (cmd "--single" "serendipity") => ("serendipity" () (symb) () #f)
6989 (cmd "--single=serendipity") => ("serendipity" () (symb) () #f)
6990 (cmd "-n" "gravity" "piety") => ("str" () (piety gravity) () #f)
6991 (cmd "-ngravity" "piety") => ("str" () (piety gravity) () #f)
6992 (cmd "--nary" "chastity") => ("str" () (chastity) () #f)
6993 (cmd "--nary=chastity" "") => ("str" () ( chastity) () #f)
6994 (cmd "-N" "calamity") => ("str" () (calamity) () #f)
6995 (cmd "-Ncalamity") => ("str" () (calamity) () #f)
6996 (cmd "--nary1" "surety") => ("str" () (surety) () #f)
6997 (cmd "--nary1=surety") => ("str" () (surety) () #f)
6998 (cmd "-N" "levity" "fealty") => ("str" () (fealty levity) () #f)
6999 (cmd "-Nlevity" "fealty") => ("str" () (fealty levity) () #f)
7000 (cmd "--nary1" "surety" "brevity") => ("str" () (brevity surety) () #f)
7001 (cmd "--nary1=surety" "brevity") => ("str" () (brevity surety) () #f)
7004 Usage: cmd [OPTION ARGUMENT ...] ...
7007 -o, --optional[=]<number>
7008 -n, --nary[=]<symbols> ...
7009 -N, --nary1[=]<symbols> ...
7010 -s, --single[=]<string>
7012 ERROR: getopt->parameter-list "unrecognized option" "-?"
7014 Some commands are defined in all extended relational-databases. The
7015 are called just like *Note Relational Database Operations::.
7017 - Function: add-domain domain-row
7018 Adds DOMAIN-ROW to the "domains" table if there is no row in the
7019 domains table associated with key `(car DOMAIN-ROW)' and returns
7020 `#t'. Otherwise returns `#f'.
7022 For the fields and layout of the domain table, *Note Catalog
7023 Representation::. Currently, these fields are
7028 * domain-integrity-rule
7034 The following example adds 3 domains to the `build' database.
7035 `Optstring' is either a string or `#f'. `filename' is a string
7036 and `build-whats' is a symbol.
7038 (for-each (build 'add-domain)
7040 (lambda (x) (or (not x) (string? x)))
7043 (filename #f #f string #f)
7044 (build-whats #f #f symbol #f)))
7046 - Function: delete-domain domain-name
7047 Removes and returns the DOMAIN-NAME row from the "domains" table.
7049 - Function: domain-checker domain
7050 Returns a procedure to check an argument for conformance to domain
7056 - Procedure: define-tables rdb spec-0 ...
7057 Adds tables as specified in SPEC-0 ... to the open
7058 relational-database RDB. Each SPEC has the form:
7060 (<name> <descriptor-name> <descriptor-name> <rows>)
7062 (<name> <primary-key-fields> <other-fields> <rows>)
7064 where <name> is the table name, <descriptor-name> is the symbol
7065 name of a descriptor table, <primary-key-fields> and
7066 <other-fields> describe the primary keys and other fields
7067 respectively, and <rows> is a list of data rows to be added to the
7070 <primary-key-fields> and <other-fields> are lists of field
7071 descriptors of the form:
7073 (<column-name> <domain>)
7075 (<column-name> <domain> <column-integrity-rule>)
7077 where <column-name> is the column name, <domain> is the domain of
7078 the column, and <column-integrity-rule> is an expression whose
7079 value is a procedure of one argument (which returns `#f' to signal
7082 If <domain> is not a defined domain name and it matches the name of
7083 this table or an already defined (in one of SPEC-0 ...) single key
7084 field table, a foriegn-key domain will be created for it.
7086 The following example shows a new database with the name of `foo.db'
7087 being created with tables describing processor families and
7088 processor/os/compiler combinations.
7090 The database command `define-tables' is defined to call `define-tables'
7091 with its arguments. The database is also configured to print `Welcome'
7092 when the database is opened. The database is then closed and reopened.
7094 (require 'database-utilities)
7095 (define my-rdb (create-database "foo.db" 'alist-table))
7097 (define-tables my-rdb
7100 ((parameters parameter-list)
7101 (procedure expression)
7102 (documentation string))
7106 (lambda (rdb) (lambda specs (apply define-tables rdb specs)))
7107 "Create or Augment tables from list of specs")
7111 (lambda (rdb) (display "Welcome") (newline) rdb)
7114 ((my-rdb 'define-tables)
7117 ((also-ran processor-family))
7126 ((processor processor-family)
7129 ((aix powerpc aix -)
7130 (amiga-dice-c m68000 amiga dice-c)
7131 (amiga-aztec m68000 amiga aztec)
7132 (amiga-sas/c-5.10 m68000 amiga sas/c)
7133 (atari-st-gcc m68000 atari gcc)
7134 (atari-st-turbo-c m68000 atari turbo-c)
7135 (borland-c-3.1 8086 ms-dos borland-c)
7136 (djgpp i386 ms-dos gcc)
7137 (linux i386 linux gcc)
7138 (microsoft-c 8086 ms-dos microsoft-c)
7139 (os/2-emx i386 os/2 gcc)
7140 (turbo-c-2 8086 ms-dos turbo-c)
7141 (watcom-9.0 i386 ms-dos watcom))))
7143 ((my-rdb 'close-database))
7145 (set! my-rdb (open-database "foo.db" 'alist-table))
7152 - Procedure: list-table-definition rdb table-name |
7153 If symbol TABLE-NAME exists in the open relational-database RDB, |
7154 then returns a list of the table-name, its primary key names and |
7155 domains, its other key names and domains, and the table's records |
7156 (as lists). Otherwise, returns #f. |
7158 The list returned by `list-table-definition', when passed as an |
7159 argument to `define-tables', will recreate the table. |
7162 File: slib.info, Node: Database Reports, Next: Database Browser, Prev: Database Utilities, Up: Relational Database
7167 Code for generating database reports is in `report.scm'. After writing
7168 it using `format', I discovered that Common-Lisp `format' is not
7169 useable for this application because there is no mechanismm for
7170 truncating fields. `report.scm' needs to be rewritten using `printf'.
7172 - Procedure: create-report rdb destination report-name table
7173 - Procedure: create-report rdb destination report-name
7174 The symbol REPORT-NAME must be primary key in the table named
7175 `*reports*' in the relational database RDB. DESTINATION is a
7176 port, string, or symbol. If DESTINATION is a:
7179 The table is created as ascii text and written to that port.
7182 The table is created as ascii text and written to the file
7183 named by DESTINATION.
7186 DESTINATION is the primary key for a row in the table named
7189 The report is prepared as follows:
7191 * `Format' (*note Format::) is called with the `header' field
7192 and the (list of) `column-names' of the table.
7194 * `Format' is called with the `reporter' field and (on
7195 successive calls) each record in the natural order for the
7196 table. A count is kept of the number of newlines output by
7197 format. When the number of newlines to be output exceeds the
7198 number of lines per page, the set of lines will be broken if
7199 there are more than `minimum-break' left on this page and the
7200 number of lines for this row is larger or equal to twice
7203 * `Format' is called with the `footer' field and the (list of)
7204 `column-names' of the table. The footer field should not
7207 * A new page is output.
7209 * This entire process repeats until all the rows are output.
7211 Each row in the table *reports* has the fields:
7217 The table to report on if none is specified.
7220 A `format' string. At the beginning and end of each page
7221 respectively, `format' is called with this string and the (list of)
7222 column-names of this table.
7225 A `format' string. For each row in the table, `format' is called
7226 with this string and the row.
7229 The minimum number of lines into which the report lines for a row
7230 can be broken. Use `0' if a row's lines should not be broken over
7233 Each row in the table *printers* has the fields:
7239 The procedure to call to actually print.
7242 File: slib.info, Node: Database Browser, Prev: Database Reports, Up: Relational Database
7247 (require 'database-browse)
7249 - Procedure: browse database
7250 Prints the names of all the tables in DATABASE and sets browse's
7251 default to DATABASE.
7254 Prints the names of all the tables in the default database.
7256 - Procedure: browse table-name
7257 For each record of the table named by the symbol TABLE-NAME,
7258 prints a line composed of all the field values.
7260 - Procedure: browse pathname
7261 Opens the database named by the string PATHNAME, prints the names
7262 of all its tables, and sets browse's default to the database.
7264 - Procedure: browse database table-name
7265 Sets browse's default to DATABASE and prints the records of the
7266 table named by the symbol TABLE-NAME.
7268 - Procedure: browse pathname table-name
7269 Opens the database named by the string PATHNAME and sets browse's
7270 default to it; `browse' prints the records of the table named by
7271 the symbol TABLE-NAME.
7275 File: slib.info, Node: Weight-Balanced Trees, Prev: Relational Database, Up: Database Packages
7277 Weight-Balanced Trees
7278 =====================
7280 `(require 'wt-tree)'
7282 Balanced binary trees are a useful data structure for maintaining
7283 large sets of ordered objects or sets of associations whose keys are
7284 ordered. MIT Scheme has an comprehensive implementation of
7285 weight-balanced binary trees which has several advantages over the
7286 other data structures for large aggregates:
7288 * In addition to the usual element-level operations like insertion,
7289 deletion and lookup, there is a full complement of collection-level
7290 operations, like set intersection, set union and subset test, all
7291 of which are implemented with good orders of growth in time and
7292 space. This makes weight balanced trees ideal for rapid
7293 prototyping of functionally derived specifications.
7295 * An element in a tree may be indexed by its position under the
7296 ordering of the keys, and the ordinal position of an element may
7297 be determined, both with reasonable efficiency.
7299 * Operations to find and remove minimum element make weight balanced
7300 trees simple to use for priority queues.
7302 * The implementation is _functional_ rather than _imperative_. This
7303 means that operations like `inserting' an association in a tree do
7304 not destroy the old tree, in much the same way that `(+ 1 x)'
7305 modifies neither the constant 1 nor the value bound to `x'. The
7306 trees are referentially transparent thus the programmer need not
7307 worry about copying the trees. Referential transparency allows
7308 space efficiency to be achieved by sharing subtrees.
7311 These features make weight-balanced trees suitable for a wide range of
7312 applications, especially those that require large numbers of sets or
7313 discrete maps. Applications that have a few global databases and/or
7314 concentrate on element-level operations like insertion and lookup are
7315 probably better off using hash-tables or red-black trees.
7317 The _size_ of a tree is the number of associations that it contains.
7318 Weight balanced binary trees are balanced to keep the sizes of the
7319 subtrees of each node within a constant factor of each other. This
7320 ensures logarithmic times for single-path operations (like lookup and
7321 insertion). A weight balanced tree takes space that is proportional to
7322 the number of associations in the tree. For the current
7323 implementation, the constant of proportionality is six words per
7326 Weight balanced trees can be used as an implementation for either
7327 discrete sets or discrete maps (associations). Sets are implemented by
7328 ignoring the datum that is associated with the key. Under this scheme
7329 if an associations exists in the tree this indicates that the key of the
7330 association is a member of the set. Typically a value such as `()',
7331 `#t' or `#f' is associated with the key.
7333 Many operations can be viewed as computing a result that, depending on
7334 whether the tree arguments are thought of as sets or maps, is known by
7335 two different names. An example is `wt-tree/member?', which, when
7336 regarding the tree argument as a set, computes the set membership
7337 operation, but, when regarding the tree as a discrete map,
7338 `wt-tree/member?' is the predicate testing if the map is defined at an
7339 element in its domain. Most names in this package have been chosen
7340 based on interpreting the trees as sets, hence the name
7341 `wt-tree/member?' rather than `wt-tree/defined-at?'.
7343 The weight balanced tree implementation is a run-time-loadable option.
7344 To use weight balanced trees, execute
7346 (load-option 'wt-tree)
7348 once before calling any of the procedures defined here.
7352 * Construction of Weight-Balanced Trees::
7353 * Basic Operations on Weight-Balanced Trees::
7354 * Advanced Operations on Weight-Balanced Trees::
7355 * Indexing Operations on Weight-Balanced Trees::
7358 File: slib.info, Node: Construction of Weight-Balanced Trees, Next: Basic Operations on Weight-Balanced Trees, Prev: Weight-Balanced Trees, Up: Weight-Balanced Trees
7360 Construction of Weight-Balanced Trees
7361 -------------------------------------
7363 Binary trees require there to be a total order on the keys used to
7364 arrange the elements in the tree. Weight balanced trees are organized
7365 by _types_, where the type is an object encapsulating the ordering
7366 relation. Creating a tree is a two-stage process. First a tree type
7367 must be created from the predicate which gives the ordering. The tree
7368 type is then used for making trees, either empty or singleton trees or
7369 trees from other aggregate structures like association lists. Once
7370 created, a tree `knows' its type and the type is used to test
7371 compatibility between trees in operations taking two trees. Usually a
7372 small number of tree types are created at the beginning of a program and
7373 used many times throughout the program's execution.
7375 - procedure+: make-wt-tree-type key<?
7376 This procedure creates and returns a new tree type based on the
7377 ordering predicate KEY<?. KEY<? must be a total ordering, having
7378 the property that for all key values `a', `b' and `c':
7381 (and (key<? a b) (key<? b a)) => #f
7382 (if (and (key<? a b) (key<? b c))
7386 Two key values are assumed to be equal if neither is less than the
7389 Each call to `make-wt-tree-type' returns a distinct value, and
7390 trees are only compatible if their tree types are `eq?'. A
7391 consequence is that trees that are intended to be used in binary
7392 tree operations must all be created with a tree type originating
7393 from the same call to `make-wt-tree-type'.
7395 - variable+: number-wt-type
7396 A standard tree type for trees with numeric keys. `Number-wt-type'
7397 could have been defined by
7399 (define number-wt-type (make-wt-tree-type <))
7401 - variable+: string-wt-type
7402 A standard tree type for trees with string keys. `String-wt-type'
7403 could have been defined by
7405 (define string-wt-type (make-wt-tree-type string<?))
7407 - procedure+: make-wt-tree wt-tree-type
7408 This procedure creates and returns a newly allocated weight
7409 balanced tree. The tree is empty, i.e. it contains no
7410 associations. WT-TREE-TYPE is a weight balanced tree type
7411 obtained by calling `make-wt-tree-type'; the returned tree has
7414 - procedure+: singleton-wt-tree wt-tree-type key datum
7415 This procedure creates and returns a newly allocated weight
7416 balanced tree. The tree contains a single association, that of
7417 DATUM with KEY. WT-TREE-TYPE is a weight balanced tree type
7418 obtained by calling `make-wt-tree-type'; the returned tree has
7421 - procedure+: alist->wt-tree tree-type alist
7422 Returns a newly allocated weight-balanced tree that contains the
7423 same associations as ALIST. This procedure is equivalent to:
7425 (lambda (type alist)
7426 (let ((tree (make-wt-tree type)))
7427 (for-each (lambda (association)
7435 File: slib.info, Node: Basic Operations on Weight-Balanced Trees, Next: Advanced Operations on Weight-Balanced Trees, Prev: Construction of Weight-Balanced Trees, Up: Weight-Balanced Trees
7437 Basic Operations on Weight-Balanced Trees
7438 -----------------------------------------
7440 This section describes the basic tree operations on weight balanced
7441 trees. These operations are the usual tree operations for insertion,
7442 deletion and lookup, some predicates and a procedure for determining the
7443 number of associations in a tree.
7445 - procedure+: wt-tree? object
7446 Returns `#t' if OBJECT is a weight-balanced tree, otherwise
7449 - procedure+: wt-tree/empty? wt-tree
7450 Returns `#t' if WT-TREE contains no associations, otherwise
7453 - procedure+: wt-tree/size wt-tree
7454 Returns the number of associations in WT-TREE, an exact
7455 non-negative integer. This operation takes constant time.
7457 - procedure+: wt-tree/add wt-tree key datum
7458 Returns a new tree containing all the associations in WT-TREE and
7459 the association of DATUM with KEY. If WT-TREE already had an
7460 association for KEY, the new association overrides the old. The
7461 average and worst-case times required by this operation are
7462 proportional to the logarithm of the number of associations in
7465 - procedure+: wt-tree/add! wt-tree key datum
7466 Associates DATUM with KEY in WT-TREE and returns an unspecified
7467 value. If WT-TREE already has an association for KEY, that
7468 association is replaced. The average and worst-case times
7469 required by this operation are proportional to the logarithm of
7470 the number of associations in WT-TREE.
7472 - procedure+: wt-tree/member? key wt-tree
7473 Returns `#t' if WT-TREE contains an association for KEY, otherwise
7474 returns `#f'. The average and worst-case times required by this
7475 operation are proportional to the logarithm of the number of
7476 associations in WT-TREE.
7478 - procedure+: wt-tree/lookup wt-tree key default
7479 Returns the datum associated with KEY in WT-TREE. If WT-TREE
7480 doesn't contain an association for KEY, DEFAULT is returned. The
7481 average and worst-case times required by this operation are
7482 proportional to the logarithm of the number of associations in
7485 - procedure+: wt-tree/delete wt-tree key
7486 Returns a new tree containing all the associations in WT-TREE,
7487 except that if WT-TREE contains an association for KEY, it is
7488 removed from the result. The average and worst-case times required
7489 by this operation are proportional to the logarithm of the number
7490 of associations in WT-TREE.
7492 - procedure+: wt-tree/delete! wt-tree key
7493 If WT-TREE contains an association for KEY the association is
7494 removed. Returns an unspecified value. The average and worst-case
7495 times required by this operation are proportional to the logarithm
7496 of the number of associations in WT-TREE.
7499 File: slib.info, Node: Advanced Operations on Weight-Balanced Trees, Next: Indexing Operations on Weight-Balanced Trees, Prev: Basic Operations on Weight-Balanced Trees, Up: Weight-Balanced Trees
7501 Advanced Operations on Weight-Balanced Trees
7502 --------------------------------------------
7504 In the following the _size_ of a tree is the number of associations
7505 that the tree contains, and a _smaller_ tree contains fewer
7508 - procedure+: wt-tree/split< wt-tree bound
7509 Returns a new tree containing all and only the associations in
7510 WT-TREE which have a key that is less than BOUND in the ordering
7511 relation of the tree type of WT-TREE. The average and worst-case
7512 times required by this operation are proportional to the logarithm
7513 of the size of WT-TREE.
7515 - procedure+: wt-tree/split> wt-tree bound
7516 Returns a new tree containing all and only the associations in
7517 WT-TREE which have a key that is greater than BOUND in the
7518 ordering relation of the tree type of WT-TREE. The average and
7519 worst-case times required by this operation are proportional to the
7520 logarithm of size of WT-TREE.
7522 - procedure+: wt-tree/union wt-tree-1 wt-tree-2
7523 Returns a new tree containing all the associations from both trees.
7524 This operation is asymmetric: when both trees have an association
7525 for the same key, the returned tree associates the datum from
7526 WT-TREE-2 with the key. Thus if the trees are viewed as discrete
7527 maps then `wt-tree/union' computes the map override of WT-TREE-1 by
7528 WT-TREE-2. If the trees are viewed as sets the result is the set
7529 union of the arguments. The worst-case time required by this
7530 operation is proportional to the sum of the sizes of both trees.
7531 If the minimum key of one tree is greater than the maximum key of
7532 the other tree then the time required is at worst proportional to
7533 the logarithm of the size of the larger tree.
7535 - procedure+: wt-tree/intersection wt-tree-1 wt-tree-2
7536 Returns a new tree containing all and only those associations from
7537 WT-TREE-1 which have keys appearing as the key of an association
7538 in WT-TREE-2. Thus the associated data in the result are those
7539 from WT-TREE-1. If the trees are being used as sets the result is
7540 the set intersection of the arguments. As a discrete map
7541 operation, `wt-tree/intersection' computes the domain restriction
7542 of WT-TREE-1 to (the domain of) WT-TREE-2. The time required by
7543 this operation is never worse that proportional to the sum of the
7546 - procedure+: wt-tree/difference wt-tree-1 wt-tree-2
7547 Returns a new tree containing all and only those associations from
7548 WT-TREE-1 which have keys that _do not_ appear as the key of an
7549 association in WT-TREE-2. If the trees are viewed as sets the
7550 result is the asymmetric set difference of the arguments. As a
7551 discrete map operation, it computes the domain restriction of
7552 WT-TREE-1 to the complement of (the domain of) WT-TREE-2. The
7553 time required by this operation is never worse that proportional to
7554 the sum of the sizes of the trees.
7556 - procedure+: wt-tree/subset? wt-tree-1 wt-tree-2
7557 Returns `#t' iff the key of each association in WT-TREE-1 is the
7558 key of some association in WT-TREE-2, otherwise returns `#f'.
7559 Viewed as a set operation, `wt-tree/subset?' is the improper subset
7560 predicate. A proper subset predicate can be constructed:
7562 (define (proper-subset? s1 s2)
7563 (and (wt-tree/subset? s1 s2)
7564 (< (wt-tree/size s1) (wt-tree/size s2))))
7566 As a discrete map operation, `wt-tree/subset?' is the subset test
7567 on the domain(s) of the map(s). In the worst-case the time
7568 required by this operation is proportional to the size of
7571 - procedure+: wt-tree/set-equal? wt-tree-1 wt-tree-2
7572 Returns `#t' iff for every association in WT-TREE-1 there is an
7573 association in WT-TREE-2 that has the same key, and _vice versa_.
7575 Viewing the arguments as sets `wt-tree/set-equal?' is the set
7576 equality predicate. As a map operation it determines if two maps
7577 are defined on the same domain.
7579 This procedure is equivalent to
7581 (lambda (wt-tree-1 wt-tree-2)
7582 (and (wt-tree/subset? wt-tree-1 wt-tree-2
7583 (wt-tree/subset? wt-tree-2 wt-tree-1)))
7585 In the worst-case the time required by this operation is
7586 proportional to the size of the smaller tree.
7588 - procedure+: wt-tree/fold combiner initial wt-tree
7589 This procedure reduces WT-TREE by combining all the associations,
7590 using an reverse in-order traversal, so the associations are
7591 visited in reverse order. COMBINER is a procedure of three
7592 arguments: a key, a datum and the accumulated result so far.
7593 Provided COMBINER takes time bounded by a constant, `wt-tree/fold'
7594 takes time proportional to the size of WT-TREE.
7596 A sorted association list can be derived simply:
7598 (wt-tree/fold (lambda (key datum list)
7599 (cons (cons key datum) list))
7603 The data in the associations can be summed like this:
7605 (wt-tree/fold (lambda (key datum sum) (+ sum datum))
7609 - procedure+: wt-tree/for-each action wt-tree
7610 This procedure traverses the tree in-order, applying ACTION to
7611 each association. The associations are processed in increasing
7612 order of their keys. ACTION is a procedure of two arguments which
7613 take the key and datum respectively of the association. Provided
7614 ACTION takes time bounded by a constant, `wt-tree/for-each' takes
7615 time proportional to in the size of WT-TREE. The example prints
7618 (wt-tree/for-each (lambda (key value)
7619 (display (list key value)))
7623 File: slib.info, Node: Indexing Operations on Weight-Balanced Trees, Prev: Advanced Operations on Weight-Balanced Trees, Up: Weight-Balanced Trees
7625 Indexing Operations on Weight-Balanced Trees
7626 --------------------------------------------
7628 Weight balanced trees support operations that view the tree as sorted
7629 sequence of associations. Elements of the sequence can be accessed by
7630 position, and the position of an element in the sequence can be
7631 determined, both in logarthmic time.
7633 - procedure+: wt-tree/index wt-tree index
7634 - procedure+: wt-tree/index-datum wt-tree index
7635 - procedure+: wt-tree/index-pair wt-tree index
7636 Returns the 0-based INDEXth association of WT-TREE in the sorted
7637 sequence under the tree's ordering relation on the keys.
7638 `wt-tree/index' returns the INDEXth key, `wt-tree/index-datum'
7639 returns the datum associated with the INDEXth key and
7640 `wt-tree/index-pair' returns a new pair `(KEY . DATUM)' which is
7641 the `cons' of the INDEXth key and its datum. The average and
7642 worst-case times required by this operation are proportional to
7643 the logarithm of the number of associations in the tree.
7645 These operations signal an error if the tree is empty, if
7646 INDEX`<0', or if INDEX is greater than or equal to the number of
7647 associations in the tree.
7649 Indexing can be used to find the median and maximum keys in the
7652 median: (wt-tree/index WT-TREE
7653 (quotient (wt-tree/size WT-TREE) 2))
7655 maximum: (wt-tree/index WT-TREE
7656 (-1+ (wt-tree/size WT-TREE)))
7658 - procedure+: wt-tree/rank wt-tree key
7659 Determines the 0-based position of KEY in the sorted sequence of
7660 the keys under the tree's ordering relation, or `#f' if the tree
7661 has no association with for KEY. This procedure returns either an
7662 exact non-negative integer or `#f'. The average and worst-case
7663 times required by this operation are proportional to the logarithm
7664 of the number of associations in the tree.
7666 - procedure+: wt-tree/min wt-tree
7667 - procedure+: wt-tree/min-datum wt-tree
7668 - procedure+: wt-tree/min-pair wt-tree
7669 Returns the association of WT-TREE that has the least key under
7670 the tree's ordering relation. `wt-tree/min' returns the least key,
7671 `wt-tree/min-datum' returns the datum associated with the least key
7672 and `wt-tree/min-pair' returns a new pair `(key . datum)' which is
7673 the `cons' of the minimum key and its datum. The average and
7674 worst-case times required by this operation are proportional to the
7675 logarithm of the number of associations in the tree.
7677 These operations signal an error if the tree is empty. They could
7679 (define (wt-tree/min tree) (wt-tree/index tree 0))
7680 (define (wt-tree/min-datum tree) (wt-tree/index-datum tree 0))
7681 (define (wt-tree/min-pair tree) (wt-tree/index-pair tree 0))
7683 - procedure+: wt-tree/delete-min wt-tree
7684 Returns a new tree containing all of the associations in WT-TREE
7685 except the association with the least key under the WT-TREE's
7686 ordering relation. An error is signalled if the tree is empty.
7687 The average and worst-case times required by this operation are
7688 proportional to the logarithm of the number of associations in the
7689 tree. This operation is equivalent to
7691 (wt-tree/delete WT-TREE (wt-tree/min WT-TREE))
7693 - procedure+: wt-tree/delete-min! wt-tree
7694 Removes the association with the least key under the WT-TREE's
7695 ordering relation. An error is signalled if the tree is empty.
7696 The average and worst-case times required by this operation are
7697 proportional to the logarithm of the number of associations in the
7698 tree. This operation is equivalent to
7700 (wt-tree/delete! WT-TREE (wt-tree/min WT-TREE))
7703 File: slib.info, Node: Other Packages, Next: About SLIB, Prev: Database Packages, Up: Top
7710 * Data Structures:: Various data structures.
7711 * Procedures:: Miscellaneous utility procedures.
7712 * Standards Support:: Support for Scheme Standards.
7713 * Session Support:: REPL and Debugging.
7714 * Extra-SLIB Packages::
7717 File: slib.info, Node: Data Structures, Next: Procedures, Prev: Other Packages, Up: Other Packages
7725 * Array Mapping:: 'array-for-each
7726 * Association Lists:: 'alist
7728 * Portable Image Files:: 'pnm
7729 * Collections:: 'collect
7730 * Dynamic Data Type:: 'dynamic
7731 * Hash Tables:: 'hash-table
7732 * Hashing:: 'hash, 'sierpinski, 'soundex
7734 * Priority Queues:: 'priority-queue
7737 * Structures:: 'struct, 'structure
7740 File: slib.info, Node: Arrays, Next: Array Mapping, Prev: Data Structures, Up: Data Structures
7747 - Function: array? obj
7748 Returns `#t' if the OBJ is an array, and `#f' if not.
7750 - Function: make-array initial-value bound1 bound2 ...
7751 Creates and returns an array that has as many dimensins as there
7752 are BOUNDs and fills it with INITIAL-VALUE.
7754 When constructing an array, BOUND is either an inclusive range of
7755 indices expressed as a two element list, or an upper bound expressed as
7756 a single integer. So
7757 (make-array 'foo 3 3) == (make-array 'foo '(0 2) '(0 2))
7759 - Function: make-shared-array array mapper bound1 bound2 ...
7760 `make-shared-array' can be used to create shared subarrays of other
7761 arrays. The MAPPER is a function that translates coordinates in
7762 the new array into coordinates in the old array. A MAPPER must be
7763 linear, and its range must stay within the bounds of the old
7764 array, but it can be otherwise arbitrary. A simple example:
7765 (define fred (make-array #f 8 8))
7766 (define freds-diagonal
7767 (make-shared-array fred (lambda (i) (list i i)) 8))
7768 (array-set! freds-diagonal 'foo 3)
7769 (array-ref fred 3 3)
7771 (define freds-center
7772 (make-shared-array fred (lambda (i j) (list (+ 3 i) (+ 3 j)))
7774 (array-ref freds-center 0 0)
7777 - Function: array-rank obj
7778 Returns the number of dimensions of OBJ. If OBJ is not an array,
7781 - Function: array-shape array
7782 `array-shape' returns a list of inclusive bounds. So:
7783 (array-shape (make-array 'foo 3 5))
7786 - Function: array-dimensions array
7787 `array-dimensions' is similar to `array-shape' but replaces
7788 elements with a 0 minimum with one greater than the maximum. So:
7789 (array-dimensions (make-array 'foo 3 5))
7792 - Procedure: array-in-bounds? array index1 index2 ...
7793 Returns `#t' if its arguments would be acceptable to `array-ref'.
7795 - Function: array-ref array index1 index2 ...
7796 Returns the element at the `(INDEX1, INDEX2)' element in ARRAY.
7798 - Procedure: array-set! array new-value index1 index2 ...
7800 - Function: array-1d-ref array index
7801 - Function: array-2d-ref array index1 index2
7802 - Function: array-3d-ref array index1 index2 index3
7804 - Procedure: array-1d-set! array new-value index
7805 - Procedure: array-2d-set! array new-value index1 index2
7806 - Procedure: array-3d-set! array new-value index1 index2 index3
7808 The functions are just fast versions of `array-ref' and `array-set!'
7809 that take a fixed number of arguments, and perform no bounds checking.
7811 If you comment out the bounds checking code, this is about as
7812 efficient as you could ask for without help from the compiler.
7814 An exercise left to the reader: implement the rest of APL.
7817 File: slib.info, Node: Array Mapping, Next: Association Lists, Prev: Arrays, Up: Data Structures
7822 `(require 'array-for-each)'
7824 - Function: array-map! array0 proc array1 ...
7825 ARRAY1, ... must have the same number of dimensions as ARRAY0 and
7826 have a range for each index which includes the range for the
7827 corresponding index in ARRAY0. PROC is applied to each tuple of
7828 elements of ARRAY1 ... and the result is stored as the
7829 corresponding element in ARRAY0. The value returned is
7830 unspecified. The order of application is unspecified.
7832 - Function: array-for-each PROC ARRAY0 ...
7833 PROC is applied to each tuple of elements of ARRAY0 ... in
7834 row-major order. The value returned is unspecified.
7836 - Function: array-indexes ARRAY
7837 Returns an array of lists of indexes for ARRAY such that, if LI is
7838 a list of indexes for which ARRAY is defined, (equal? LI (apply
7839 array-ref (array-indexes ARRAY) LI)).
7841 - Function: array-index-map! array proc
7842 applies PROC to the indices of each element of ARRAY in turn,
7843 storing the result in the corresponding element. The value
7844 returned and the order of application are unspecified.
7846 One can implement ARRAY-INDEXES as
7847 (define (array-indexes array)
7848 (let ((ra (apply make-array #f (array-shape array))))
7849 (array-index-map! ra (lambda x x))
7852 (define (apl:index-generator n)
7853 (let ((v (make-uniform-vector n 1)))
7854 (array-index-map! v (lambda (i) i))
7857 - Function: array-copy! source destination
7858 Copies every element from vector or array SOURCE to the
7859 corresponding element of DESTINATION. DESTINATION must have the
7860 same rank as SOURCE, and be at least as large in each dimension.
7861 The order of copying is unspecified.
7864 File: slib.info, Node: Association Lists, Next: Byte, Prev: Array Mapping, Up: Data Structures
7871 Alist functions provide utilities for treating a list of key-value
7872 pairs as an associative database. These functions take an equality
7873 predicate, PRED, as an argument. This predicate should be repeatable,
7874 symmetric, and transitive.
7876 Alist functions can be used with a secondary index method such as hash
7877 tables for improved performance.
7879 - Function: predicate->asso pred
7880 Returns an "association function" (like `assq', `assv', or
7881 `assoc') corresponding to PRED. The returned function returns a
7882 key-value pair whose key is `pred'-equal to its first argument or
7883 `#f' if no key in the alist is PRED-equal to the first argument.
7885 - Function: alist-inquirer pred
7886 Returns a procedure of 2 arguments, ALIST and KEY, which returns
7887 the value associated with KEY in ALIST or `#f' if KEY does not
7890 - Function: alist-associator pred
7891 Returns a procedure of 3 arguments, ALIST, KEY, and VALUE, which
7892 returns an alist with KEY and VALUE associated. Any previous
7893 value associated with KEY will be lost. This returned procedure
7894 may or may not have side effects on its ALIST argument. An
7895 example of correct usage is:
7896 (define put (alist-associator string-ci=?))
7898 (set! alist (put alist "Foo" 9))
7900 - Function: alist-remover pred
7901 Returns a procedure of 2 arguments, ALIST and KEY, which returns
7902 an alist with an association whose KEY is key removed. This
7903 returned procedure may or may not have side effects on its ALIST
7904 argument. An example of correct usage is:
7905 (define rem (alist-remover string-ci=?))
7906 (set! alist (rem alist "foo"))
7908 - Function: alist-map proc alist
7909 Returns a new association list formed by mapping PROC over the
7910 keys and values of ALIST. PROC must be a function of 2 arguments
7911 which returns the new value part.
7913 - Function: alist-for-each proc alist
7914 Applies PROC to each pair of keys and values of ALIST. PROC must
7915 be a function of 2 arguments. The returned value is unspecified.
7918 File: slib.info, Node: Byte, Next: Portable Image Files, Prev: Association Lists, Up: Data Structures
7925 Some algorithms are expressed in terms of arrays of small integers.
7926 Using Scheme strings to implement these arrays is not portable vis-a-vis
7927 the correspondence between integers and characters and non-ascii
7928 character sets. These functions abstract the notion of a "byte".
7930 - Function: byte-ref bytes k
7931 K must be a valid index of BYTES. `byte-ref' returns byte K of
7932 BYTES using zero-origin indexing.
7934 - Procedure: byte-set! bytes k byte
7935 K must be a valid index of BYTES%, and BYTE must be a small
7936 integer. `Byte-set!' stores BYTE in element K of BYTES and
7937 returns an unspecified value.
7939 - Function: make-bytes k
7940 - Function: make-bytes k byte
7941 `Make-bytes' returns a newly allocated byte-array of length K. If
7942 BYTE is given, then all elements of the byte-array are initialized
7943 to BYTE, otherwise the contents of the byte-array are unspecified.
7946 - Function: bytes-length bytes
7947 `bytes-length' returns length of byte-array BYTES.
7950 - Function: write-byte byte
7951 - Function: write-byte byte port
7952 Writes the byte BYTE (not an external representation of the byte)
7953 to the given PORT and returns an unspecified value. The PORT
7954 argument may be omitted, in which case it defaults to the value
7955 returned by `current-output-port'.
7958 - Function: read-byte
7959 - Function: read-byte port
7960 Returns the next byte available from the input PORT, updating the
7961 PORT to point to the following byte. If no more bytes are
7962 available, an end of file object is returned. PORT may be
7963 omitted, in which case it defaults to the value returned by
7964 `current-input-port'.
7967 - Function: bytes byte ...
7968 Returns a newly allocated byte-array composed of the arguments.
7971 - Function: bytes->list bytes
7972 - Function: list->bytes bytes
7973 `Bytes->list' returns a newly allocated list of the bytes that
7974 make up the given byte-array. `List->bytes' returns a newly
7975 allocated byte-array formed from the small integers in the list
7976 BYTES. `Bytes->list' and `list->bytes' are inverses so far as
7977 `equal?' is concerned.
7981 File: slib.info, Node: Portable Image Files, Next: Collections, Prev: Byte, Up: Data Structures
7983 Portable Image Files
7984 --------------------
7988 - Function: pnm:type-dimensions path
7989 The string PATH must name a "portable bitmap graphics" file.
7990 `pnm:type-dimensions' returns a list of 4 items:
7991 1. A symbol describing the type of the file named by PATH.
7993 2. The image width in pixels.
7995 3. The image height in pixels.
7997 4. The maximum value of pixels assume in the file.
7999 The current set of file-type symbols is:
8002 Black-and-White image; pixel values are 0 or 1.
8006 Gray (monochrome) image; pixel values are from 0 to MAXVAL
8007 specified in file header.
8011 RGB (full color) image; red, green, and blue interleaved
8012 pixel values are from 0 to MAXVAL
8015 - Function: pnm:image-file->array path array
8016 Reads the "portable bitmap graphics" file named by PATH into
8017 ARRAY. ARRAY must be the correct size and type for PATH. ARRAY
8020 - Function: pnm:image-file->array path
8021 `pnm:image-file->array' creates and returns an array with the
8022 "portable bitmap graphics" file named by PATH read into it.
8025 - Procedure: pnm:array-write type array maxval path
8026 Writes the contents of ARRAY to a TYPE image file named PATH. The
8027 file will have pixel values between 0 and MAXVAL, which must be
8028 compatible with TYPE. For `pbm' files, MAXVAL must be `1'.
8032 File: slib.info, Node: Collections, Next: Dynamic Data Type, Prev: Portable Image Files, Up: Data Structures
8037 `(require 'collect)'
8039 Routines for managing collections. Collections are aggregate data
8040 structures supporting iteration over their elements, similar to the
8041 Dylan(TM) language, but with a different interface. They have
8042 "elements" indexed by corresponding "keys", although the keys may be
8043 implicit (as with lists).
8045 New types of collections may be defined as YASOS objects (*note
8046 Yasos::). They must support the following operations:
8047 * `(collection? SELF)' (always returns `#t');
8049 * `(size SELF)' returns the number of elements in the collection;
8051 * `(print SELF PORT)' is a specialized print operation for the
8052 collection which prints a suitable representation on the given
8053 PORT or returns it as a string if PORT is `#t';
8055 * `(gen-elts SELF)' returns a thunk which on successive invocations
8056 yields elements of SELF in order or gives an error if it is
8057 invoked more than `(size SELF)' times;
8059 * `(gen-keys SELF)' is like `gen-elts', but yields the collection's
8062 They might support specialized `for-each-key' and `for-each-elt'
8065 - Function: collection? obj
8066 A predicate, true initially of lists, vectors and strings. New
8067 sorts of collections must answer `#t' to `collection?'.
8069 - Procedure: map-elts proc . collections
8070 - Procedure: do-elts proc . collections
8071 PROC is a procedure taking as many arguments as there are
8072 COLLECTIONS (at least one). The COLLECTIONS are iterated over in
8073 their natural order and PROC is applied to the elements yielded by
8074 each iteration in turn. The order in which the arguments are
8075 supplied corresponds to te order in which the COLLECTIONS appear.
8076 `do-elts' is used when only side-effects of PROC are of interest
8077 and its return value is unspecified. `map-elts' returns a
8078 collection (actually a vector) of the results of the applications
8082 (map-elts + (list 1 2 3) (vector 1 2 3))
8085 - Procedure: map-keys proc . collections
8086 - Procedure: do-keys proc . collections
8087 These are analogous to `map-elts' and `do-elts', but each
8088 iteration is over the COLLECTIONS' _keys_ rather than their
8092 (map-keys + (list 1 2 3) (vector 1 2 3))
8095 - Procedure: for-each-key collection proc
8096 - Procedure: for-each-elt collection proc
8097 These are like `do-keys' and `do-elts' but only for a single
8098 collection; they are potentially more efficient.
8100 - Function: reduce proc seed . collections
8101 A generalization of the list-based `comlist:reduce-init' (*note
8102 Lists as sequences::) to collections which will shadow the
8103 list-based version if `(require 'collect)' follows `(require
8104 'common-list-functions)' (*note Common List Functions::).
8107 (reduce + 0 (vector 1 2 3))
8109 (reduce union '() '((a b c) (b c d) (d a)))
8112 - Function: any? pred . collections
8113 A generalization of the list-based `some' (*note Lists as
8114 sequences::) to collections.
8117 (any? odd? (list 2 3 4 5))
8120 - Function: every? pred . collections
8121 A generalization of the list-based `every' (*note Lists as
8122 sequences::) to collections.
8125 (every? collection? '((1 2) #(1 2)))
8128 - Function: empty? collection
8129 Returns `#t' iff there are no elements in COLLECTION.
8131 `(empty? COLLECTION) == (zero? (size COLLECTION))'
8133 - Function: size collection
8134 Returns the number of elements in COLLECTION.
8136 - Function: Setter list-ref
8137 See *Note Setters:: for a definition of "setter". N.B. `(setter
8138 list-ref)' doesn't work properly for element 0 of a list.
8140 Here is a sample collection: `simple-table' which is also a `table'.
8141 (define-predicate TABLE?)
8142 (define-operation (LOOKUP table key failure-object))
8143 (define-operation (ASSOCIATE! table key value)) ;; returns key
8144 (define-operation (REMOVE! table key)) ;; returns value
8146 (define (MAKE-SIMPLE-TABLE)
8147 (let ( (table (list)) )
8151 ((SIZE self) (size table))
8152 ((PRINT self port) (format port "#<SIMPLE-TABLE>"))
8153 ((LOOKUP self key failure-object)
8155 ((assq key table) => cdr)
8156 (else failure-object)
8158 ((ASSOCIATE! self key value)
8161 => (lambda (bucket) (set-cdr! bucket value) key))
8163 (set! table (cons (cons key value) table))
8166 ((REMOVE! self key);; returns old value
8168 ((null? table) (slib:error "TABLE:REMOVE! Key not found: " key))
8169 ((eq? key (caar table))
8170 (let ( (value (cdar table)) )
8171 (set! table (cdr table))
8175 (let loop ( (last table) (this (cdr table)) )
8178 (slib:error "TABLE:REMOVE! Key not found: " key))
8179 ((eq? key (caar this))
8180 (let ( (value (cdar this)) )
8181 (set-cdr! last (cdr this))
8185 (loop (cdr last) (cdr this)))
8188 ;; collection behaviors
8189 ((COLLECTION? self) #t)
8190 ((GEN-KEYS self) (collect:list-gen-elts (map car table)))
8191 ((GEN-ELTS self) (collect:list-gen-elts (map cdr table)))
8192 ((FOR-EACH-KEY self proc)
8193 (for-each (lambda (bucket) (proc (car bucket))) table)
8195 ((FOR-EACH-ELT self proc)
8196 (for-each (lambda (bucket) (proc (cdr bucket))) table)
8201 File: slib.info, Node: Dynamic Data Type, Next: Hash Tables, Prev: Collections, Up: Data Structures
8206 `(require 'dynamic)'
8208 - Function: make-dynamic obj
8209 Create and returns a new "dynamic" whose global value is OBJ.
8211 - Function: dynamic? obj
8212 Returns true if and only if OBJ is a dynamic. No object
8213 satisfying `dynamic?' satisfies any of the other standard type
8216 - Function: dynamic-ref dyn
8217 Return the value of the given dynamic in the current dynamic
8220 - Procedure: dynamic-set! dyn obj
8221 Change the value of the given dynamic to OBJ in the current
8222 dynamic environment. The returned value is unspecified.
8224 - Function: call-with-dynamic-binding dyn obj thunk
8225 Invoke and return the value of the given thunk in a new, nested
8226 dynamic environment in which the given dynamic has been bound to a
8227 new location whose initial contents are the value OBJ. This
8228 dynamic environment has precisely the same extent as the
8229 invocation of the thunk and is thus captured by continuations
8230 created within that invocation and re-established by those
8231 continuations when they are invoked.
8233 The `dynamic-bind' macro is not implemented.
8236 File: slib.info, Node: Hash Tables, Next: Hashing, Prev: Dynamic Data Type, Up: Data Structures
8241 `(require 'hash-table)'
8243 - Function: predicate->hash pred
8244 Returns a hash function (like `hashq', `hashv', or `hash')
8245 corresponding to the equality predicate PRED. PRED should be
8246 `eq?', `eqv?', `equal?', `=', `char=?', `char-ci=?', `string=?', or
8249 A hash table is a vector of association lists.
8251 - Function: make-hash-table k
8252 Returns a vector of K empty (association) lists.
8254 Hash table functions provide utilities for an associative database.
8255 These functions take an equality predicate, PRED, as an argument. PRED
8256 should be `eq?', `eqv?', `equal?', `=', `char=?', `char-ci=?',
8257 `string=?', or `string-ci=?'.
8259 - Function: predicate->hash-asso pred
8260 Returns a hash association function of 2 arguments, KEY and
8261 HASHTAB, corresponding to PRED. The returned function returns a
8262 key-value pair whose key is PRED-equal to its first argument or
8263 `#f' if no key in HASHTAB is PRED-equal to the first argument.
8265 - Function: hash-inquirer pred
8266 Returns a procedure of 3 arguments, `hashtab' and `key', which
8267 returns the value associated with `key' in `hashtab' or `#f' if
8268 key does not appear in `hashtab'.
8270 - Function: hash-associator pred
8271 Returns a procedure of 3 arguments, HASHTAB, KEY, and VALUE, which
8272 modifies HASHTAB so that KEY and VALUE associated. Any previous
8273 value associated with KEY will be lost.
8275 - Function: hash-remover pred
8276 Returns a procedure of 2 arguments, HASHTAB and KEY, which
8277 modifies HASHTAB so that the association whose key is KEY is
8280 - Function: hash-map proc hash-table
8281 Returns a new hash table formed by mapping PROC over the keys and
8282 values of HASH-TABLE. PROC must be a function of 2 arguments
8283 which returns the new value part.
8285 - Function: hash-for-each proc hash-table
8286 Applies PROC to each pair of keys and values of HASH-TABLE. PROC
8287 must be a function of 2 arguments. The returned value is
8291 File: slib.info, Node: Hashing, Next: Object, Prev: Hash Tables, Up: Data Structures
8298 These hashing functions are for use in quickly classifying objects.
8299 Hash tables use these functions.
8301 - Function: hashq obj k
8302 - Function: hashv obj k
8303 - Function: hash obj k
8304 Returns an exact non-negative integer less than K. For each
8305 non-negative integer less than K there are arguments OBJ for which
8306 the hashing functions applied to OBJ and K returns that integer.
8308 For `hashq', `(eq? obj1 obj2)' implies `(= (hashq obj1 k) (hashq
8311 For `hashv', `(eqv? obj1 obj2)' implies `(= (hashv obj1 k) (hashv
8314 For `hash', `(equal? obj1 obj2)' implies `(= (hash obj1 k) (hash
8317 `hash', `hashv', and `hashq' return in time bounded by a constant.
8318 Notice that items having the same `hash' implies the items have
8319 the same `hashv' implies the items have the same `hashq'.
8321 `(require 'sierpinski)'
8323 - Function: make-sierpinski-indexer max-coordinate
8324 Returns a procedure (eg hash-function) of 2 numeric arguments which
8325 preserves _nearness_ in its mapping from NxN to N.
8327 MAX-COORDINATE is the maximum coordinate (a positive integer) of a
8328 population of points. The returned procedures is a function that
8329 takes the x and y coordinates of a point, (non-negative integers)
8330 and returns an integer corresponding to the relative position of
8331 that point along a Sierpinski curve. (You can think of this as
8332 computing a (pseudo-) inverse of the Sierpinski spacefilling
8335 Example use: Make an indexer (hash-function) for integer points
8336 lying in square of integer grid points [0,99]x[0,99]:
8337 (define space-key (make-sierpinski-indexer 100))
8338 Now let's compute the index of some points:
8339 (space-key 24 78) => 9206
8340 (space-key 23 80) => 9172
8342 Note that locations (24, 78) and (23, 80) are near in index and
8343 therefore, because the Sierpinski spacefilling curve is
8344 continuous, we know they must also be near in the plane. Nearness
8345 in the plane does not, however, necessarily correspond to nearness
8346 in index, although it _tends_ to be so.
8348 Example applications:
8349 * Sort points by Sierpinski index to get heuristic solution to
8350 _travelling salesman problem_. For details of performance,
8351 see L. Platzman and J. Bartholdi, "Spacefilling curves and the
8352 Euclidean travelling salesman problem", JACM 36(4):719-737
8353 (October 1989) and references therein.
8355 * Use Sierpinski index as key by which to store 2-dimensional
8356 data in a 1-dimensional data structure (such as a table).
8357 Then locations that are near each other in 2-d space will
8358 tend to be near each other in 1-d data structure; and
8359 locations that are near in 1-d data structure will be near in
8360 2-d space. This can significantly speed retrieval from
8361 secondary storage because contiguous regions in the plane
8362 will tend to correspond to contiguous regions in secondary
8363 storage. (This is a standard technique for managing CAD/CAM
8364 or geographic data.)
8367 `(require 'soundex)'
8369 - Function: soundex name
8370 Computes the _soundex_ hash of NAME. Returns a string of an
8371 initial letter and up to three digits between 0 and 6. Soundex
8372 supposedly has the property that names that sound similar in normal
8373 English pronunciation tend to map to the same key.
8375 Soundex was a classic algorithm used for manual filing of personal
8376 records before the advent of computers. It performs adequately for
8377 English names but has trouble with other languages. |
8379 See Knuth, Vol. 3 `Sorting and searching', pp 391-2
8381 To manage unusual inputs, `soundex' omits all non-alphabetic
8382 characters. Consequently, in this implementation:
8384 (soundex <string of blanks>) => ""
8387 Examples from Knuth:
8389 (map soundex '("Euler" "Gauss" "Hilbert" "Knuth"
8390 "Lloyd" "Lukasiewicz"))
8391 => ("E460" "G200" "H416" "K530" "L300" "L222")
8393 (map soundex '("Ellery" "Ghosh" "Heilbronn" "Kant"
8394 "Ladd" "Lissajous"))
8395 => ("E460" "G200" "H416" "K530" "L300" "L222")
8397 Some cases in which the algorithm fails (Knuth):
8399 (map soundex '("Rogers" "Rodgers")) => ("R262" "R326")
8401 (map soundex '("Sinclair" "St. Clair")) => ("S524" "S324")
8403 (map soundex '("Tchebysheff" "Chebyshev")) => ("T212" "C121")
8406 File: slib.info, Node: Object, Next: Priority Queues, Prev: Hashing, Up: Data Structures
8408 Macroless Object System
8409 -----------------------
8413 This is the Macroless Object System written by Wade Humeniuk
8414 (whumeniu@datap.ca). Conceptual Tributes: *Note Yasos::, MacScheme's
8415 %object, CLOS, Lack of R4RS macros.
8421 An object is an ordered association-list (by `eq?') of methods
8422 (procedures). Methods can be added (`make-method!'), deleted
8423 (`unmake-method!') and retrieved (`get-method'). Objects may
8424 inherit methods from other objects. The object binds to the
8425 environment it was created in, allowing closures to be used to
8426 hide private procedures and data.
8429 A generic-method associates (in terms of `eq?') object's method.
8430 This allows scheme function style to be used for objects. The
8431 calling scheme for using a generic method is `(generic-method
8432 object param1 param2 ...)'.
8435 A method is a procedure that exists in the object. To use a method
8436 get-method must be called to look-up the method. Generic methods
8437 implement the get-method functionality. Methods may be added to an
8438 object associated with any scheme obj in terms of eq?
8441 A generic method that returns a boolean value for any scheme obj.
8444 A object's method asscociated with a generic-predicate. Returns
8450 - Function: make-object ancestor ...
8451 Returns an object. Current object implementation is a tagged
8452 vector. ANCESTORs are optional and must be objects in terms of
8453 object?. ANCESTORs methods are included in the object. Multiple
8454 ANCESTORs might associate the same generic-method with a method.
8455 In this case the method of the ANCESTOR first appearing in the
8456 list is the one returned by `get-method'.
8458 - Function: object? obj
8459 Returns boolean value whether OBJ was created by make-object.
8461 - Function: make-generic-method exception-procedure
8462 Returns a procedure which be associated with an object's methods.
8463 If EXCEPTION-PROCEDURE is specified then it is used to process
8466 - Function: make-generic-predicate
8467 Returns a boolean procedure for any scheme object.
8469 - Function: make-method! object generic-method method
8470 Associates METHOD to the GENERIC-METHOD in the object. The METHOD
8471 overrides any previous association with the GENERIC-METHOD within
8472 the object. Using `unmake-method!' will restore the object's
8473 previous association with the GENERIC-METHOD. METHOD must be a
8476 - Function: make-predicate! object generic-preciate
8477 Makes a predicate method associated with the GENERIC-PREDICATE.
8479 - Function: unmake-method! object generic-method
8480 Removes an object's association with a GENERIC-METHOD .
8482 - Function: get-method object generic-method
8483 Returns the object's method associated (if any) with the
8484 GENERIC-METHOD. If no associated method exists an error is
8492 (define instantiate (make-generic-method))
8494 (define (make-instance-object . ancestors)
8495 (define self (apply make-object
8496 (map (lambda (obj) (instantiate obj)) ancestors)))
8497 (make-method! self instantiate (lambda (self) self))
8500 (define who (make-generic-method))
8501 (define imigrate! (make-generic-method))
8502 (define emigrate! (make-generic-method))
8503 (define describe (make-generic-method))
8504 (define name (make-generic-method))
8505 (define address (make-generic-method))
8506 (define members (make-generic-method))
8510 (define self (make-instance-object))
8511 (define population '())
8512 (make-method! self imigrate!
8513 (lambda (new-person)
8514 (if (not (eq? new-person self))
8515 (set! population (cons new-person population)))))
8516 (make-method! self emigrate!
8518 (if (not (eq? person self))
8520 (comlist:remove-if (lambda (member)
8521 (eq? member person))
8523 (make-method! self describe
8525 (map (lambda (person) (describe person)) population)))
8526 (make-method! self who
8527 (lambda (self) (map (lambda (person) (name person))
8529 (make-method! self members (lambda (self) population))
8532 (define (make-person %name %address)
8533 (define self (make-instance-object society))
8534 (make-method! self name (lambda (self) %name))
8535 (make-method! self address (lambda (self) %address))
8536 (make-method! self who (lambda (self) (name self)))
8537 (make-method! self instantiate
8539 (make-person (string-append (name self) "-son-of")
8541 (make-method! self describe
8542 (lambda (self) (list (name self) (address self))))
8546 Inverter Documentation
8547 ......................
8550 <inverter>::(<number> <description>)
8552 <inverter>::value => <number>::value
8553 <inverter>::set-value! => <number>::set-value!
8554 <inverter>::describe => <description>::describe
8557 <inverter>::inverter?
8568 <number>::set-value!
8575 (define value (make-generic-method (lambda (val) val)))
8576 (define set-value! (make-generic-method))
8577 (define invert (make-generic-method
8581 (error "Method not supported:" val)))))
8582 (define noop (make-generic-method))
8583 (define inverter? (make-generic-predicate))
8584 (define describe (make-generic-method))
8585 (define help (make-generic-method))
8587 (define (make-number x)
8588 (define self (make-object))
8589 (make-method! self value (lambda (this) x))
8590 (make-method! self set-value!
8591 (lambda (this new-value) (set! x new-value)))
8594 (define (make-description str)
8595 (define self (make-object))
8596 (make-method! self describe (lambda (this) str))
8597 (make-method! self help (lambda (this) "Help not available"))
8600 (define (make-inverter)
8601 (let* ((self (make-object
8603 (make-description "A number which can be inverted")))
8604 (<value> (get-method self value)))
8605 (make-method! self invert (lambda (self) (/ 1 (<value> self))))
8606 (make-predicate! self inverter?)
8607 (unmake-method! self help)
8608 (make-method! self help
8610 (display "Inverter Methods:") (newline)
8611 (display " (value inverter) ==> n") (newline)))
8616 (define invert! (make-generic-method))
8618 (define x (make-inverter))
8620 (make-method! x invert! (lambda (x) (set-value! x (/ 1 (value x)))))
8623 (set-value! x 33) => undefined
8624 (invert! x) => undefined
8627 (unmake-method! x invert!) => undefined
8629 (invert! x) error--> ERROR: Method not supported: x
8632 File: slib.info, Node: Priority Queues, Next: Queues, Prev: Object, Up: Data Structures
8637 `(require 'priority-queue)'
8639 - Function: make-heap pred<?
8640 Returns a binary heap suitable which can be used for priority queue
8643 - Function: heap-length heap
8644 Returns the number of elements in HEAP.
8646 - Procedure: heap-insert! heap item
8647 Inserts ITEM into HEAP. ITEM can be inserted multiple times. The
8648 value returned is unspecified.
8650 - Function: heap-extract-max! heap
8651 Returns the item which is larger than all others according to the
8652 PRED<? argument to `make-heap'. If there are no items in HEAP, an
8655 The algorithm for priority queues was taken from `Introduction to
8656 Algorithms' by T. Cormen, C. Leiserson, R. Rivest. 1989 MIT Press.
8659 File: slib.info, Node: Queues, Next: Records, Prev: Priority Queues, Up: Data Structures
8666 A "queue" is a list where elements can be added to both the front and
8667 rear, and removed from the front (i.e., they are what are often called
8668 "dequeues"). A queue may also be used like a stack.
8670 - Function: make-queue
8671 Returns a new, empty queue.
8673 - Function: queue? obj
8674 Returns `#t' if OBJ is a queue.
8676 - Function: queue-empty? q
8677 Returns `#t' if the queue Q is empty.
8679 - Procedure: queue-push! q datum
8680 Adds DATUM to the front of queue Q.
8682 - Procedure: enquque! q datum
8683 Adds DATUM to the rear of queue Q.
8685 All of the following functions raise an error if the queue Q is empty.
8687 - Function: queue-front q
8688 Returns the datum at the front of the queue Q.
8690 - Function: queue-rear q
8691 Returns the datum at the rear of the queue Q.
8693 - Prcoedure: queue-pop! q
8694 - Procedure: dequeue! q
8695 Both of these procedures remove and return the datum at the front
8696 of the queue. `queue-pop!' is used to suggest that the queue is
8697 being used like a stack.
8700 File: slib.info, Node: Records, Next: Structures, Prev: Queues, Up: Data Structures
8707 The Record package provides a facility for user to define their own
8710 - Function: make-record-type type-name field-names
8711 Returns a "record-type descriptor", a value representing a new data
8712 type disjoint from all others. The TYPE-NAME argument must be a
8713 string, but is only used for debugging purposes (such as the
8714 printed representation of a record of the new type). The
8715 FIELD-NAMES argument is a list of symbols naming the "fields" of a
8716 record of the new type. It is an error if the list contains any
8717 duplicates. It is unspecified how record-type descriptors are
8720 - Function: record-constructor rtd [field-names]
8721 Returns a procedure for constructing new members of the type
8722 represented by RTD. The returned procedure accepts exactly as
8723 many arguments as there are symbols in the given list,
8724 FIELD-NAMES; these are used, in order, as the initial values of
8725 those fields in a new record, which is returned by the constructor
8726 procedure. The values of any fields not named in that list are
8727 unspecified. The FIELD-NAMES argument defaults to the list of
8728 field names in the call to `make-record-type' that created the
8729 type represented by RTD; if the FIELD-NAMES argument is provided,
8730 it is an error if it contains any duplicates or any symbols not in
8733 - Function: record-predicate rtd
8734 Returns a procedure for testing membership in the type represented
8735 by RTD. The returned procedure accepts exactly one argument and
8736 returns a true value if the argument is a member of the indicated
8737 record type; it returns a false value otherwise.
8739 - Function: record-accessor rtd field-name
8740 Returns a procedure for reading the value of a particular field of
8741 a member of the type represented by RTD. The returned procedure
8742 accepts exactly one argument which must be a record of the
8743 appropriate type; it returns the current value of the field named
8744 by the symbol FIELD-NAME in that record. The symbol FIELD-NAME
8745 must be a member of the list of field-names in the call to
8746 `make-record-type' that created the type represented by RTD.
8748 - Function: record-modifier rtd field-name
8749 Returns a procedure for writing the value of a particular field of
8750 a member of the type represented by RTD. The returned procedure
8751 accepts exactly two arguments: first, a record of the appropriate
8752 type, and second, an arbitrary Scheme value; it modifies the field
8753 named by the symbol FIELD-NAME in that record to contain the given
8754 value. The returned value of the modifier procedure is
8755 unspecified. The symbol FIELD-NAME must be a member of the list
8756 of field-names in the call to `make-record-type' that created the
8757 type represented by RTD.
8759 In May of 1996, as a product of discussion on the `rrrs-authors'
8760 mailing list, I rewrote `record.scm' to portably implement type
8761 disjointness for record data types.
8763 As long as an implementation's procedures are opaque and the `record'
8764 code is loaded before other programs, this will give disjoint record
8765 types which are unforgeable and incorruptible by R4RS procedures.
8767 As a consequence, the procedures `record?', `record-type-descriptor',
8768 `record-type-name'.and `record-type-field-names' are no longer
8772 File: slib.info, Node: Structures, Prev: Records, Up: Data Structures
8777 `(require 'struct)' (uses defmacros)
8779 `defmacro's which implement "records" from the book `Essentials of
8780 Programming Languages' by Daniel P. Friedman, M. Wand and C.T. Haynes.
8781 Copyright 1992 Jeff Alexander, Shinnder Lee, and Lewis Patterson
8783 Matthew McDonald <mafm@cs.uwa.edu.au> added field setters.
8785 - Macro: define-record tag (var1 var2 ...)
8786 Defines several functions pertaining to record-name TAG:
8788 - Function: make-TAG var1 var2 ...
8790 - Function: TAG? obj
8792 - Function: TAG->var1 obj
8794 - Function: TAG->var2 obj
8797 - Function: set-TAG-var1! obj val
8799 - Function: set-TAG-var2! obj val
8802 Here is an example of its use.
8804 (define-record term (operator left right))
8806 (define foo (make-term 'plus 1 2))
8810 (set-term-left! foo 2345)
8815 - Macro: variant-case exp (tag (var1 var2 ...) body) ...
8816 executes the following for the matching clause:
8818 ((lambda (VAR1 VAR ...) BODY)
8820 (TAG->VAR2 EXP) ...)
8823 File: slib.info, Node: Procedures, Next: Standards Support, Prev: Data Structures, Up: Other Packages
8828 Anything that doesn't fall neatly into any of the other categories
8833 * Common List Functions:: 'common-list-functions
8834 * Tree Operations:: 'tree
8835 * Type Coercion:: 'coerce |
8836 * Chapter Ordering:: 'chapter-order
8838 * Topological Sort:: Keep your socks on.
8839 * String-Case:: 'string-case
8840 * String Ports:: 'string-port
8841 * String Search:: Also Search from a Port.
8842 * Line I/O:: 'line-i/o
8843 * Multi-Processing:: 'process
8844 * Metric Units:: Portable manifest types for numeric values. |
8847 File: slib.info, Node: Common List Functions, Next: Tree Operations, Prev: Procedures, Up: Procedures
8849 Common List Functions
8850 ---------------------
8852 `(require 'common-list-functions)'
8854 The procedures below follow the Common LISP equivalents apart from
8855 optional arguments in some cases.
8859 * List construction::
8861 * Lists as sequences::
8862 * Destructive list operations::
8863 * Non-List functions::
8866 File: slib.info, Node: List construction, Next: Lists as sets, Prev: Common List Functions, Up: Common List Functions
8871 - Function: make-list k . init
8872 `make-list' creates and returns a list of K elements. If INIT is
8873 included, all elements in the list are initialized to INIT.
8877 => (#<unspecified> #<unspecified> #<unspecified>)
8879 => (foo foo foo foo foo)
8881 - Function: list* x . y
8882 Works like `list' except that the cdr of the last pair is the last
8883 argument unless there is only one argument, when the result is
8884 just that argument. Sometimes called `cons*'. E.g.:
8894 - Function: copy-list lst
8895 `copy-list' makes a copy of LST using new pairs and returns it.
8896 Only the top level of the list is copied, i.e., pairs forming
8897 elements of the copied list remain `eq?' to the corresponding
8898 elements of the original; the copy is, however, not `eq?' to the
8899 original, but is `equal?' to it.
8902 (copy-list '(foo foo foo))
8904 (define q '(foo bar baz bang))
8908 (define r (copy-list q))
8914 (eq? bar (car (copy-list (list bar 'foo))))
8918 File: slib.info, Node: Lists as sets, Next: Lists as sequences, Prev: List construction, Up: Common List Functions
8923 `eqv?' is used to test for membership by procedures which treat lists
8926 - Function: adjoin e l
8927 `adjoin' returns the adjoint of the element E and the list L.
8928 That is, if E is in L, `adjoin' returns L, otherwise, it returns
8932 (adjoin 'baz '(bar baz bang))
8934 (adjoin 'foo '(bar baz bang))
8935 => (foo bar baz bang)
8937 - Function: union l1 l2
8938 `union' returns the combination of L1 and L2. Duplicates between
8939 L1 and L2 are culled. Duplicates within L1 or within L2 may or
8943 (union '(1 2 3 4) '(5 6 7 8))
8944 => (4 3 2 1 5 6 7 8)
8945 (union '(1 2 3 4) '(3 4 5 6))
8948 - Function: intersection l1 l2
8949 `intersection' returns all elements that are in both L1 and L2.
8952 (intersection '(1 2 3 4) '(3 4 5 6))
8954 (intersection '(1 2 3 4) '(5 6 7 8))
8957 - Function: set-difference l1 l2
8958 `set-difference' returns all elements that are in L1 but not in L2.
8961 (set-difference '(1 2 3 4) '(3 4 5 6))
8963 (set-difference '(1 2 3 4) '(1 2 3 4 5 6))
8966 - Function: member-if pred lst
8967 `member-if' returns LST if `(PRED ELEMENT)' is `#t' for any
8968 ELEMENT in LST. Returns `#f' if PRED does not apply to any
8972 (member-if vector? '(1 2 3 4))
8974 (member-if number? '(1 2 3 4))
8977 - Function: some pred lst . more-lsts
8978 PRED is a boolean function of as many arguments as there are list
8979 arguments to `some' i.e., LST plus any optional arguments. PRED
8980 is applied to successive elements of the list arguments in order.
8981 `some' returns `#t' as soon as one of these applications returns
8982 `#t', and is `#f' if none returns `#t'. All the lists should have
8986 (some odd? '(1 2 3 4))
8989 (some odd? '(2 4 6 8))
8992 (some > '(2 3) '(1 4))
8995 - Function: every pred lst . more-lsts
8996 `every' is analogous to `some' except it returns `#t' if every
8997 application of PRED is `#t' and `#f' otherwise.
9000 (every even? '(1 2 3 4))
9003 (every even? '(2 4 6 8))
9006 (every > '(2 3) '(1 4))
9009 - Function: notany pred . lst
9010 `notany' is analogous to `some' but returns `#t' if no application
9011 of PRED returns `#t' or `#f' as soon as any one does.
9013 - Function: notevery pred . lst
9014 `notevery' is analogous to `some' but returns `#t' as soon as an
9015 application of PRED returns `#f', and `#f' otherwise.
9018 (notevery even? '(1 2 3 4))
9021 (notevery even? '(2 4 6 8))
9024 - Function: list-of?? predicate |
9025 Returns a predicate which returns true if its argument is a list |
9026 every element of which satisfies PREDICATE. |
9028 - Function: list-of?? predicate low-bound high-bound |
9029 LOW-BOUND and HIGH-BOUND are non-negative integers. `list-of??' |
9030 returns a predicate which returns true if its argument is a list |
9031 of length between LOW-BOUND and HIGH-BOUND (inclusive); every |
9032 element of which satisfies PREDICATE. |
9034 - Function: list-of?? predicate bound |
9035 BOUND is an integer. If BOUND is negative, `list-of??' returns a |
9036 predicate which returns true if its argument is a list of length |
9037 greater than `(- BOUND)'; every element of which satisfies |
9038 PREDICATE. Otherwise, `list-of??' returns a predicate which |
9039 returns true if its argument is a list of length less than or |
9040 equal to BOUND; every element of which satisfies PREDICATE. |
9042 - Function: find-if pred lst
9043 `find-if' searches for the first ELEMENT in LST such that `(PRED
9044 ELEMENT)' returns `#t'. If it finds any such ELEMENT in LST,
9045 ELEMENT is returned. Otherwise, `#f' is returned.
9048 (find-if number? '(foo 1 bar 2))
9051 (find-if number? '(foo bar baz bang))
9054 (find-if symbol? '(1 2 foo bar))
9057 - Function: remove elt lst
9058 `remove' removes all occurrences of ELT from LST using `eqv?' to
9059 test for equality and returns everything that's left. N.B.: other
9060 implementations (Chez, Scheme->C and T, at least) use `equal?' as
9064 (remove 1 '(1 2 1 3 1 4 1 5))
9067 (remove 'foo '(bar baz bang))
9070 - Function: remove-if pred lst
9071 `remove-if' removes all ELEMENTs from LST where `(PRED ELEMENT)'
9072 is `#t' and returns everything that's left.
9075 (remove-if number? '(1 2 3 4))
9078 (remove-if even? '(1 2 3 4 5 6 7 8))
9081 - Function: remove-if-not pred lst
9082 `remove-if-not' removes all ELEMENTs from LST for which `(PRED
9083 ELEMENT)' is `#f' and returns everything that's left.
9086 (remove-if-not number? '(foo bar baz))
9088 (remove-if-not odd? '(1 2 3 4 5 6 7 8))
9091 - Function: has-duplicates? lst
9092 returns `#t' if 2 members of LST are `equal?', `#f' otherwise.
9095 (has-duplicates? '(1 2 3 4))
9098 (has-duplicates? '(2 4 3 4))
9101 The procedure `remove-duplicates' uses `member' (rather than `memv').
9103 - Function: remove-duplicates lst
9104 returns a copy of LST with its duplicate members removed.
9105 Elements are considered duplicate if they are `equal?'.
9108 (remove-duplicates '(1 2 3 4))
9111 (remove-duplicates '(2 4 3 4))
9115 File: slib.info, Node: Lists as sequences, Next: Destructive list operations, Prev: Lists as sets, Up: Common List Functions
9120 - Function: position obj lst
9121 `position' returns the 0-based position of OBJ in LST, or `#f' if
9122 OBJ does not occur in LST.
9125 (position 'foo '(foo bar baz bang))
9127 (position 'baz '(foo bar baz bang))
9129 (position 'oops '(foo bar baz bang))
9132 - Function: reduce p lst
9133 `reduce' combines all the elements of a sequence using a binary
9134 operation (the combination is left-associative). For example,
9135 using `+', one can add up all the elements. `reduce' allows you to
9136 apply a function which accepts only two arguments to more than 2
9137 objects. Functional programmers usually refer to this as "foldl".
9138 `collect:reduce' (*note Collections::) provides a version of
9139 `collect' generalized to collections.
9142 (reduce + '(1 2 3 4))
9144 (define (bad-sum . l) (reduce + l))
9146 == (reduce + (1 2 3 4))
9147 == (+ (+ (+ 1 2) 3) 4)
9152 (reduce string-append '("hello" "cruel" "world"))
9153 == (string-append (string-append "hello" "cruel") "world")
9154 => "hellocruelworld"
9155 (reduce anything '())
9157 (reduce anything '(x))
9160 What follows is a rather non-standard implementation of `reverse'
9161 in terms of `reduce' and a combinator elsewhere called "C".
9163 ;;; Contributed by Jussi Piitulainen (jpiitula@ling.helsinki.fi)
9172 (reduce-init (commute cons) '() args)))
9174 - Function: reduce-init p init lst
9175 `reduce-init' is the same as reduce, except that it implicitly
9176 inserts INIT at the start of the list. `reduce-init' is preferred
9177 if you want to handle the null list, the one-element, and lists
9178 with two or more elements consistently. It is common to use the
9179 operator's idempotent as the initializer. Functional programmers
9180 usually call this "foldl".
9183 (define (sum . l) (reduce-init + 0 l))
9185 == (reduce-init + 0 (1 2 3 4))
9186 == (+ (+ (+ (+ 0 1) 2) 3) 4)
9189 == (reduce-init + 0 '())
9192 (reduce-init string-append "@" '("hello" "cruel" "world"))
9194 (string-append (string-append (string-append "@" "hello")
9197 => "@hellocruelworld"
9199 Given a differentiation of 2 arguments, `diff', the following will
9200 differentiate by any number of variables.
9201 (define (diff* exp . vars)
9202 (reduce-init diff exp vars))
9205 ;;; Real-world example: Insertion sort using reduce-init.
9207 (define (insert l item)
9210 (if (< (car l) item)
9211 (cons (car l) (insert (cdr l) item))
9213 (define (insertion-sort l) (reduce-init insert '() l))
9215 (insertion-sort '(3 1 4 1 5)
9216 == (reduce-init insert () (3 1 4 1 5))
9217 == (insert (insert (insert (insert (insert () 3) 1) 4) 1) 5)
9218 == (insert (insert (insert (insert (3)) 1) 4) 1) 5)
9219 == (insert (insert (insert (1 3) 4) 1) 5)
9220 == (insert (insert (1 3 4) 1) 5)
9221 == (insert (1 1 3 4) 5)
9224 - Function: last lst n
9225 `last' returns the last N elements of LST. N must be a
9226 non-negative integer.
9229 (last '(foo bar baz bang) 2)
9234 - Function: butlast lst n
9235 `butlast' returns all but the last N elements of LST.
9238 (butlast '(a b c d) 3)
9240 (butlast '(a b c d) 4)
9243 `last' and `butlast' split a list into two parts when given identical
9245 (last '(a b c d e) 2)
9247 (butlast '(a b c d e) 2)
9250 - Function: nthcdr n lst
9251 `nthcdr' takes N `cdr's of LST and returns the result. Thus
9252 `(nthcdr 3 LST)' == `(cdddr LST)'
9255 (nthcdr 2 '(a b c d))
9257 (nthcdr 0 '(a b c d))
9260 - Function: butnthcdr n lst
9261 `butnthcdr' returns all but the nthcdr N elements of LST.
9264 (butnthcdr 3 '(a b c d))
9266 (butnthcdr 4 '(a b c d))
9269 `nthcdr' and `butnthcdr' split a list into two parts when given
9270 identical arugments.
9271 (nthcdr 2 '(a b c d e))
9273 (butnthcdr 2 '(a b c d e))
9277 File: slib.info, Node: Destructive list operations, Next: Non-List functions, Prev: Lists as sequences, Up: Common List Functions
9279 Destructive list operations
9280 ...........................
9282 These procedures may mutate the list they operate on, but any such
9283 mutation is undefined.
9285 - Procedure: nconc args
9286 `nconc' destructively concatenates its arguments. (Compare this
9287 with `append', which copies arguments rather than destroying them.)
9288 Sometimes called `append!' (*note Rev2 Procedures::).
9290 Example: You want to find the subsets of a set. Here's the
9293 (define (subsets set)
9296 (append (mapcar (lambda (sub) (cons (car set) sub))
9297 (subsets (cdr set)))
9298 (subsets (cdr set)))))
9299 But that does way more consing than you need. Instead, you could
9300 replace the `append' with `nconc', since you don't have any need
9301 for all the intermediate results.
9311 `nconc' is the same as `append!' in `sc2.scm'.
9313 - Procedure: nreverse lst
9314 `nreverse' reverses the order of elements in LST by mutating
9315 `cdr's of the list. Sometimes called `reverse!'.
9318 (define foo '(a b c))
9324 Some people have been confused about how to use `nreverse',
9325 thinking that it doesn't return a value. It needs to be pointed
9327 (set! lst (nreverse lst))
9329 is the proper usage, not
9331 The example should suffice to show why this is the case.
9333 - Procedure: delete elt lst
9334 - Procedure: delete-if pred lst
9335 - Procedure: delete-if-not pred lst
9336 Destructive versions of `remove' `remove-if', and `remove-if-not'.
9339 (define lst '(foo bar baz bang))
9343 => (foo bar baz bang)
9345 (define lst '(1 2 3 4 5 6 7 8 9))
9346 (delete-if odd? lst)
9351 Some people have been confused about how to use `delete',
9352 `delete-if', and `delete-if', thinking that they dont' return a
9353 value. It needs to be pointed out that
9354 (set! lst (delete el lst))
9356 is the proper usage, not
9358 The examples should suffice to show why this is the case.
9361 File: slib.info, Node: Non-List functions, Prev: Destructive list operations, Up: Common List Functions
9366 - Function: and? . args
9367 `and?' checks to see if all its arguments are true. If they are,
9368 `and?' returns `#t', otherwise, `#f'. (In contrast to `and', this
9369 is a function, so all arguments are always evaluated and in an
9378 - Function: or? . args
9379 `or?' checks to see if any of its arguments are true. If any is
9380 true, `or?' returns `#t', and `#f' otherwise. (To `or' as `and?'
9389 - Function: atom? object
9390 Returns `#t' if OBJECT is not a pair and `#f' if it is pair.
9391 (Called `atom' in Common LISP.)
9396 (atom? #(1 2)) ; dubious!
9400 File: slib.info, Node: Tree Operations, Next: Type Coercion, Prev: Common List Functions, Up: Procedures
9407 These are operations that treat lists a representations of trees.
9409 - Function: subst new old tree
9410 - Function: substq new old tree
9411 - Function: substv new old tree
9412 `subst' makes a copy of TREE, substituting NEW for every subtree
9413 or leaf of TREE which is `equal?' to OLD and returns a modified
9414 tree. The original TREE is unchanged, but may share parts with
9417 `substq' and `substv' are similar, but test against OLD using
9418 `eq?' and `eqv?' respectively.
9421 (substq 'tempest 'hurricane '(shakespeare wrote (the hurricane)))
9422 => (shakespeare wrote (the tempest))
9423 (substq 'foo '() '(shakespeare wrote (twelfth night)))
9424 => (shakespeare wrote (twelfth night . foo) . foo)
9425 (subst '(a . cons) '(old . pair)
9426 '((old . spice) ((old . shoes) old . pair) (old . pair)))
9427 => ((old . spice) ((old . shoes) a . cons) (a . cons))
9429 - Function: copy-tree tree
9430 Makes a copy of the nested list structure TREE using new pairs and
9431 returns it. All levels are copied, so that none of the pairs in
9432 the tree are `eq?' to the original ones - only the leaves are.
9436 (copy-tree (list bar 'foo))
9438 (eq? bar (car (copy-tree (list bar 'foo))))
9442 File: slib.info, Node: Type Coercion, Next: Chapter Ordering, Prev: Tree Operations, Up: Procedures
9447 `(require 'coerce)' |
9449 - Function: type-of obj |
9450 Returns a symbol name for the type of OBJ. |
9452 - Function: coerce obj result-type |
9453 Converts and returns OBJ of type `char', `number', `string', |
9454 `symbol', `list', or `vector' to RESULT-TYPE (which must be one of |
9458 File: slib.info, Node: Chapter Ordering, Next: Sorting, Prev: Type Coercion, Up: Procedures
9463 `(require 'chapter-order)'
9465 The `chap:' functions deal with strings which are ordered like
9466 chapter numbers (or letters) in a book. Each section of the string
9467 consists of consecutive numeric or consecutive aphabetic characters of
9470 - Function: chap:string<? string1 string2
9471 Returns #t if the first non-matching run of alphabetic upper-case
9472 or the first non-matching run of alphabetic lower-case or the first
9473 non-matching run of numeric characters of STRING1 is `string<?'
9474 than the corresponding non-matching run of characters of STRING2.
9476 (chap:string<? "a.9" "a.10") => #t
9477 (chap:string<? "4c" "4aa") => #t
9478 (chap:string<? "Revised^{3.99}" "Revised^{4}") => #t
9480 - Function: chap:string>? string1 string2
9481 - Function: chap:string<=? string1 string2
9482 - Function: chap:string>=? string1 string2
9483 Implement the corresponding chapter-order predicates.
9485 - Function: chap:next-string string
9486 Returns the next string in the _chapter order_. If STRING has no
9487 alphabetic or numeric characters, `(string-append STRING "0")' is
9488 returnd. The argument to chap:next-string will always be
9489 `chap:string<?' than the result.
9491 (chap:next-string "a.9") => "a.10"
9492 (chap:next-string "4c") => "4d"
9493 (chap:next-string "4z") => "4aa"
9494 (chap:next-string "Revised^{4}") => "Revised^{5}"
9497 File: slib.info, Node: Sorting, Next: Topological Sort, Prev: Chapter Ordering, Up: Procedures
9504 Many Scheme systems provide some kind of sorting functions. They do
9505 not, however, always provide the _same_ sorting functions, and those
9506 that I have had the opportunity to test provided inefficient ones (a
9507 common blunder is to use quicksort which does not perform well).
9509 Because `sort' and `sort!' are not in the standard, there is very
9510 little agreement about what these functions look like. For example,
9511 Dybvig says that Chez Scheme provides
9512 (merge predicate list1 list2)
9513 (merge! predicate list1 list2)
9514 (sort predicate list)
9515 (sort! predicate list)
9517 while MIT Scheme 7.1, following Common LISP, offers unstable
9518 (sort list predicate)
9521 (sort! list/vector predicate?)
9524 (sort list/vector predicate?)
9525 (sort! list/vector predicate?)
9527 Here is a comprehensive catalogue of the variations I have found.
9529 1. Both `sort' and `sort!' may be provided.
9531 2. `sort' may be provided without `sort!'.
9533 3. `sort!' may be provided without `sort'.
9535 4. Neither may be provided.
9537 5. The sequence argument may be either a list or a vector.
9539 6. The sequence argument may only be a list.
9541 7. The sequence argument may only be a vector.
9543 8. The comparison function may be expected to behave like `<'.
9545 9. The comparison function may be expected to behave like `<='.
9547 10. The interface may be `(sort predicate? sequence)'.
9549 11. The interface may be `(sort sequence predicate?)'.
9551 12. The interface may be `(sort sequence &optional (predicate? <))'.
9553 13. The sort may be stable.
9555 14. The sort may be unstable.
9557 All of this variation really does not help anybody. A nice simple
9558 merge sort is both stable and fast (quite a lot faster than _quick_
9561 I am providing this source code with no restrictions at all on its use
9562 (but please retain D.H.D.Warren's credit for the original idea). You
9563 may have to rename some of these functions in order to use them in a
9564 system which already provides incompatible or inferior sorts. For each
9565 of the functions, only the top-level define needs to be edited to do
9568 I could have given these functions names which would not clash with
9569 any Scheme that I know of, but I would like to encourage implementors to
9570 converge on a single interface, and this may serve as a hint. The
9571 argument order for all functions has been chosen to be as close to
9572 Common LISP as made sense, in order to avoid NIH-itis.
9574 Each of the five functions has a required _last_ parameter which is a
9575 comparison function. A comparison function `f' is a function of 2
9576 arguments which acts like `<'. For example,
9579 (and (f x y) (f y z)) == (f x z)
9581 The standard functions `<', `>', `char<?', `char>?', `char-ci<?',
9582 `char-ci>?', `string<?', `string>?', `string-ci<?', and `string-ci>?'
9583 are suitable for use as comparison functions. Think of `(less? x y)'
9584 as saying when `x' must _not_ precede `y'.
9586 - Function: sorted? sequence less?
9587 Returns `#t' when the sequence argument is in non-decreasing order
9588 according to LESS? (that is, there is no adjacent pair `... x y
9589 ...' for which `(less? y x)').
9591 Returns `#f' when the sequence contains at least one out-of-order
9592 pair. It is an error if the sequence is neither a list nor a
9595 - Function: merge list1 list2 less?
9596 This merges two lists, producing a completely new list as result.
9597 I gave serious consideration to producing a Common-LISP-compatible
9598 version. However, Common LISP's `sort' is our `sort!' (well, in
9599 fact Common LISP's `stable-sort' is our `sort!', merge sort is
9600 _fast_ as well as stable!) so adapting CL code to Scheme takes a
9601 bit of work anyway. I did, however, appeal to CL to determine the
9602 _order_ of the arguments.
9604 - Procedure: merge! list1 list2 less?
9605 Merges two lists, re-using the pairs of LIST1 and LIST2 to build
9606 the result. If the code is compiled, and LESS? constructs no new
9607 pairs, no pairs at all will be allocated. The first pair of the
9608 result will be either the first pair of LIST1 or the first pair of
9609 LIST2, but you can't predict which.
9611 The code of `merge' and `merge!' could have been quite a bit
9612 simpler, but they have been coded to reduce the amount of work
9613 done per iteration. (For example, we only have one `null?' test
9616 - Function: sort sequence less?
9617 Accepts either a list or a vector, and returns a new sequence
9618 which is sorted. The new sequence is the same type as the input.
9619 Always `(sorted? (sort sequence less?) less?)'. The original
9620 sequence is not altered in any way. The new sequence shares its
9621 _elements_ with the old one; no elements are copied.
9623 - Procedure: sort! sequence less?
9624 Returns its sorted result in the original boxes. If the original
9625 sequence is a list, no new storage is allocated at all. If the
9626 original sequence is a vector, the sorted elements are put back in
9629 Some people have been confused about how to use `sort!', thinking
9630 that it doesn't return a value. It needs to be pointed out that
9631 (set! slist (sort! slist <))
9633 is the proper usage, not
9636 Note that these functions do _not_ accept a CL-style `:key' argument.
9637 A simple device for obtaining the same expressiveness is to define
9638 (define (keyed less? key)
9639 (lambda (x y) (less? (key x) (key y))))
9641 and then, when you would have written
9642 (sort a-sequence #'my-less :key #'my-key)
9644 in Common LISP, just write
9645 (sort! a-sequence (keyed my-less? my-key))
9650 File: slib.info, Node: Topological Sort, Next: String-Case, Prev: Sorting, Up: Procedures
9655 `(require 'topological-sort)' or `(require 'tsort)'
9657 The algorithm is inspired by Cormen, Leiserson and Rivest (1990)
9658 `Introduction to Algorithms', chapter 23.
9660 - Function: tsort dag pred
9661 - Function: topological-sort dag pred
9664 is a list of sublists. The car of each sublist is a vertex.
9665 The cdr is the adjacency list of that vertex, i.e. a list of
9666 all vertices to which there exists an edge from the car
9670 is one of `eq?', `eqv?', `equal?', `=', `char=?',
9671 `char-ci=?', `string=?', or `string-ci=?'.
9673 Sort the directed acyclic graph DAG so that for every edge from
9674 vertex U to V, U will come before V in the resulting list of
9677 Time complexity: O (|V| + |E|)
9679 Example (from Cormen):
9680 Prof. Bumstead topologically sorts his clothing when getting
9681 dressed. The first argument to `tsort' describes which
9682 garments he needs to put on before others. (For example,
9683 Prof Bumstead needs to put on his shirt before he puts on his
9684 tie or his belt.) `tsort' gives the correct order of
9688 (tsort '((shirt tie belt)
9693 (undershorts pants shoes)
9697 (socks undershorts pants shoes watch shirt belt tie jacket)
9700 File: slib.info, Node: String-Case, Next: String Ports, Prev: Topological Sort, Up: Procedures
9705 `(require 'string-case)'
9707 - Procedure: string-upcase str
9708 - Procedure: string-downcase str
9709 - Procedure: string-capitalize str
9710 The obvious string conversion routines. These are non-destructive.
9712 - Function: string-upcase! str
9713 - Function: string-downcase! str
9714 - Function: string-captialize! str
9715 The destructive versions of the functions above.
9717 - Function: string-ci->symbol str
9718 Converts string STR to a symbol having the same case as if the
9719 symbol had been `read'.
9721 - Function: symbol-append obj1 ... |
9722 Converts OBJ1 ... to strings, appends them, and converts to a |
9723 symbol which is returned. Strings and numbers are converted to |
9724 read's symbol case; the case of symbol characters is not changed. |
9725 #f is converted to the empty string (symbol). |
9728 File: slib.info, Node: String Ports, Next: String Search, Prev: String-Case, Up: Procedures
9733 `(require 'string-port)'
9735 - Procedure: call-with-output-string proc
9736 PROC must be a procedure of one argument. This procedure calls
9737 PROC with one argument: a (newly created) output port. When the
9738 function returns, the string composed of the characters written
9739 into the port is returned.
9741 - Procedure: call-with-input-string string proc
9742 PROC must be a procedure of one argument. This procedure calls
9743 PROC with one argument: an (newly created) input port from which
9744 STRING's contents may be read. When PROC returns, the port is
9745 closed and the value yielded by the procedure PROC is returned.
9748 File: slib.info, Node: String Search, Next: Line I/O, Prev: String Ports, Up: Procedures
9753 `(require 'string-search)'
9755 - Procedure: string-index string char
9756 - Procedure: string-index-ci string char
9757 Returns the index of the first occurence of CHAR within STRING, or
9758 `#f' if the STRING does not contain a character CHAR.
9760 - Procedure: string-reverse-index string char
9761 - Procedure: string-reverse-index-ci string char
9762 Returns the index of the last occurence of CHAR within STRING, or
9763 `#f' if the STRING does not contain a character CHAR.
9765 - procedure: substring? pattern string
9766 - procedure: substring-ci? pattern string
9767 Searches STRING to see if some substring of STRING is equal to
9768 PATTERN. `substring?' returns the index of the first character of
9769 the first substring of STRING that is equal to PATTERN; or `#f' if
9770 STRING does not contain PATTERN.
9772 (substring? "rat" "pirate") => 2
9773 (substring? "rat" "outrage") => #f
9774 (substring? "" any-string) => 0
9776 - Procedure: find-string-from-port? str in-port max-no-chars
9777 Looks for a string STR within the first MAX-NO-CHARS chars of the
9780 - Procedure: find-string-from-port? str in-port
9781 When called with two arguments, the search span is limited by the
9782 end of the input stream.
9784 - Procedure: find-string-from-port? str in-port char
9785 Searches up to the first occurrence of character CHAR in STR.
9787 - Procedure: find-string-from-port? str in-port proc
9788 Searches up to the first occurrence of the procedure PROC
9789 returning non-false when called with a character (from IN-PORT)
9792 When the STR is found, `find-string-from-port?' returns the number
9793 of characters it has read from the port, and the port is set to
9794 read the first char after that (that is, after the STR) The
9795 function returns `#f' when the STR isn't found.
9797 `find-string-from-port?' reads the port _strictly_ sequentially,
9798 and does not perform any buffering. So `find-string-from-port?'
9799 can be used even if the IN-PORT is open to a pipe or other
9800 communication channel.
9802 - Function: string-subst txt old1 new1 ...
9803 Returns a copy of string TXT with all occurrences of string OLD1
9804 in TXT replaced with NEW1, OLD2 replaced with NEW2 ....
9807 File: slib.info, Node: Line I/O, Next: Multi-Processing, Prev: String Search, Up: Procedures
9812 `(require 'line-i/o)'
9814 - Function: read-line
9815 - Function: read-line port
9816 Returns a string of the characters up to, but not including a
9817 newline or end of file, updating PORT to point to the character
9818 following the newline. If no characters are available, an end of
9819 file object is returned. The PORT argument may be omitted, in
9820 which case it defaults to the value returned by
9821 `current-input-port'.
9823 - Function: read-line! string
9824 - Function: read-line! string port
9825 Fills STRING with characters up to, but not including a newline or
9826 end of file, updating the PORT to point to the last character read
9827 or following the newline if it was read. If no characters are
9828 available, an end of file object is returned. If a newline or end
9829 of file was found, the number of characters read is returned.
9830 Otherwise, `#f' is returned. The PORT argument may be omitted, in
9831 which case it defaults to the value returned by
9832 `current-input-port'.
9834 - Function: write-line string
9835 - Function: write-line string port
9836 Writes STRING followed by a newline to the given PORT and returns
9837 an unspecified value. The PORT argument may be omitted, in which
9838 case it defaults to the value returned by `current-input-port'.
9840 - Function: display-file path
9841 - Function: display-file path port
9842 Displays the contents of the file named by PATH to PORT. The PORT
9843 argument may be ommited, in which case it defaults to the value
9844 returned by `current-output-port'.
9847 File: slib.info, Node: Multi-Processing, Next: Metric Units, Prev: Line I/O, Up: Procedures
9852 `(require 'process)'
9854 This module implements asynchronous (non-polled) time-sliced
9855 multi-processing in the SCM Scheme implementation using procedures
9856 `alarm' and `alarm-interrupt'. Until this is ported to another
9857 implementation, consider it an example of writing schedulers in Scheme.
9859 - Procedure: add-process! proc
9860 Adds proc, which must be a procedure (or continuation) capable of
9861 accepting accepting one argument, to the `process:queue'. The
9862 value returned is unspecified. The argument to PROC should be
9863 ignored. If PROC returns, the process is killed.
9865 - Procedure: process:schedule!
9866 Saves the current process on `process:queue' and runs the next
9867 process from `process:queue'. The value returned is unspecified.
9869 - Procedure: kill-process!
9870 Kills the current process and runs the next process from
9871 `process:queue'. If there are no more processes on
9872 `process:queue', `(slib:exit)' is called (*note System::).
9875 File: slib.info, Node: Metric Units, Prev: Multi-Processing, Up: Procedures
9880 `(require 'metric-units)' |
9882 <http://swissnet.ai.mit.edu/~jaffer/MIXF.html> |
9884 "Metric Interchange Format" is a character string encoding for |
9885 numerical values and units which: |
9887 * is unambiguous in all locales; |
9889 * uses only [TOG] "Portable Character Set" characters matching "Basic |
9890 Latin" characters in Plane 0 of the Universal Character Set [UCS]; |
9892 * is transparent to [UTF-7] and [UTF-8] UCS transformation formats; |
9894 * is human readable and writable; |
9896 * is machine readable and writable; |
9898 * incorporates SI prefixes and units; |
9900 * incorporates [ISO 6093] numbers; and |
9902 * incorporates [IEC 60027-2] binary prefixes. |
9904 In the expression for the value of a quantity, the unit symbol is |
9905 placed after the numerical value. A dot (PERIOD, `.') is placed between |
9906 the numerical value and the unit symbol. |
9908 Within a compound unit, each of the base and derived symbols can |
9909 optionally have an attached SI prefix. |
9911 Unit symbols formed from other unit symbols by multiplication are |
9912 indicated by means of a dot (PERIOD, `.') placed between them. |
9914 Unit symbols formed from other unit symbols by division are indicated |
9915 by means of a SOLIDUS (`/') or negative exponents. The SOLIDUS must |
9916 not be repeated in the same compound unit unless contained within a |
9917 parenthesized subexpression. |
9919 The grouping formed by a prefix symbol attached to a unit symbol |
9920 constitutes a new inseparable symbol (forming a multiple or submultiple |
9921 of the unit concerned) which can be raised to a positive or negative |
9922 power and which can be combined with other unit symbols to form compound |
9925 The grouping formed by surrounding compound unit symbols with |
9926 parentheses (`(' and `)') constitutes a new inseparable symbol which |
9927 can be raised to a positive or negative power and which can be combined |
9928 with other unit symbols to form compound unit symbols. |
9930 Compound prefix symbols, that is, prefix symbols formed by the |
9931 juxtaposition of two or more prefix symbols, are not permitted. |
9933 Prefix symbols are not used with the time-related unit symbols min |
9934 (minute), h (hour), d (day). No prefix symbol may be used with dB |
9935 (decibel). Only submultiple prefix symbols may be used with the unit |
9936 symbols L (liter), Np (neper), o (degree), oC (degree Celsius), rad |
9937 (radian), and sr (steradian). Submultiple prefix symbols may not be |
9938 used with the unit symbols t (metric ton), r (revolution), or Bd (baud). |
9940 A unit exponent follows the unit, separated by a CIRCUMFLEX (`^'). |
9941 Exponents may be positive or negative. Fractional exponents must be |
9947 Factor Name Symbol | Factor Name Symbol |
9948 ====== ==== ====== | ====== ==== ====== |
9949 1e24 yotta Y | 1e-1 deci d |
9950 1e21 zetta Z | 1e-2 centi c |
9951 1e18 exa E | 1e-3 milli m |
9952 1e15 peta P | 1e-6 micro u |
9953 1e12 tera T | 1e-9 nano n |
9954 1e9 giga G | 1e-12 pico p |
9955 1e6 mega M | 1e-15 femto f |
9956 1e3 kilo k | 1e-18 atto a |
9957 1e2 hecto h | 1e-21 zepto z |
9958 1e1 deka da | 1e-24 yocto y |
9963 These binary prefixes are valid only with the units B (byte) and bit. |
9964 However, decimal prefixes can also be used with bit; and decimal |
9965 multiple (not submultiple) prefixes can also be used with B (byte). |
9967 Factor (power-of-2) Name Symbol |
9968 ====== ============ ==== ====== |
9969 1.152921504606846976e18 (2^60) exbi Ei |
9970 1.125899906842624e15 (2^50) pebi Pi |
9971 1.099511627776e12 (2^40) tebi Ti |
9972 1.073741824e9 (2^30) gibi Gi |
9973 1.048576e6 (2^20) mebi Mi |
9974 1.024e3 (2^10) kibi Ki |
9979 Type of Quantity Name Symbol Equivalent |
9980 ================ ==== ====== ========== |
9982 time minute min = 60.s |
9983 time hour h = 60.min |
9985 frequency hertz Hz s^-1 |
9986 signaling rate baud Bd s^-1 |
9988 volume liter L dm^3 |
9989 plane angle radian rad |
9990 solid angle steradian sr rad^2 |
9991 plane angle revolution * r = 6.283185307179586.rad |
9992 plane angle degree * o = 2.777777777777778e-3.r |
9993 information capacity bit bit |
9994 information capacity byte, octet B = 8.bit |
9997 mass unified atomic mass unit u = 1.66053873e-27.kg |
9998 amount of substance mole mol |
9999 catalytic activity katal kat mol/s |
10000 thermodynamic temperature kelvin K |
10001 centigrade temperature degree Celsius oC |
10002 luminous intensity candela cd |
10003 luminous flux lumen lm cd.sr |
10004 illuminance lux lx lm/m^2 |
10005 force newton N m.kg.s^-2 |
10006 pressure, stress pascal Pa N/m^2 |
10007 energy, work, heat joule J N.m |
10008 energy electronvolt eV = 1.602176462e-19.J |
10009 power, radiant flux watt W J/s |
10010 logarithm of power ratio neper Np |
10011 logarithm of power ratio decibel * dB = 0.1151293.Np |
10012 electric current ampere A |
10013 electric charge coulomb C s.A |
10014 electric potential, EMF volt V W/A |
10015 capacitance farad F C/V |
10016 electric resistance ohm Ohm V/A |
10017 electric conductance siemens S A/V |
10018 magnetic flux weber Wb V.s |
10019 magnetic flux density tesla T Wb/m^2 |
10020 inductance henry H Wb/A |
10021 radionuclide activity becquerel Bq s^-1 |
10022 absorbed dose energy gray Gy m^2.s^-2 |
10023 dose equivalent sievert Sv m^2.s^-2 |
10025 * The formulas are: |
10027 * r/rad = 8 * atan(1) |
10031 * db/Np = ln(10) / 20 |
10033 - Function: si:conversion-factor to-unit from-unit |
10034 If the strings FROM-UNIT and TO-UNIT express valid unit |
10035 expressions for quantities of the same unit-dimensions, then the |
10036 value returned by `si:conversion-factor' will be such that |
10037 multiplying a numerical value expressed in FROM-UNITs by the |
10038 returned conversion factor yields the numerical value expressed in |
10041 Otherwise, `si:conversion-factor' returns: |
10044 if neither FROM-UNIT nor TO-UNIT is a syntactically valid |
10048 if FROM-UNIT is not a syntactically valid unit. |
10051 if TO-UNIT is not a syntactically valid unit. |
10054 if linear conversion (by a factor) is not possible. |
10057 (si:conversion-factor "km/s" "m/s" ) => 0.001 |
10058 (si:conversion-factor "N" "m/s" ) => 0 |
10059 (si:conversion-factor "moC" "oC" ) => 1000 |
10060 (si:conversion-factor "mK" "oC" ) => 0 |
10061 (si:conversion-factor "rad" "o" ) => 0.0174533 |
10062 (si:conversion-factor "K" "o" ) => 0 |
10063 (si:conversion-factor "K" "K" ) => 1 |
10064 (si:conversion-factor "oK" "oK" ) => -3 |
10065 (si:conversion-factor "" "s/s" ) => 1 |
10066 (si:conversion-factor "km/h" "mph" ) => -2 |
10069 File: slib.info, Node: Standards Support, Next: Session Support, Prev: Procedures, Up: Other Packages
10076 * With-File:: 'with-file
10077 * Transcripts:: 'transcript
10078 * Rev2 Procedures:: 'rev2-procedures
10079 * Rev4 Optional Procedures:: 'rev4-optional-procedures
10080 * Multi-argument / and -:: 'multiarg/and-
10081 * Multi-argument Apply:: 'multiarg-apply
10082 * Rationalize:: 'rationalize
10083 * Promises:: 'promise
10084 * Dynamic-Wind:: 'dynamic-wind
10089 File: slib.info, Node: With-File, Next: Transcripts, Prev: Standards Support, Up: Standards Support
10094 `(require 'with-file)'
10096 - Function: with-input-from-file file thunk
10097 - Function: with-output-to-file file thunk
10098 Description found in R4RS.
10101 File: slib.info, Node: Transcripts, Next: Rev2 Procedures, Prev: With-File, Up: Standards Support
10106 `(require 'transcript)'
10108 - Function: transcript-on filename
10109 - Function: transcript-off filename
10110 Redefines `read-char', `read', `write-char', `write', `display',
10114 File: slib.info, Node: Rev2 Procedures, Next: Rev4 Optional Procedures, Prev: Transcripts, Up: Standards Support
10119 `(require 'rev2-procedures)'
10121 The procedures below were specified in the `Revised^2 Report on
10122 Scheme'. *N.B.*: The symbols `1+' and `-1+' are not `R4RS' syntax.
10123 Scheme->C, for instance, barfs on this module.
10125 - Procedure: substring-move-left! string1 start1 end1 string2 start2
10126 - Procedure: substring-move-right! string1 start1 end1 string2 start2
10127 STRING1 and STRING2 must be a strings, and START1, START2 and END1
10128 must be exact integers satisfying
10130 0 <= START1 <= END1 <= (string-length STRING1)
10131 0 <= START2 <= END1 - START1 + START2 <= (string-length STRING2)
10133 `substring-move-left!' and `substring-move-right!' store
10134 characters of STRING1 beginning with index START1 (inclusive) and
10135 ending with index END1 (exclusive) into STRING2 beginning with
10136 index START2 (inclusive).
10138 `substring-move-left!' stores characters in time order of
10139 increasing indices. `substring-move-right!' stores characters in
10140 time order of increasing indeces.
10142 - Procedure: substring-fill! string start end char
10143 Fills the elements START-END of STRING with the character CHAR.
10145 - Function: string-null? str
10146 == `(= 0 (string-length STR))'
10148 - Procedure: append! . pairs
10149 Destructively appends its arguments. Equivalent to `nconc'.
10155 Subtracts 1 from N.
10162 These are equivalent to the procedures of the same name but
10163 without the trailing `?'.
10166 File: slib.info, Node: Rev4 Optional Procedures, Next: Multi-argument / and -, Prev: Rev2 Procedures, Up: Standards Support
10168 Rev4 Optional Procedures
10169 ------------------------
10171 `(require 'rev4-optional-procedures)'
10173 For the specification of these optional procedures, *Note Standard
10174 procedures: (r4rs)Standard procedures.
10176 - Function: list-tail l p
10178 - Function: string->list s
10180 - Function: list->string l
10182 - Function: string-copy
10184 - Procedure: string-fill! s obj
10186 - Function: list->vector l
10188 - Function: vector->list s
10190 - Procedure: vector-fill! s obj
10193 File: slib.info, Node: Multi-argument / and -, Next: Multi-argument Apply, Prev: Rev4 Optional Procedures, Up: Standards Support
10195 Multi-argument / and -
10196 ----------------------
10198 `(require 'mutliarg/and-)'
10200 For the specification of these optional forms, *Note Numerical
10201 operations: (r4rs)Numerical operations. The `two-arg:'* forms are only
10202 defined if the implementation does not support the many-argument forms.
10204 - Function: two-arg:/ n1 n2
10205 The original two-argument version of `/'.
10207 - Function: / divident . divisors
10209 - Function: two-arg:- n1 n2
10210 The original two-argument version of `-'.
10212 - Function: - minuend . subtrahends
10215 File: slib.info, Node: Multi-argument Apply, Next: Rationalize, Prev: Multi-argument / and -, Up: Standards Support
10217 Multi-argument Apply
10218 --------------------
10220 `(require 'multiarg-apply)'
10222 For the specification of this optional form, *Note Control features:
10223 (r4rs)Control features.
10225 - Function: two-arg:apply proc l
10226 The implementation's native `apply'. Only defined for
10227 implementations which don't support the many-argument version.
10229 - Function: apply proc . args
10232 File: slib.info, Node: Rationalize, Next: Promises, Prev: Multi-argument Apply, Up: Standards Support
10237 `(require 'rationalize)'
10239 The procedure "rationalize" is interesting because most programming
10240 languages do not provide anything analogous to it. Thanks to Alan
10241 Bawden for contributing this algorithm.
10243 - Function: rationalize x y
10244 Computes the correct result for exact arguments (provided the
10245 implementation supports exact rational numbers of unlimited
10246 precision); and produces a reasonable answer for inexact arguments
10247 when inexact arithmetic is implemented using floating-point.
10249 `Rationalize' has limited use in implementations lacking exact
10250 (non-integer) rational numbers. The following procedures return a list
10251 of the numerator and denominator.
10253 - Function: find-ratio x y
10254 `find-ratio' returns the list of the _simplest_ numerator and
10255 denominator whose quotient differs from X by no more than Y.
10257 (find-ratio 3/97 .0001) => (3 97) |
10258 (find-ratio 3/97 .001) => (1 32) |
10260 - Function: find-ratio-between x y
10261 `find-ratio-between' returns the list of the _simplest_ numerator
10262 and denominator between X and Y.
10264 (find-ratio-between 2/7 3/5) => (1 2) |
10265 (find-ratio-between -3/5 -2/7) => (-1 2) |
10268 File: slib.info, Node: Promises, Next: Dynamic-Wind, Prev: Rationalize, Up: Standards Support
10273 `(require 'promise)'
10275 - Function: make-promise proc
10277 Change occurrences of `(delay EXPRESSION)' to `(make-promise (lambda
10278 () EXPRESSION))' and `(define force promise:force)' to implement
10279 promises if your implementation doesn't support them (*note Control
10280 features: (r4rs)Control features.).
10283 File: slib.info, Node: Dynamic-Wind, Next: Eval, Prev: Promises, Up: Standards Support
10288 `(require 'dynamic-wind)'
10290 This facility is a generalization of Common LISP `unwind-protect',
10291 designed to take into account the fact that continuations produced by
10292 `call-with-current-continuation' may be reentered.
10294 - Procedure: dynamic-wind thunk1 thunk2 thunk3
10295 The arguments THUNK1, THUNK2, and THUNK3 must all be procedures of
10296 no arguments (thunks).
10298 `dynamic-wind' calls THUNK1, THUNK2, and then THUNK3. The value
10299 returned by THUNK2 is returned as the result of `dynamic-wind'.
10300 THUNK3 is also called just before control leaves the dynamic
10301 context of THUNK2 by calling a continuation created outside that
10302 context. Furthermore, THUNK1 is called before reentering the
10303 dynamic context of THUNK2 by calling a continuation created inside
10304 that context. (Control is inside the context of THUNK2 if THUNK2
10305 is on the current return stack).
10307 *Warning:* There is no provision for dealing with errors or
10308 interrupts. If an error or interrupt occurs while using
10309 `dynamic-wind', the dynamic environment will be that in effect at
10310 the time of the error or interrupt.
10313 File: slib.info, Node: Eval, Next: Values, Prev: Dynamic-Wind, Up: Standards Support
10320 - Function: eval expression environment-specifier
10321 Evaluates EXPRESSION in the specified environment and returns its
10322 value. EXPRESSION must be a valid Scheme expression represented
10323 as data, and ENVIRONMENT-SPECIFIER must be a value returned by one
10324 of the three procedures described below. Implementations may
10325 extend `eval' to allow non-expression programs (definitions) as
10326 the first argument and to allow other values as environments, with
10327 the restriction that `eval' is not allowed to create new bindings
10328 in the environments associated with `null-environment' or
10329 `scheme-report-environment'.
10331 (eval '(* 7 3) (scheme-report-environment 5))
10334 (let ((f (eval '(lambda (f x) (f x x))
10335 (null-environment))))
10339 - Function: scheme-report-environment version
10340 - Function: null-environment version
10341 - Function: null-environment
10342 VERSION must be an exact non-negative integer N corresponding to a
10343 version of one of the Revised^N Reports on Scheme.
10344 `Scheme-report-environment' returns a specifier for an environment
10345 that contains the set of bindings specified in the corresponding
10346 report that the implementation supports. `Null-environment'
10347 returns a specifier for an environment that contains only the
10348 (syntactic) bindings for all the syntactic keywords defined in the
10349 given version of the report.
10351 Not all versions may be available in all implementations at all
10352 times. However, an implementation that conforms to version N of
10353 the Revised^N Reports on Scheme must accept version N. An error
10354 is signalled if the specified version is not available.
10356 The effect of assigning (through the use of `eval') a variable
10357 bound in a `scheme-report-environment' (for example `car') is
10358 unspecified. Thus the environments specified by
10359 `scheme-report-environment' may be immutable.
10362 - Function: interaction-environment
10363 This optional procedure returns a specifier for the environment
10364 that contains implementation-defined bindings, typically a
10365 superset of those listed in the report. The intent is that this
10366 procedure will return the environment in which the implementation
10367 would evaluate expressions dynamically typed by the user.
10369 Here are some more `eval' examples:
10373 (define car 'volvo)
10377 (eval 'car (interaction-environment))
10379 (eval 'car (scheme-report-environment 5))
10380 => #<primitive-procedure car>
10381 (eval '(eval 'car (interaction-environment))
10382 (scheme-report-environment 5))
10384 (eval '(eval '(set! car 'buick) (interaction-environment))
10385 (scheme-report-environment 5))
10389 (eval 'car (scheme-report-environment 5))
10390 => #<primitive-procedure car>
10391 (eval '(eval 'car (interaction-environment))
10392 (scheme-report-environment 5))
10396 File: slib.info, Node: Values, Prev: Eval, Up: Standards Support
10401 `(require 'values)'
10403 - Function: values obj ...
10404 `values' takes any number of arguments, and passes (returns) them
10405 to its continuation.
10407 - Function: call-with-values thunk proc
10408 THUNK must be a procedure of no arguments, and PROC must be a
10409 procedure. `call-with-values' calls THUNK with a continuation
10410 that, when passed some values, calls PROC with those values as
10413 Except for continuations created by the `call-with-values'
10414 procedure, all continuations take exactly one value, as now; the
10415 effect of passing no value or more than one value to continuations
10416 that were not created by the `call-with-values' procedure is
10420 File: slib.info, Node: Session Support, Next: Extra-SLIB Packages, Prev: Standards Support, Up: Other Packages
10427 * Repl:: Macros at top-level
10428 * Quick Print:: Loop-safe Output
10429 * Debug:: To err is human ...
10430 * Breakpoints:: Pause execution
10432 * System Interface:: 'system, 'getenv, and 'net-clients
10435 File: slib.info, Node: Repl, Next: Quick Print, Prev: Session Support, Up: Session Support
10442 Here is a read-eval-print-loop which, given an eval, evaluates forms.
10444 - Procedure: repl:top-level repl:eval
10445 `read's, `repl:eval's and `write's expressions from
10446 `(current-input-port)' to `(current-output-port)' until an
10447 end-of-file is encountered. `load', `slib:eval', `slib:error',
10448 and `repl:quit' dynamically bound during `repl:top-level'.
10450 - Procedure: repl:quit
10451 Exits from the invocation of `repl:top-level'.
10453 The `repl:' procedures establish, as much as is possible to do
10454 portably, a top level environment supporting macros. `repl:top-level'
10455 uses `dynamic-wind' to catch error conditions and interrupts. If your
10456 implementation supports this you are all set.
10458 Otherwise, if there is some way your implementation can catch error
10459 conditions and interrupts, then have them call `slib:error'. It will
10460 display its arguments and reenter `repl:top-level'. `slib:error'
10461 dynamically bound by `repl:top-level'.
10463 To have your top level loop always use macros, add any interrupt
10464 catching lines and the following lines to your Scheme init file:
10467 (repl:top-level macro:eval)
10470 File: slib.info, Node: Quick Print, Next: Debug, Prev: Repl, Up: Session Support
10477 When displaying error messages and warnings, it is paramount that the
10478 output generated for circular lists and large data structures be
10479 limited. This section supplies a procedure to do this. It could be
10482 Notice that the neccessity for truncating output eliminates
10483 Common-Lisp's *Note Format:: from consideration; even when
10484 variables `*print-level*' and `*print-level*' are set, huge
10485 strings and bit-vectors are _not_ limited.
10487 - Procedure: qp arg1 ...
10488 - Procedure: qpn arg1 ...
10489 - Procedure: qpr arg1 ...
10490 `qp' writes its arguments, separated by spaces, to
10491 `(current-output-port)'. `qp' compresses printing by substituting
10492 `...' for substructure it does not have sufficient room to print.
10493 `qpn' is like `qp' but outputs a newline before returning. `qpr'
10494 is like `qpn' except that it returns its last argument.
10496 - Variable: *qp-width*
10497 `*qp-width*' is the largest number of characters that `qp' should
10501 File: slib.info, Node: Debug, Next: Breakpoints, Prev: Quick Print, Up: Session Support
10508 Requiring `debug' automatically requires `trace' and `break'.
10510 An application with its own datatypes may want to substitute its own
10511 printer for `qp'. This example shows how to do this:
10513 (define qpn (lambda args) ...)
10517 - Procedure: trace-all file ...
10518 Traces (*note Trace::) all procedures `define'd at top-level in
10521 - Procedure: track-all file ...
10522 Tracks (*note Trace::) all procedures `define'd at top-level in
10525 - Procedure: stack-all file ...
10526 Stacks (*note Trace::) all procedures `define'd at top-level in
10529 - Procedure: break-all file ...
10530 Breakpoints (*note Breakpoints::) all procedures `define'd at
10531 top-level in `file' ....
10534 File: slib.info, Node: Breakpoints, Next: Trace, Prev: Debug, Up: Session Support
10541 - Function: init-debug
10542 If your Scheme implementation does not support `break' or `abort',
10543 a message will appear when you `(require 'break)' or `(require
10544 'debug)' telling you to type `(init-debug)'. This is in order to
10545 establish a top-level continuation. Typing `(init-debug)' at top
10546 level sets up a continuation for `break'.
10548 - Function: breakpoint arg1 ...
10549 Returns from the top level continuation and pushes the
10550 continuation from which it was called on a continuation stack.
10552 - Function: continue
10553 Pops the topmost continuation off of the continuation stack and
10554 returns an unspecified value to it.
10556 - Function: continue arg1 ...
10557 Pops the topmost continuation off of the continuation stack and
10558 returns ARG1 ... to it.
10560 - Macro: break proc1 ...
10561 Redefines the top-level named procedures given as arguments so that
10562 `breakpoint' is called before calling PROC1 ....
10565 With no arguments, makes sure that all the currently broken
10566 identifiers are broken (even if those identifiers have been
10567 redefined) and returns a list of the broken identifiers.
10569 - Macro: unbreak proc1 ...
10570 Turns breakpoints off for its arguments.
10573 With no arguments, unbreaks all currently broken identifiers and
10574 returns a list of these formerly broken identifiers.
10576 These are _procedures_ for breaking. If defmacros are not natively
10577 supported by your implementation, these might be more convenient to use.
10579 - Function: breakf proc
10580 - Function: breakf proc name
10582 (set! SYMBOL (breakf SYMBOL))
10585 (set! SYMBOL (breakf SYMBOL 'SYMBOL))
10588 (define SYMBOL (breakf FUNCTION))
10591 (define SYMBOL (breakf FUNCTION 'SYMBOL))
10593 - Function: unbreakf proc
10595 (set! SYMBOL (unbreakf SYMBOL))
10598 File: slib.info, Node: Trace, Next: System Interface, Prev: Breakpoints, Up: Session Support
10605 This feature provides three ways to monitor procedure invocations:
10608 Pushes the procedure-name when the procedure is called; pops when
10612 Pushes the procedure-name and arguments when the procedure is
10613 called; pops when it returns.
10616 Pushes the procedure-name and prints `CALL PROCEDURE-NAME ARG1
10617 ...' when the procdure is called; pops and prints `RETN
10618 PROCEDURE-NAME VALUE' when the procedure returns.
10620 - Variable: debug:max-count
10621 If a traced procedure calls itself or untraced procedures which
10622 call it, stack, track, and trace will limit the number of stack
10623 pushes to DEBUG:MAX-COUNT.
10625 - Function: print-call-stack
10626 - Function: print-call-stack port
10627 Prints the call-stack to PORT or the current-error-port.
10629 - Macro: trace proc1 ...
10630 Traces the top-level named procedures given as arguments.
10633 With no arguments, makes sure that all the currently traced
10634 identifiers are traced (even if those identifiers have been
10635 redefined) and returns a list of the traced identifiers.
10637 - Macro: track proc1 ...
10638 Traces the top-level named procedures given as arguments.
10641 With no arguments, makes sure that all the currently tracked
10642 identifiers are tracked (even if those identifiers have been
10643 redefined) and returns a list of the tracked identifiers.
10645 - Macro: stack proc1 ...
10646 Traces the top-level named procedures given as arguments.
10649 With no arguments, makes sure that all the currently stacked
10650 identifiers are stacked (even if those identifiers have been
10651 redefined) and returns a list of the stacked identifiers.
10653 - Macro: untrace proc1 ...
10654 Turns tracing, tracking, and off for its arguments.
10657 With no arguments, untraces all currently traced identifiers and
10658 returns a list of these formerly traced identifiers.
10660 - Macro: untrack proc1 ...
10661 Turns tracing, tracking, and off for its arguments.
10664 With no arguments, untracks all currently tracked identifiers and
10665 returns a list of these formerly tracked identifiers.
10667 - Macro: unstack proc1 ...
10668 Turns tracing, stacking, and off for its arguments.
10671 With no arguments, unstacks all currently stacked identifiers and
10672 returns a list of these formerly stacked identifiers.
10674 These are _procedures_ for tracing. If defmacros are not natively
10675 supported by your implementation, these might be more convenient to use.
10677 - Function: tracef proc
10678 - Function: tracef proc name
10680 (set! SYMBOL (tracef SYMBOL))
10683 (set! SYMBOL (tracef SYMBOL 'SYMBOL))
10686 (define SYMBOL (tracef FUNCTION))
10689 (define SYMBOL (tracef FUNCTION 'SYMBOL))
10691 - Function: untracef proc
10692 Removes tracing, tracking, or stacking for PROC. To untrace, type
10693 (set! SYMBOL (untracef SYMBOL))
10696 File: slib.info, Node: System Interface, Prev: Trace, Up: Session Support
10701 If `(provided? 'getenv)':
10703 - Function: getenv name
10704 Looks up NAME, a string, in the program environment. If NAME is
10705 found a string of its value is returned. Otherwise, `#f' is
10708 If `(provided? 'system)':
10710 - Function: system command-string
10711 Executes the COMMAND-STRING on the computer and returns the
10712 integer status code.
10714 If `system' is provided by the Scheme implementation, the "net-clients"
10715 package provides interfaces to common network client programs like FTP,
10716 mail, and Netscape.
10718 `(require 'net-clients)'
10720 - Function: call-with-tmpnam proc
10721 - Function: call-with-tmpnam proc k
10722 Calls PROC with K arguments, strings returned by successive calls
10723 to `tmpnam'. If PROC returns, then any files named by the
10724 arguments to PROC are deleted automatically and the value(s)
10725 yielded by the PROC is(are) returned. K may be ommited, in which
10726 case it defaults to `1'.
10728 - Function: user-email-address
10729 `user-email-address' returns a string of the form
10730 `username@hostname'. If this e-mail address cannot be obtained,
10733 - Function: current-directory
10734 `current-directory' returns a string containing the absolute file
10735 name representing the current working directory. If this string
10736 cannot be obtained, #f is returned.
10738 If `current-directory' cannot be supported by the platform, the
10739 value of `current-directory' is #f.
10741 - Function: make-directory name
10742 Creates a sub-directory NAME of the current-directory. If
10743 successful, `make-directory' returns #t; otherwise #f.
10745 - Function: null-directory? file-name
10746 Returns #t if changing directory to FILE-NAME makes the current
10747 working directory the same as it is before changing directory;
10748 otherwise returns #f.
10750 - Function: absolute-path? file-name
10751 Returns #t if FILE-NAME is a fully specified pathname (does not
10752 depend on the current working directory); otherwise returns #f.
10754 - Function: glob-pattern? str
10755 Returns #t if the string STR contains characters used for
10756 specifying glob patterns, namely `*', `?', or `['.
10758 - Function: parse-ftp-address uri |
10759 Returns a list of the decoded FTP URI; or #f if indecipherable. |
10760 FTP "Uniform Resource Locator", "ange-ftp", and "getit" formats
10761 are handled. The returned list has four elements which are
10770 3. remote-directory
10772 - Function: ftp-upload paths user password remote-site remote-dir
10773 PASSWORD must be a non-empty string or #f. PATHS must be a
10774 non-empty list of pathnames or Glob patterns (*note Filenames::)
10775 matching files to transfer.
10777 `ftp-upload' puts the files specified by PATHS into the REMOTE-DIR
10778 directory of FTP REMOTE-SITE using name USER with (optional)
10781 If PASSWORD is #f and USER is not `ftp' or `anonymous', then USER
10782 is ignored; FTP takes the username and password from the `.netrc'
10783 or equivalent file.
10785 - Function: path->uri path |
10786 Returns a URI-string for PATH on the local host. |
10788 - Function: browse-url-netscape url
10789 If a `netscape' browser is running, `browse-url-netscape' causes
10790 the browser to display the page specified by string URL and
10793 If the browser is not running, `browse-url-netscape' runs
10794 `netscape' with the argument URL. If the browser starts as a
10795 background job, `browse-url-netscape' returns #t immediately; if
10796 the browser starts as a foreground job, then `browse-url-netscape'
10797 returns #t when the browser exits; otherwise it returns #f.
10800 File: slib.info, Node: Extra-SLIB Packages, Prev: Session Support, Up: Other Packages
10802 Extra-SLIB Packages
10803 ===================
10805 Several Scheme packages have been written using SLIB. There are
10806 several reasons why a package might not be included in the SLIB
10808 * Because it requires special hardware or software which is not
10811 * Because it is large and of limited interest to most Scheme users.
10813 * Because it has copying terms different enough from the other SLIB
10814 packages that its inclusion would cause confusion.
10816 * Because it is an application program, rather than a library module.
10818 * Because I have been too busy to integrate it.
10820 Once an optional package is installed (and an entry added to
10821 `*catalog*', the `require' mechanism allows it to be called up and used
10822 as easily as any other SLIB package. Some optional packages (for which
10823 `*catalog*' already has entries) available from SLIB sites are:
10826 is a portable debugger for Scheme (requires emacs editor).
10828 http://swissnet.ai.mit.edu/ftpdir/scm/slib-psd1-3.tar.gz
10830 swissnet.ai.mit.edu:/pub/scm/slib-psd1-3.tar.gz
10832 ftp.maths.tcd.ie:pub/bosullvn/jacal/slib-psd1-3.tar.gz
10834 ftp.cs.indiana.edu:/pub/scheme-repository/utl/slib-psd1-3.tar.gz
10837 With PSD, you can run a Scheme program in an Emacs buffer, set
10838 breakpoints, single step evaluation and access and modify the
10839 program's variables. It works by instrumenting the original source
10840 code, so it should run with any R4RS compliant Scheme. It has been
10841 tested with SCM, Elk 1.5, and the sci interpreter in the Scheme->C
10842 system, but should work with other Schemes with a minimal amount
10843 of porting, if at all. Includes documentation and user's manual.
10844 Written by Pertti Kellom\"aki, pk@cs.tut.fi. The Lisp Pointers
10845 article describing PSD (Lisp Pointers VI(1):15-23, January-March
10846 1993) is available as
10847 http://www.cs.tut.fi/staff/pk/scheme/psd/article/article.html
10851 is an embedding of Prolog in Scheme.
10852 http://www.cs.rice.edu/CS/PLT/packages/schelog/
10856 is a Scheme program which converts text among the JIS, EUC, and
10857 Shift-JIS Japanese character sets.
10858 http://www.sci.toyama-u.ac.jp/~iwao/Scheme/Jfilter/index.html
10861 File: slib.info, Node: About SLIB, Next: Index, Prev: Other Packages, Up: Top
10866 More people than I can name have contributed to SLIB. Thanks to all of
10869 SLIB 2d1, released March 2001. |
10870 Aubrey Jaffer <jaffer @ ai.mit.edu>
10871 Hyperactive Software - The Maniac Inside!
10872 <http://swissnet.ai.mit.edu/~jaffer/SLIB.html>
10876 * Installation:: How to install SLIB on your system.
10877 * Porting:: SLIB to new platforms.
10878 * Coding Guidelines:: How to write modules for SLIB.
10879 * Copyrights:: Intellectual propery issues.
10882 File: slib.info, Node: Installation, Next: Porting, Prev: About SLIB, Up: About SLIB
10887 Check the manifest in `README' to find a configuration file for your
10888 Scheme implementation. Initialization files for most IEEE P1178
10889 compliant Scheme Implementations are included with this distribution.
10891 If the Scheme implementation supports `getenv', then the value of the
10892 shell environment variable SCHEME_LIBRARY_PATH will be used for
10893 `(library-vicinity)' if it is defined. Currently, Chez, Elk,
10894 MITScheme, scheme->c, VSCM, and SCM support `getenv'. Scheme48
10895 supports `getenv' but does not use it for determining
10896 `library-vicinity'. (That is done from the Makefile.)
10898 You should check the definitions of `software-type',
10899 `scheme-implementation-version', `implementation-vicinity', and
10900 `library-vicinity' in the initialization file. There are comments in
10901 the file for how to configure it.
10903 Once this is done you can modify the startup file for your Scheme
10904 implementation to `load' this initialization file. SLIB is then
10907 Multiple implementations of Scheme can all use the same SLIB
10908 directory. Simply configure each implementation's initialization file
10911 - Implementation: SCM
10912 The SCM implementation does not require any initialization file as
10913 SLIB support is already built into SCM. See the documentation
10914 with SCM for installation instructions.
10916 - Implementation: VSCM
10917 From: Matthias Blume <blume@cs.Princeton.EDU>
10918 Date: Tue, 1 Mar 1994 11:42:31 -0500
10920 Disclaimer: The code below is only a quick hack. If I find some
10921 time to spare I might get around to make some more things work.
10923 You have to provide `vscm.init' as an explicit command line
10924 argument. Since this is not very nice I would recommend the
10925 following installation procedure:
10929 2. `(load "vscm.init")'
10931 3. `(slib:dump "dumpfile")'
10933 4. mv dumpfile place-where-vscm-standard-bootfile-resides e.g.
10934 mv dumpfile /usr/local/vscm/lib/scheme-boot (In this case
10935 vscm should have been compiled with flag
10936 -DDEFAULT_BOOTFILE='"/usr/local/vscm/lib/scheme-boot"'. See
10937 Makefile (definition of DDP) for details.)
10940 - Implementation: Scheme48
10941 To make a Scheme48 image for an installation under `<prefix>',
10943 1. `cd' to the SLIB directory
10945 2. type `make prefix=<prefix> slib48'.
10947 3. To install the image, type `make prefix=<prefix> install48'.
10948 This will also create a shell script with the name `slib48'
10949 which will invoke the saved image.
10951 - Implementation: PLT Scheme
10952 - Implementation: DrScheme
10953 - Implementation: MzScheme
10954 Date: Mon, 2 Oct 2000 21:29:48 -0400 (EDT)
10955 From: Shriram Krishnamurthi <sk@cs.brown.edu>
10957 We distribute an SLIB init file for our system. If you have PLT
10958 Scheme (our preferred name for the entire suite, which includes
10959 DrScheme, MzScheme and other implementations) installed, you ought
10960 to be able to run "help-desk", or run `drscheme' and choose Help
10961 Desk from the Help menu; in Help Desk, type `slib'. This will give
10962 instructions for how to load the SLIB init file.
10965 File: slib.info, Node: Porting, Next: Coding Guidelines, Prev: Installation, Up: About SLIB
10970 If there is no initialization file for your Scheme implementation, you
10971 will have to create one. Your Scheme implementation must be largely
10972 compliant with `IEEE Std 1178-1990', `Revised^4 Report on the
10973 Algorithmic Language Scheme', or `Revised^5 Report on the Algorithmic
10974 Language Scheme' in order to support SLIB. (1)
10976 `Template.scm' is an example configuration file. The comments inside
10977 will direct you on how to customize it to reflect your system. Give
10978 your new initialization file the implementation's name with `.init'
10979 appended. For instance, if you were porting `foo-scheme' then the
10980 initialization file might be called `foo.init'.
10982 Your customized version should then be loaded as part of your scheme
10983 implementation's initialization. It will load `require.scm' from the
10984 library; this will allow the use of `provide', `provided?', and
10985 `require' along with the "vicinity" functions (these functions are
10986 documented in the section *Note Require::). The rest of the library
10987 will then be accessible in a system independent fashion.
10989 Please mail new working configuration files to `jaffer @ ai.mit.edu'
10990 so that they can be included in the SLIB distribution.
10992 ---------- Footnotes ----------
10994 (1) If you are porting a `Revised^3 Report on the Algorithmic
10995 Language Scheme' implementation, then you will need to finish writing
10996 `sc4sc3.scm' and `load' it from your initialization file.
10999 File: slib.info, Node: Coding Guidelines, Next: Copyrights, Prev: Porting, Up: About SLIB
11004 All library packages are written in IEEE P1178 Scheme and assume that
11005 a configuration file and `require.scm' package have already been
11006 loaded. Other versions of Scheme can be supported in library packages
11007 as well by using, for example, `(provided? 'rev3-report)' or `(require
11008 'rev3-report)' (*note Require::).
11010 The module name and `:' should prefix each symbol defined in the
11011 package. Definitions for external use should then be exported by having
11012 `(define foo module-name:foo)'.
11014 Code submitted for inclusion in SLIB should not duplicate routines
11015 already in SLIB files. Use `require' to force those library routines
11016 to be used by your package. Care should be taken that there are no
11017 circularities in the `require's and `load's between the library
11020 Documentation should be provided in Emacs Texinfo format if possible,
11021 But documentation must be provided.
11023 Your package will be released sooner with SLIB if you send me a file
11024 which tests your code. Please run this test _before_ you send me the
11030 Please document your changes. A line or two for `ChangeLog' is
11031 sufficient for simple fixes or extensions. Look at the format of
11032 `ChangeLog' to see what information is desired. Please send me `diff'
11033 files from the latest SLIB distribution (remember to send `diff's of
11034 `slib.texi' and `ChangeLog'). This makes for less email traffic and
11035 makes it easier for me to integrate when more than one person is
11036 changing a file (this happens a lot with `slib.texi' and `*.init'
11039 If someone else wrote a package you want to significantly modify,
11040 please try to contact the author, who may be working on a new version.
11041 This will insure against wasting effort on obsolete versions.
11043 Please _do not_ reformat the source code with your favorite
11044 beautifier, make 10 fixes, and send me the resulting source code. I do
11045 not have the time to fish through 10000 diffs to find your 10 real
11049 File: slib.info, Node: Copyrights, Prev: Coding Guidelines, Up: About SLIB
11054 This section has instructions for SLIB authors regarding copyrights.
11056 Each package in SLIB must either be in the public domain, or come
11057 with a statement of terms permitting users to copy, redistribute and
11058 modify it. The comments at the beginning of `require.scm' and
11059 `macwork.scm' illustrate copyright and appropriate terms.
11061 If your code or changes amount to less than about 10 lines, you do not
11062 need to add your copyright or send a disclaimer.
11064 Putting code into the Public Domain
11065 -----------------------------------
11067 In order to put code in the public domain you should sign a copyright
11068 disclaimer and send it to the SLIB maintainer. Contact jaffer @
11069 ai.mit.edu for the address to mail the disclaimer to.
11071 I, NAME, hereby affirm that I have placed the software package
11072 NAME in the public domain.
11074 I affirm that I am the sole author and sole copyright holder for
11075 the software package, that I have the right to place this software
11076 package in the public domain, and that I will do nothing to
11077 undermine this status in the future.
11081 This wording assumes that you are the sole author. If you are not the
11082 sole author, the wording needs to be different. If you don't want to be
11083 bothered with sending a letter every time you release or modify a
11084 module, make your letter say that it also applies to your future
11085 revisions of that module.
11087 Make sure no employer has any claim to the copyright on the work you
11088 are submitting. If there is any doubt, create a copyright disclaimer
11089 and have your employer sign it. Mail the signed disclaimer to the SLIB
11090 maintainer. Contact jaffer @ ai.mit.edu for the address to mail the
11091 disclaimer to. An example disclaimer follows.
11093 Explicit copying terms
11094 ----------------------
11096 If you submit more than about 10 lines of code which you are not placing
11097 into the Public Domain (by sending me a disclaimer) you need to:
11099 * Arrange that your name appears in a copyright line for the
11100 appropriate year. Multiple copyright lines are acceptable.
11102 * With your copyright line, specify any terms you require to be
11103 different from those already in the file.
11105 * Make sure no employer has any claim to the copyright on the work
11106 you are submitting. If there is any doubt, create a copyright
11107 disclaimer and have your employer sign it. Mail the signed
11108 disclaim to the SLIB maintainer. Contact jaffer @ ai.mit.edu for
11109 the address to mail the disclaimer to.
11111 Example: Company Copyright Disclaimer
11112 -------------------------------------
11114 This disclaimer should be signed by a vice president or general
11115 manager of the company. If you can't get at them, anyone else
11116 authorized to license out software produced there will do. Here is a
11119 EMPLOYER Corporation hereby disclaims all copyright interest in
11120 the program PROGRAM written by NAME.
11122 EMPLOYER Corporation affirms that it has no other intellectual
11123 property interest that would undermine this release, and will do
11124 nothing to undermine it in the future.
11126 SIGNATURE AND DATE,
11127 NAME, TITLE, EMPLOYER Corporation
11130 File: slib.info, Node: Index, Prev: About SLIB, Up: Top
11132 Procedure and Macro Index
11133 *************************
11135 This is an alphabetical list of all the procedures and macros in SLIB.
11139 * -: Multi-argument / and -.
11140 * -1+: Rev2 Procedures.
11141 * /: Multi-argument / and -.
11142 * 1+: Rev2 Procedures.
11143 * <=?: Rev2 Procedures.
11144 * <?: Rev2 Procedures.
11145 * =?: Rev2 Procedures.
11146 * >=?: Rev2 Procedures.
11147 * >?: Rev2 Procedures.
11148 * absolute-path?: System Interface.
11149 * add-domain: Database Utilities.
11150 * add-process!: Multi-Processing.
11151 * add-setter: Setters.
11152 * adjoin: Lists as sets.
11153 * adjoin-parameters!: Parameter lists.
11154 * alarm: Multi-Processing.
11155 * alarm-interrupt: Multi-Processing.
11156 * alist->wt-tree: Construction of Weight-Balanced Trees.
11157 * alist-associator: Association Lists.
11158 * alist-for-each: Association Lists.
11159 * alist-inquirer: Association Lists.
11160 * alist-map: Association Lists.
11161 * alist-remover: Association Lists.
11162 * and?: Non-List functions.
11163 * any?: Collections.
11164 * append!: Rev2 Procedures.
11165 * apply: Multi-argument Apply.
11166 * array-1d-ref: Arrays.
11167 * array-1d-set!: Arrays.
11168 * array-2d-ref: Arrays.
11169 * array-2d-set!: Arrays.
11170 * array-3d-ref: Arrays.
11171 * array-3d-set!: Arrays.
11172 * array-copy!: Array Mapping.
11173 * array-dimensions: Arrays.
11174 * array-for-each: Array Mapping.
11175 * array-in-bounds?: Arrays.
11176 * array-index-map!: Array Mapping.
11177 * array-indexes: Array Mapping.
11178 * array-map!: Array Mapping.
11179 * array-rank: Arrays.
11180 * array-ref: Arrays.
11181 * array-set!: Arrays.
11182 * array-shape: Arrays.
11184 * asctime: Posix Time.
11185 * ash: Bit-Twiddling.
11186 * atom?: Non-List functions.
11187 * batch:call-with-output-script: Batch.
11188 * batch:command: Batch.
11189 * batch:comment: Batch.
11190 * batch:delete-file: Batch.
11191 * batch:initialize!: Batch.
11192 * batch:lines->file: Batch.
11193 * batch:rename-file: Batch.
11194 * batch:run-script: Batch.
11195 * batch:try-chopped-command: Batch.
11196 * batch:try-command: Batch.
11197 * bit-extract: Bit-Twiddling.
11198 * bit-field: Bit-Twiddling.
11199 * bitwise-if: Bit-Twiddling.
11200 * break: Breakpoints.
11201 * break-all: Debug.
11202 * breakf: Breakpoints.
11203 * breakpoint: Breakpoints.
11204 * browse: Database Browser.
11205 * browse-url-netscape: System Interface.
11206 * butlast: Lists as sequences.
11207 * butnthcdr: Lists as sequences.
11211 * bytes->list: Byte.
11212 * bytes-length: Byte.
11213 * call-with-dynamic-binding: Dynamic Data Type.
11214 * call-with-input-string: String Ports.
11215 * call-with-output-string: String Ports.
11216 * call-with-tmpnam: System Interface.
11217 * call-with-values: Values.
11218 * capture-syntactic-environment: Syntactic Closures.
11219 * cart-prod-tables: Relational Database Operations.
11220 * catalog->html: HTML Tables. |
11221 * cgi:serve-query: HTTP and CGI.
11222 * chap:next-string: Chapter Ordering.
11223 * chap:string<=?: Chapter Ordering.
11224 * chap:string<?: Chapter Ordering.
11225 * chap:string>=?: Chapter Ordering.
11226 * chap:string>?: Chapter Ordering.
11227 * check-parameters: Parameter lists.
11228 * close-base: Base Table.
11229 * close-database: Relational Database Operations.
11230 * close-table: Table Operations.
11231 * coerce: Type Coercion. |
11232 * collection?: Collections.
11233 * combined-rulesets: Commutative Rings.
11234 * command->p-specs: HTML. |
11235 * command:make-editable-table: HTML Tables. |
11236 * command:modify-table: HTML Tables. |
11237 * continue: Breakpoints.
11238 * copy-bit: Bit-Twiddling.
11239 * copy-bit-field: Bit-Twiddling.
11240 * copy-list: List construction.
11241 * copy-random-state: Random Numbers.
11242 * copy-tree: Tree Operations.
11243 * create-database <1>: Database Utilities.
11244 * create-database: Creating and Opening Relational Databases.
11245 * create-report: Database Reports.
11246 * create-table: Relational Database Operations.
11247 * create-view: Relational Database Operations.
11248 * cring:define-rule: Commutative Rings.
11249 * ctime: Posix Time.
11250 * current-directory: System Interface.
11251 * current-error-port: Input/Output.
11252 * current-input-port <1>: Byte.
11253 * current-input-port: Ruleset Definition and Use.
11254 * current-output-port: Byte.
11255 * current-time: Time and Date.
11256 * db->html-directory: HTML Tables. |
11257 * db->html-files: HTML Tables. |
11258 * db->netscape: HTML Tables.
11259 * decode-universal-time: Common-Lisp Time.
11260 * define-access-operation: Setters.
11261 * define-operation: Yasos interface.
11262 * define-predicate: Yasos interface.
11263 * define-record: Structures.
11264 * define-syntax: Macro by Example.
11265 * define-tables: Database Utilities.
11266 * defmacro: Defmacro.
11267 * defmacro:eval: Defmacro.
11268 * defmacro:expand*: Defmacro.
11269 * defmacro:load: Defmacro.
11270 * defmacro?: Defmacro.
11271 * delete <1>: Destructive list operations.
11272 * delete: Base Table.
11273 * delete*: Base Table.
11274 * delete-domain: Database Utilities.
11275 * delete-file: Input/Output.
11276 * delete-if: Destructive list operations.
11277 * delete-if-not: Destructive list operations.
11278 * delete-table: Relational Database Operations.
11279 * dequeue!: Queues.
11280 * determinant: Determinant. |
11281 * difftime: Time and Date.
11282 * display-file: Line I/O.
11283 * do-elts: Collections.
11284 * do-keys: Collections.
11285 * domain-checker: Database Utilities.
11286 * dynamic-ref: Dynamic Data Type.
11287 * dynamic-set!: Dynamic Data Type.
11288 * dynamic-wind: Dynamic-Wind.
11289 * dynamic?: Dynamic Data Type.
11290 * empty?: Collections.
11291 * encode-universal-time: Common-Lisp Time.
11292 * enquque!: Queues.
11295 * every: Lists as sets.
11296 * every?: Collections.
11297 * extended-euclid: Modular Arithmetic.
11298 * factor: Prime Numbers.
11299 * fft: Fast Fourier Transform.
11300 * fft-1: Fast Fourier Transform.
11301 * file-exists?: Input/Output.
11302 * filename:match-ci??: Filenames.
11303 * filename:match??: Filenames.
11304 * filename:substitute-ci??: Filenames.
11305 * filename:substitute??: Filenames.
11306 * fill-empty-parameters: Parameter lists.
11307 * find-if: Lists as sets.
11308 * find-ratio: Rationalize.
11309 * find-ratio-between: Rationalize.
11310 * find-string-from-port?: String Search.
11311 * fluid-let: Fluid-Let.
11312 * for-each-elt: Collections.
11313 * for-each-key <1>: Collections.
11314 * for-each-key: Base Table.
11315 * for-each-row: Table Operations.
11316 * force-output: Input/Output.
11317 * form:delimited: HTML. |
11318 * form:element: HTML. |
11319 * form:image: HTML. |
11320 * form:reset: HTML. |
11321 * form:submit: HTML. |
11322 * format: Format Interface.
11323 * fprintf: Standard Formatted Output.
11324 * fscanf: Standard Formatted Input.
11325 * ftp-upload: System Interface.
11326 * generic-write: Generic-Write.
11327 * gentemp: Defmacro.
11328 * get: Table Operations.
11329 * get*: Table Operations.
11330 * get-decoded-time: Common-Lisp Time.
11331 * get-method: Object.
11332 * get-universal-time: Common-Lisp Time.
11333 * getenv: System Interface.
11335 * getopt--: Getopt.
11336 * getopt->arglist: Getopt Parameter lists.
11337 * getopt->parameter-list: Getopt Parameter lists.
11338 * glob-pattern?: System Interface.
11339 * gmktime: Posix Time.
11340 * gmtime: Posix Time.
11341 * golden-section-search: Minimizing.
11342 * gtime: Posix Time.
11343 * has-duplicates?: Lists as sets.
11345 * hash-associator: Hash Tables.
11346 * hash-for-each: Hash Tables.
11347 * hash-inquirer: Hash Tables.
11348 * hash-map: Hash Tables.
11349 * hash-remover: Hash Tables.
11352 * heap-extract-max!: Priority Queues.
11353 * heap-insert!: Priority Queues.
11354 * heap-length: Priority Queues.
11355 * home-vicinity: Vicinity.
11356 * html:anchor: URI. |
11357 * html:atval: HTML.
11358 * html:base: URI. |
11360 * html:buttons: HTML. |
11361 * html:caption: HTML Tables. |
11362 * html:checkbox: HTML. |
11363 * html:comment: HTML.
11364 * html:editable-row-converter: HTML Tables. |
11367 * html:heading: HTML Tables.
11368 * html:hidden: HTML. |
11369 * html:href-heading: HTML Tables.
11370 * html:http-equiv: HTML. |
11371 * html:isindex: URI. |
11372 * html:link: URI. |
11373 * html:linked-row-converter: HTML Tables. |
11374 * html:meta: HTML. |
11375 * html:meta-refresh: HTML. |
11376 * html:plain: HTML.
11378 * html:select: HTML. |
11379 * html:table: HTML Tables.
11380 * html:text: HTML. |
11381 * html:text-area: HTML. |
11382 * http:content: HTTP and CGI.
11383 * http:error-page: HTTP and CGI.
11384 * http:forwarding-page: HTTP and CGI. |
11385 * http:header: HTTP and CGI.
11386 * http:serve-query: HTTP and CGI.
11387 * identifier=?: Syntactic Closures.
11388 * identifier?: Syntactic Closures.
11389 * identity: Legacy.
11390 * implementation-vicinity: Vicinity.
11391 * in-vicinity: Vicinity.
11392 * init-debug: Breakpoints.
11393 * integer-expt: Bit-Twiddling.
11394 * integer-length: Bit-Twiddling.
11395 * integer-sqrt: Root Finding.
11396 * interaction-environment: Eval.
11397 * intersection: Lists as sets.
11398 * jacobi-symbol: Prime Numbers.
11399 * kill-process!: Multi-Processing.
11400 * kill-table: Base Table.
11401 * laguerre:find-polynomial-root: Root Finding.
11402 * laguerre:find-root: Root Finding.
11403 * last: Lists as sequences.
11404 * last-pair: Legacy.
11405 * library-vicinity: Vicinity.
11406 * list*: List construction.
11407 * list->bytes: Byte.
11408 * list->string: Rev4 Optional Procedures.
11409 * list->vector: Rev4 Optional Procedures.
11410 * list-of??: Lists as sets. |
11411 * list-table-definition: Database Utilities. |
11412 * list-tail: Rev4 Optional Procedures.
11413 * load-option: Weight-Balanced Trees.
11414 * localtime: Posix Time.
11415 * logand: Bit-Twiddling.
11416 * logbit?: Bit-Twiddling.
11417 * logcount: Bit-Twiddling.
11418 * logior: Bit-Twiddling.
11419 * lognot: Bit-Twiddling.
11420 * logtest: Bit-Twiddling.
11421 * logxor: Bit-Twiddling.
11422 * macro:eval <1>: Syntax-Case Macros.
11423 * macro:eval <2>: Syntactic Closures.
11424 * macro:eval <3>: Macros That Work.
11425 * macro:eval: R4RS Macros.
11426 * macro:expand <1>: Syntax-Case Macros.
11427 * macro:expand <2>: Syntactic Closures.
11428 * macro:expand <3>: Macros That Work.
11429 * macro:expand: R4RS Macros.
11430 * macro:load <1>: Syntax-Case Macros.
11431 * macro:load <2>: Syntactic Closures.
11432 * macro:load <3>: Macros That Work.
11433 * macro:load: R4RS Macros.
11434 * macroexpand: Defmacro.
11435 * macroexpand-1: Defmacro.
11436 * macwork:eval: Macros That Work.
11437 * macwork:expand: Macros That Work.
11438 * macwork:load: Macros That Work.
11439 * make-: Structures.
11440 * make-array: Arrays.
11441 * make-base: Base Table.
11442 * make-bytes: Byte.
11443 * make-command-server: Database Utilities.
11444 * make-directory: System Interface.
11445 * make-dynamic: Dynamic Data Type.
11446 * make-generic-method: Object.
11447 * make-generic-predicate: Object.
11448 * make-getter: Base Table.
11449 * make-hash-table: Hash Tables.
11450 * make-heap: Priority Queues.
11451 * make-key->list: Base Table.
11452 * make-key-extractor: Base Table.
11453 * make-keyifier-1: Base Table.
11454 * make-list: List construction.
11455 * make-list-keyifier: Base Table.
11456 * make-method!: Object.
11457 * make-object: Object.
11458 * make-parameter-list: Parameter lists.
11459 * make-port-crc: Cyclic Checksum.
11460 * make-predicate!: Object.
11461 * make-promise: Promises.
11462 * make-putter: Base Table.
11463 * make-query-alist-command-server: HTTP and CGI. |
11464 * make-queue: Queues.
11465 * make-random-state: Random Numbers.
11466 * make-record-type: Records.
11467 * make-relational-system: Creating and Opening Relational Databases.
11468 * make-ruleset: Commutative Rings.
11469 * make-shared-array: Arrays.
11470 * make-sierpinski-indexer: Hashing.
11471 * make-syntactic-closure: Syntactic Closures.
11472 * make-table: Base Table.
11474 * make-vicinity: Vicinity.
11475 * make-wt-tree: Construction of Weight-Balanced Trees.
11476 * make-wt-tree-type: Construction of Weight-Balanced Trees.
11477 * map-elts: Collections.
11478 * map-key: Base Table.
11479 * map-keys: Collections.
11480 * member-if: Lists as sets.
11483 * mktime: Posix Time.
11484 * modular:: Modular Arithmetic.
11485 * modular:*: Modular Arithmetic.
11486 * modular:+: Modular Arithmetic.
11487 * modular:expt: Modular Arithmetic.
11488 * modular:invert: Modular Arithmetic.
11489 * modular:invertable?: Modular Arithmetic.
11490 * modular:negate: Modular Arithmetic.
11491 * modular:normalize: Modular Arithmetic.
11492 * modulus->integer: Modular Arithmetic.
11493 * must-be-first: Batch.
11494 * must-be-last: Batch.
11495 * nconc: Destructive list operations.
11496 * newton:find-root: Root Finding.
11497 * newtown:find-integer-root: Root Finding.
11498 * notany: Lists as sets.
11499 * notevery: Lists as sets.
11500 * nreverse: Destructive list operations.
11501 * nthcdr: Lists as sequences.
11502 * null-directory?: System Interface.
11503 * null-environment: Eval.
11504 * object: Yasos interface.
11505 * object->limited-string: Object-To-String.
11506 * object->string: Object-To-String.
11507 * object-with-ancestors: Yasos interface.
11509 * offset-time: Time and Date.
11510 * open-base: Base Table.
11511 * open-database <1>: Database Utilities.
11512 * open-database: Creating and Opening Relational Databases.
11513 * open-database!: Database Utilities.
11514 * open-table <1>: Relational Database Operations.
11515 * open-table: Base Table.
11516 * operate-as: Yasos interface.
11517 * or?: Non-List functions.
11518 * ordered-for-each-key: Base Table.
11519 * os->batch-dialect: Batch.
11520 * output-port-height: Input/Output.
11521 * output-port-width: Input/Output.
11522 * parameter-list->arglist: Parameter lists.
11523 * parameter-list-expand: Parameter lists.
11524 * parameter-list-ref: Parameter lists.
11525 * parse-ftp-address: System Interface.
11526 * path->uri: System Interface. |
11528 * plot-function!: Plotting.
11529 * pnm:array-write: Portable Image Files.
11530 * pnm:image-file->array: Portable Image Files.
11531 * pnm:type-dimensions: Portable Image Files.
11532 * position: Lists as sequences.
11533 * pprint-file: Pretty-Print.
11534 * pprint-filter-file: Pretty-Print.
11535 * prec:commentfix: Grammar Rule Definition.
11536 * prec:define-grammar: Ruleset Definition and Use.
11537 * prec:delim: Grammar Rule Definition.
11538 * prec:infix: Grammar Rule Definition.
11539 * prec:inmatchfix: Grammar Rule Definition.
11540 * prec:make-led: Nud and Led Definition.
11541 * prec:make-nud: Nud and Led Definition.
11542 * prec:matchfix: Grammar Rule Definition.
11543 * prec:nary: Grammar Rule Definition.
11544 * prec:nofix: Grammar Rule Definition.
11545 * prec:parse: Ruleset Definition and Use.
11546 * prec:postfix: Grammar Rule Definition.
11547 * prec:prefix: Grammar Rule Definition.
11548 * prec:prestfix: Grammar Rule Definition.
11549 * predicate->asso: Association Lists.
11550 * predicate->hash: Hash Tables.
11551 * predicate->hash-asso: Hash Tables.
11552 * present?: Base Table.
11553 * pretty-print: Pretty-Print.
11554 * pretty-print->string: Pretty-Print. |
11555 * prime?: Prime Numbers.
11556 * primes<: Prime Numbers.
11557 * primes>: Prime Numbers.
11558 * print: Yasos interface.
11559 * print-call-stack: Trace.
11560 * printf: Standard Formatted Output.
11561 * process:schedule!: Multi-Processing.
11562 * program-vicinity: Vicinity.
11563 * project-table: Relational Database Operations.
11564 * provide <1>: Require.
11565 * provide: Feature.
11566 * provided? <1>: Require.
11567 * provided?: Feature.
11569 * qpn: Quick Print.
11570 * qpr: Quick Print.
11571 * queue-empty?: Queues.
11572 * queue-front: Queues.
11573 * queue-pop!: Queues.
11574 * queue-push!: Queues.
11575 * queue-rear: Queues.
11577 * random: Random Numbers.
11578 * random:exp: Random Numbers.
11579 * random:hollow-sphere!: Random Numbers.
11580 * random:normal: Random Numbers.
11581 * random:normal-vector!: Random Numbers.
11582 * random:solid-sphere!: Random Numbers.
11583 * random:uniform: Random Numbers.
11584 * rationalize: Rationalize.
11586 * read-command: Command Line.
11587 * read-line: Line I/O.
11588 * read-line!: Line I/O.
11589 * read-options-file: Command Line.
11590 * record-accessor: Records.
11591 * record-constructor: Records.
11592 * record-modifier: Records.
11593 * record-predicate: Records.
11594 * reduce <1>: Lists as sequences.
11595 * reduce: Collections.
11596 * reduce-init: Lists as sequences.
11597 * remove: Lists as sets.
11598 * remove-duplicates: Lists as sets.
11599 * remove-if: Lists as sets.
11600 * remove-if-not: Lists as sets.
11601 * remove-parameter: Parameter lists.
11602 * remove-setter-for: Setters.
11604 * repl:top-level: Repl.
11605 * replace-suffix: Filenames.
11606 * require <1>: Require.
11607 * require <2>: Catalog Compilation.
11608 * require: Requesting Features.
11609 * require:feature->path <1>: Require.
11610 * require:feature->path: Requesting Features.
11611 * restrict-table: Relational Database Operations.
11612 * row:delete: Table Operations.
11613 * row:delete*: Table Operations.
11614 * row:insert: Table Operations.
11615 * row:insert*: Table Operations.
11616 * row:remove: Table Operations.
11617 * row:remove*: Table Operations.
11618 * row:retrieve: Table Operations.
11619 * row:retrieve*: Table Operations.
11620 * row:update: Table Operations.
11621 * row:update*: Table Operations.
11622 * scanf: Standard Formatted Input.
11623 * scanf-read-list: Standard Formatted Input.
11624 * scheme-report-environment: Eval.
11625 * schmooz: Schmooz.
11626 * secant:find-bracketed-root: Root Finding.
11627 * secant:find-root: Root Finding.
11628 * seed->random-state: Random Numbers.
11630 * set-: Structures.
11631 * set-difference: Lists as sets.
11632 * Setter: Collections.
11634 * si:conversion-factor: Metric Units. |
11635 * singleton-wt-tree: Construction of Weight-Balanced Trees.
11636 * size <1>: Collections.
11637 * size: Yasos interface.
11638 * slib:error: System.
11639 * slib:eval: System.
11640 * slib:eval-load: System.
11641 * slib:exit: System.
11642 * slib:load: System.
11643 * slib:load-compiled: System.
11644 * slib:load-source: System.
11645 * slib:report: Configuration.
11646 * slib:report-version: Configuration.
11647 * slib:warn: System.
11648 * software-type: Configuration.
11649 * some: Lists as sets.
11652 * sorted?: Sorting.
11653 * soundex: Hashing.
11654 * sprintf: Standard Formatted Output.
11655 * sscanf: Standard Formatted Input.
11657 * stack-all: Debug.
11658 * string->list: Rev4 Optional Procedures.
11659 * string-capitalize: String-Case.
11660 * string-captialize!: String-Case.
11661 * string-ci->symbol: String-Case.
11662 * string-copy: Rev4 Optional Procedures.
11663 * string-downcase: String-Case.
11664 * string-downcase!: String-Case.
11665 * string-fill!: Rev4 Optional Procedures.
11666 * string-index: String Search.
11667 * string-index-ci: String Search.
11668 * string-join: Batch.
11669 * string-null?: Rev2 Procedures.
11670 * string-reverse-index: String Search.
11671 * string-reverse-index-ci: String Search.
11672 * string-subst: String Search.
11673 * string-upcase: String-Case.
11674 * string-upcase!: String-Case.
11675 * sub-vicinity: Vicinity.
11676 * subst: Tree Operations.
11677 * substq: Tree Operations.
11678 * substring-ci?: String Search.
11679 * substring-fill!: Rev2 Procedures.
11680 * substring-move-left!: Rev2 Procedures.
11681 * substring-move-right!: Rev2 Procedures.
11682 * substring?: String Search.
11683 * substv: Tree Operations.
11684 * supported-key-type?: Base Table.
11685 * supported-type?: Base Table.
11686 * symbol-append: String-Case. |
11687 * symmetric:modulus: Modular Arithmetic.
11688 * sync-base: Base Table.
11689 * sync-database: Relational Database Operations. |
11690 * syncase:eval: Syntax-Case Macros.
11691 * syncase:expand: Syntax-Case Macros.
11692 * syncase:load: Syntax-Case Macros.
11693 * synclo:eval: Syntactic Closures.
11694 * synclo:expand: Syntactic Closures.
11695 * synclo:load: Syntactic Closures.
11696 * syntax-rules: Macro by Example.
11697 * system: System Interface.
11698 * table->linked-html: HTML Tables. |
11699 * table->linked-page: HTML Tables. |
11700 * table-exists?: Relational Database Operations.
11701 * table-name->filename: HTML Tables.
11703 * tek40:draw: Tektronix Graphics Support.
11704 * tek40:graphics: Tektronix Graphics Support.
11705 * tek40:init: Tektronix Graphics Support.
11706 * tek40:linetype: Tektronix Graphics Support.
11707 * tek40:move: Tektronix Graphics Support.
11708 * tek40:put-text: Tektronix Graphics Support.
11709 * tek40:reset: Tektronix Graphics Support.
11710 * tek40:text: Tektronix Graphics Support.
11711 * tek41:draw: Tektronix Graphics Support.
11712 * tek41:encode-int: Tektronix Graphics Support.
11713 * tek41:encode-x-y: Tektronix Graphics Support.
11714 * tek41:graphics: Tektronix Graphics Support.
11715 * tek41:init: Tektronix Graphics Support.
11716 * tek41:move: Tektronix Graphics Support.
11717 * tek41:point: Tektronix Graphics Support.
11718 * tek41:reset: Tektronix Graphics Support.
11719 * time-zone: Time Zone.
11720 * tmpnam: Input/Output.
11721 * tok:char-group: Token definition.
11722 * topological-sort: Topological Sort.
11724 * trace-all: Debug.
11727 * track-all: Debug.
11728 * transcript-off: Transcripts.
11729 * transcript-on: Transcripts.
11730 * transformer: Syntactic Closures.
11731 * truncate-up-to: Batch.
11732 * tsort: Topological Sort.
11733 * two-arg:-: Multi-argument / and -.
11734 * two-arg:/: Multi-argument / and -.
11735 * two-arg:apply: Multi-argument Apply.
11736 * type-of: Type Coercion. |
11737 * tz:params: Time Zone.
11738 * tzset: Time Zone.
11739 * unbreak: Breakpoints.
11740 * unbreakf: Breakpoints.
11741 * union: Lists as sets.
11742 * unmake-method!: Object.
11747 * uri->tree: URI. |
11748 * uric:decode: URI. |
11749 * uric:encode: URI. |
11750 * user-email-address: System Interface.
11751 * user-vicinity: Vicinity.
11753 * variant-case: Structures.
11754 * vector->list: Rev4 Optional Procedures.
11755 * vector-fill!: Rev4 Optional Procedures.
11756 * with-input-from-file: With-File.
11757 * with-output-to-file: With-File.
11758 * write-base: Base Table.
11759 * write-byte: Byte.
11760 * write-database: Relational Database Operations.
11761 * write-line: Line I/O.
11762 * wt-tree/add: Basic Operations on Weight-Balanced Trees.
11763 * wt-tree/add!: Basic Operations on Weight-Balanced Trees.
11764 * wt-tree/delete: Basic Operations on Weight-Balanced Trees.
11765 * wt-tree/delete!: Basic Operations on Weight-Balanced Trees.
11766 * wt-tree/delete-min: Indexing Operations on Weight-Balanced Trees.
11767 * wt-tree/delete-min!: Indexing Operations on Weight-Balanced Trees.
11768 * wt-tree/difference: Advanced Operations on Weight-Balanced Trees.
11769 * wt-tree/empty?: Basic Operations on Weight-Balanced Trees.
11770 * wt-tree/fold: Advanced Operations on Weight-Balanced Trees.
11771 * wt-tree/for-each: Advanced Operations on Weight-Balanced Trees.
11772 * wt-tree/index: Indexing Operations on Weight-Balanced Trees.
11773 * wt-tree/index-datum: Indexing Operations on Weight-Balanced Trees.
11774 * wt-tree/index-pair: Indexing Operations on Weight-Balanced Trees.
11775 * wt-tree/intersection: Advanced Operations on Weight-Balanced Trees.
11776 * wt-tree/lookup: Basic Operations on Weight-Balanced Trees.
11777 * wt-tree/member?: Basic Operations on Weight-Balanced Trees.
11778 * wt-tree/min: Indexing Operations on Weight-Balanced Trees.
11779 * wt-tree/min-datum: Indexing Operations on Weight-Balanced Trees.
11780 * wt-tree/min-pair: Indexing Operations on Weight-Balanced Trees.
11781 * wt-tree/rank: Indexing Operations on Weight-Balanced Trees.
11782 * wt-tree/set-equal?: Advanced Operations on Weight-Balanced Trees.
11783 * wt-tree/size: Basic Operations on Weight-Balanced Trees.
11784 * wt-tree/split<: Advanced Operations on Weight-Balanced Trees.
11785 * wt-tree/split>: Advanced Operations on Weight-Balanced Trees.
11786 * wt-tree/subset?: Advanced Operations on Weight-Balanced Trees.
11787 * wt-tree/union: Advanced Operations on Weight-Balanced Trees.
11788 * wt-tree?: Basic Operations on Weight-Balanced Trees.
11793 This is an alphabetical list of all the global variables in SLIB.
11797 * *catalog*: Require.
11798 * *features*: Require.
11799 * *http:byline*: HTTP and CGI.
11800 * *modules*: Require.
11801 * *optarg*: Getopt.
11802 * *optind*: Getopt.
11803 * *qp-width*: Quick Print.
11804 * *random-state*: Random Numbers.
11805 * *ruleset*: Commutative Rings.
11806 * *syn-defs*: Ruleset Definition and Use.
11807 * *syn-ignore-whitespace*: Ruleset Definition and Use.
11808 * *timezone*: Time Zone.
11809 * batch:platform: Batch.
11810 * catalog-id: Base Table.
11811 * char-code-limit: Configuration.
11812 * charplot:height: Plotting.
11813 * charplot:width: Plotting.
11814 * column-domains: Table Operations.
11815 * column-foreigns: Table Operations.
11816 * column-names: Table Operations.
11817 * column-types: Table Operations.
11818 * daylight?: Time Zone.
11819 * debug:max-count: Trace.
11820 * distribute*: Commutative Rings.
11821 * distribute/: Commutative Rings.
11822 * most-positive-fixnum: Configuration.
11824 * number-wt-type: Construction of Weight-Balanced Trees.
11825 * primary-limit: Table Operations.
11826 * prime:prngs: Prime Numbers.
11827 * prime:trials: Prime Numbers.
11828 * slib:form-feed: Configuration.
11829 * slib:tab: Configuration.
11830 * stderr: Standard Formatted I/O.
11831 * stdin: Standard Formatted I/O.
11832 * stdout: Standard Formatted I/O.
11833 * string-wt-type: Construction of Weight-Balanced Trees.
11835 * tok:decimal-digits: Token definition.
11836 * tok:lower-case: Token definition.
11837 * tok:upper-case: Token definition.
11838 * tok:whitespaces: Token definition.
11839 * tzname: Time Zone.
11841 Concept and Feature Index
11842 *************************
11846 * alist: Association Lists.
11847 * alist-table <1>: Creating and Opening Relational Databases.
11848 * alist-table: Base Table.
11849 * ange-ftp: System Interface.
11851 * array-for-each: Array Mapping.
11852 * attribute-value: HTML.
11853 * balanced binary trees: Weight-Balanced Trees.
11856 * binary trees: Weight-Balanced Trees.
11857 * binary trees, as discrete maps: Weight-Balanced Trees.
11858 * binary trees, as sets: Weight-Balanced Trees.
11859 * break: Breakpoints.
11861 * calendar time <1>: Posix Time.
11862 * calendar time: Time and Date.
11863 * Calendar-Time: Posix Time.
11864 * caltime: Posix Time.
11865 * careful: Commutative Rings.
11866 * catalog: Requesting Features.
11867 * Catalog File: Library Catalogs.
11868 * chapter-order: Chapter Ordering.
11869 * charplot: Plotting.
11870 * coerce: Type Coercion. |
11871 * collect: Collections.
11872 * command line: Command Line.
11873 * commentfix: Precedence Parsing Overview.
11874 * common-list-functions <1>: Common List Functions.
11875 * common-list-functions: Collections.
11876 * commutative-ring: Commutative Rings.
11877 * Coordinated Universal Time: Posix Time.
11878 * database-utilities <1>: Database Utilities.
11879 * database-utilities: Batch.
11880 * debug <1>: Breakpoints.
11882 * defmacroexpand <1>: Pretty-Print.
11883 * defmacroexpand: Defmacro.
11884 * delim: Precedence Parsing Overview.
11885 * discrete maps, using binary trees: Weight-Balanced Trees.
11886 * DrScheme: Installation.
11887 * dynamic: Dynamic Data Type.
11888 * dynamic-wind: Dynamic-Wind.
11890 * Euclidean Domain: Commutative Rings.
11891 * factor: Prime Numbers.
11892 * feature <1>: About this manual.
11893 * feature <2>: Requesting Features.
11894 * feature: Feature.
11895 * fft: Fast Fourier Transform.
11896 * fluid-let <1>: Database Utilities.
11897 * fluid-let: Fluid-Let.
11900 * generic-write: Generic-Write.
11901 * getit: System Interface.
11902 * getopt <1>: Database Utilities.
11907 * hash-table: Hash Tables.
11908 * HOME <1>: Vicinity.
11909 * HOME: Library Catalogs.
11910 * homecat: Catalog Compilation.
11911 * implcat: Catalog Compilation.
11912 * infix: Precedence Parsing Overview.
11913 * inmatchfix: Precedence Parsing Overview.
11914 * Left Denotation, led: Nud and Led Definition.
11915 * line-i: Line I/O.
11916 * logical: Bit-Twiddling.
11918 * macro: R4RS Macros.
11919 * macro-by-example: Macro by Example.
11920 * macros-that-work: Macros That Work.
11921 * make-crc: Cyclic Checksum.
11922 * match: Base Table.
11923 * match-keys <1>: Table Operations.
11924 * match-keys: Base Table.
11925 * matchfix: Precedence Parsing Overview.
11926 * metric-units: Metric Units. |
11927 * minimize: Minimizing.
11928 * minimum field width (printf): Standard Formatted Output.
11929 * mkimpcat.scm: Catalog Compilation.
11930 * mklibcat.scm: Catalog Compilation.
11931 * modular: Modular Arithmetic.
11932 * multiarg-apply: Multi-argument Apply.
11933 * mutliarg: Multi-argument / and -.
11934 * MzScheme: Installation.
11935 * nary: Precedence Parsing Overview.
11936 * net-clients: System Interface.
11937 * new-catalog: Catalog Compilation. |
11938 * nofix: Precedence Parsing Overview.
11939 * null: HTML Tables. |
11940 * Null Denotation, nud: Nud and Led Definition.
11942 * object->string: Object-To-String.
11944 * option, run-time-loadable: Weight-Balanced Trees.
11945 * options file: Command Line.
11946 * parameters <1>: Database Utilities.
11947 * parameters <2>: Batch.
11948 * parameters: Parameter lists.
11949 * parse: Precedence Parsing.
11950 * plain-text: HTML.
11951 * PLT Scheme: Installation.
11952 * posix-time: Posix Time.
11953 * postfix: Precedence Parsing Overview.
11954 * pprint-file: Pretty-Print.
11956 * precedence: Precedence Parsing.
11957 * precision (printf): Standard Formatted Output.
11958 * prefix: Precedence Parsing Overview.
11959 * prestfix: Precedence Parsing Overview.
11960 * pretty-print: Pretty-Print.
11961 * primes: Prime Numbers.
11962 * printf: Standard Formatted Output.
11963 * priority-queue: Priority Queues.
11964 * PRNG: Random Numbers.
11965 * process: Multi-Processing.
11966 * promise: Promises.
11967 * qp <1>: Quick Print.
11969 * query-string: HTTP and CGI.
11971 * random: Random Numbers.
11972 * rationalize: Rationalize.
11973 * read-command: Command Line.
11975 * relational-database: Relational Database.
11977 * repl: Syntax-Case Macros.
11979 * rev2-procedures: Rev2 Procedures.
11980 * rev3-report: Coding Guidelines.
11981 * rev4-optional-procedures: Rev4 Optional Procedures.
11982 * ring, commutative: Commutative Rings.
11983 * RNG: Random Numbers.
11984 * root: Root Finding.
11985 * run-time-loadable option: Weight-Balanced Trees.
11986 * scanf: Standard Formatted Input.
11987 * Scheme48: Installation.
11988 * schmooz: Schmooz.
11989 * SCM: Installation.
11990 * Server-based Naming Authority: URI. |
11991 * session: Feature.
11992 * sets, using binary trees: Weight-Balanced Trees.
11993 * sierpinski: Hashing.
11994 * sitecat: Catalog Compilation.
11995 * slibcat: Catalog Compilation.
11997 * soundex: Hashing.
11998 * stdio: Standard Formatted I/O.
11999 * string-case: String-Case.
12000 * string-port: String Ports.
12001 * string-search: String Search.
12002 * struct: Structures.
12003 * syntactic-closures: Syntactic Closures.
12004 * syntax-case: Syntax-Case Macros.
12005 * time: Time and Date.
12006 * time-zone: Time Zone.
12007 * topological-sort: Topological Sort.
12009 * transcript: Transcripts.
12010 * tree: Tree Operations.
12011 * trees, balanced binary: Weight-Balanced Trees.
12012 * tsort: Topological Sort.
12013 * TZ-string: Time Zone.
12014 * Uniform Resource Identifiers: URI. |
12015 * Uniform Resource Locator: System Interface.
12016 * Unique Factorization: Commutative Rings.
12018 * URI: HTTP and CGI.
12019 * usercat: Catalog Compilation.
12022 * VSCM: Installation.
12023 * weight-balanced binary trees: Weight-Balanced Trees.
12024 * wild-card: Base Table.
12025 * with-file: With-File.
12026 * wt-tree: Weight-Balanced Trees.
12033 Node: The Library System
\7f1740
12034 Node: Feature
\7f2054
12035 Node: Requesting Features
\7f3004
12036 Node: Library Catalogs
\7f4363
12037 Node: Catalog Compilation
\7f6815
12038 Node: Built-in Support
\7f9624
12039 Node: Require
\7f10255
12040 Node: Vicinity
\7f12747
12041 Node: Configuration
\7f15714
12042 Node: Input/Output
\7f18655
12043 Node: Legacy
\7f20254
12044 Node: System
\7f21096
12045 Node: About this manual
\7f23588
12046 Node: Scheme Syntax Extension Packages
\7f24145
12047 Node: Defmacro
\7f24830
12048 Node: R4RS Macros
\7f26781
12049 Node: Macro by Example
\7f28036
12050 Node: Macros That Work
\7f30913
12051 Node: Syntactic Closures
\7f36971
12052 Node: Syntax-Case Macros
\7f54405
12053 Node: Fluid-Let
\7f58531
12054 Node: Yasos
\7f59472
12055 Node: Yasos terms
\7f60265
12056 Node: Yasos interface
\7f61289
12057 Node: Setters
\7f63364
12058 Node: Yasos examples
\7f66005
12059 Node: Textual Conversion Packages
\7f68999
12060 Node: Precedence Parsing
\7f69697
12061 Node: Precedence Parsing Overview
\7f70360
12062 Ref: Precedence Parsing Overview-Footnote-1
\7f72358
12063 Node: Ruleset Definition and Use
\7f72561
12064 Node: Token definition
\7f74942
12065 Node: Nud and Led Definition
\7f77211
12066 Node: Grammar Rule Definition
\7f79660
12067 Node: Format
\7f87234
12068 Node: Format Interface
\7f87482
12069 Node: Format Specification
\7f89219
12070 Node: Standard Formatted I/O
\7f99349
12071 Node: Standard Formatted Output
\7f99915
12072 Node: Standard Formatted Input
\7f109182
12073 Node: Programs and Arguments
\7f115842
12074 Node: Getopt
\7f116342
12075 Node: Command Line
\7f122184
12076 Node: Parameter lists
\7f125373
12077 Node: Getopt Parameter lists
\7f129358
12078 Node: Filenames
\7f133527
12079 Node: Batch
\7f136757
12080 Node: HTML
\7f144550
12081 Node: HTML Tables
\7f155838
12082 Node: HTTP and CGI
\7f166135
12084 Node: Printing Scheme
\7f177162
12085 Node: Generic-Write
\7f177550
12086 Node: Object-To-String
\7f178953
12087 Node: Pretty-Print
\7f179357
12088 Node: Time and Date
\7f184343
12089 Node: Time Zone
\7f185370
12090 Node: Posix Time
\7f189931
12091 Node: Common-Lisp Time
\7f192067
12092 Node: Vector Graphics
\7f193646
12093 Node: Tektronix Graphics Support
\7f193835
12094 Node: Schmooz
\7f195209
12095 Node: Mathematical Packages
\7f199435
12096 Node: Bit-Twiddling
\7f200069
12097 Node: Modular Arithmetic
\7f204660
12098 Node: Prime Numbers
\7f206794
12099 Node: Random Numbers
\7f208477
12100 Node: Fast Fourier Transform
\7f213113
12101 Node: Cyclic Checksum
\7f214031
12102 Node: Plotting
\7f216292
12103 Node: Root Finding
\7f219151
12104 Node: Minimizing
\7f223138
12105 Ref: Minimizing-Footnote-1
\7f208597
12106 Node: Commutative Rings
\7f225178
12107 Node: Determinant
\7f236562
12108 Node: Database Packages
\7f237120
12109 Node: Base Table
\7f237384
12110 Node: Relational Database
\7f247798
12111 Node: Motivations
\7f248582
12112 Node: Creating and Opening Relational Databases
\7f253629
12113 Node: Relational Database Operations
\7f256061
12114 Node: Table Operations
\7f259258
12115 Node: Catalog Representation
\7f267136
12116 Node: Unresolved Issues
\7f270034
12117 Node: Database Utilities
\7f272985
12118 Node: Database Reports
\7f289598
12119 Node: Database Browser
\7f292352
12120 Node: Weight-Balanced Trees
\7f293413
12121 Node: Construction of Weight-Balanced Trees
\7f297284
12122 Node: Basic Operations on Weight-Balanced Trees
\7f300734
12123 Node: Advanced Operations on Weight-Balanced Trees
\7f303699
12124 Node: Indexing Operations on Weight-Balanced Trees
\7f309721
12125 Node: Other Packages
\7f313635
12126 Node: Data Structures
\7f314034
12127 Node: Arrays
\7f314790
12128 Node: Array Mapping
\7f317744
12129 Node: Association Lists
\7f319661
12130 Node: Byte
\7f321912
12131 Node: Portable Image Files
\7f324152
12132 Node: Collections
\7f325699
12133 Node: Dynamic Data Type
\7f331817
12134 Node: Hash Tables
\7f333078
12135 Node: Hashing
\7f335195
12136 Node: Object
\7f339989
12137 Node: Priority Queues
\7f348225
12138 Node: Queues
\7f349068
12139 Node: Records
\7f350194
12140 Node: Structures
\7f353705
12141 Node: Procedures
\7f355005
12142 Node: Common List Functions
\7f355852
12143 Node: List construction
\7f356276
12144 Node: Lists as sets
\7f357939
12145 Node: Lists as sequences
\7f365060
12146 Node: Destructive list operations
\7f370366
12147 Node: Non-List functions
\7f373029
12148 Node: Tree Operations
\7f374174
12149 Node: Type Coercion
\7f375796
12150 Node: Chapter Ordering
\7f377022
12151 Node: Sorting
\7f378719
12152 Node: Topological Sort
\7f384496
12153 Node: String-Case
\7f386183
12154 Node: String Ports
\7f387284
12155 Node: String Search
\7f388048
12156 Node: Line I/O
\7f390415
12157 Node: Multi-Processing
\7f392065
12158 Node: Metric Units
\7f393248
12159 Node: Standards Support
\7f408689
12160 Node: With-File
\7f409423
12161 Node: Transcripts
\7f409699
12162 Node: Rev2 Procedures
\7f410020
12163 Node: Rev4 Optional Procedures
\7f411727
12164 Node: Multi-argument / and -
\7f412297
12165 Node: Multi-argument Apply
\7f412948
12166 Node: Rationalize
\7f413434
12167 Node: Promises
\7f414876
12168 Node: Dynamic-Wind
\7f415293
12169 Node: Eval
\7f416547
12170 Node: Values
\7f419884
12171 Node: Session Support
\7f420671
12172 Node: Repl
\7f421139
12173 Node: Quick Print
\7f422422
12174 Node: Debug
\7f423535
12175 Node: Breakpoints
\7f424421
12176 Node: Trace
\7f426444
12177 Node: System Interface
\7f429555
12178 Node: Extra-SLIB Packages
\7f433443
12179 Node: About SLIB
\7f435743
12180 Node: Installation
\7f436407
12181 Node: Porting
\7f439635
12182 Ref: Porting-Footnote-1
\7f413781
12183 Node: Coding Guidelines
\7f441153
12184 Node: Copyrights
\7f443234
12185 Node: Index
\7f446519