SLIB
The Portable Scheme Library
Version 3b6, February 2020
Aubrey Jaļ¬€er
This manual is for SLIB (version 3b6, February 2020), the portable Scheme library.
Copyright
c
ī€ 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
2006, 2007, 2008 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document under the
terms of the GNU Free Documentation License, Version 1.3 or any later version
published by the Free Software Foundation; with no Invariant Sections, no
Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included
in the section entitled ā€œGNU Free Documentation License.ā€
i
Table of Contents
1 The Library System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1 Feature. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Require . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 Library Catalogs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.4 Catalog Creation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.5 Catalog Vicinities. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.6 Compiling Scheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.6.1 Module Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.6.2 Module Manifests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.6.3 Module Semantics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.6.4 Top-level Variable References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.6.5 Module Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2 Universal SLIB Procedures. . . . . . . . . . . . . . . . . . . . 11
2.1 Vicinity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.2 Conļ¬guration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.3 Input/Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.4 System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.5 Miscellany . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.5.1 Mutual Exclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.5.2 Legacy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3 Scheme Syntax Extension Packages . . . . . . . . . . 18
3.1 Defmacro. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.1.1 Defmacroexpand. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.2 R4RS Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.3 Macro by Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.3.1 Caveat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.4 Macros That Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.4.1 Deļ¬nitions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.4.2 Restrictions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.5 Syntactic Closures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.5.1 Syntactic Closure Macro Facility . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.5.1.1 Terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.5.1.2 Transformer Deļ¬nition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.5.1.3 Identiļ¬ers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
3.5.1.4 Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
3.6 Syntax-Case Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
3.6.1 Notes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
3.7 Deļ¬ne-Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
3.8 Deļ¬ne-Record-Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
3.9 Fluid-Let . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
ii
3.10 Parameter Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
3.11 Binding to multiple values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
3.12 Guarded LET* special form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
3.13 Guarded COND Clause. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
3.14 Yasos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
3.14.1 Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
3.14.2 Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
3.14.3 Setters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
3.14.4 Examples. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
4 Textual Conversion Packages. . . . . . . . . . . . . . . . . . 40
4.1 Precedence Parsing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
4.1.1 Precedence Parsing Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
4.1.2 Rule Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
4.1.3 Ruleset Deļ¬nition and Use. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
4.1.4 Token deļ¬nition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
4.1.5 Nud and Led Deļ¬nition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
4.1.6 Grammar Rule Deļ¬nition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
4.2 Format (version 3.1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
4.2.1 Format Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
4.2.2 Format Speciļ¬cation (Format version 3.1) . . . . . . . . . . . . . . . . . 47
4.2.2.1 Implemented CL Format Control Directives . . . . . . . . . . 47
4.2.2.2 Not Implemented CL Format Control Directives . . . . . . 50
4.2.2.3 Extended, Replaced and Additional Control Directives . . 51
4.2.2.4 Conļ¬guration Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
4.2.2.5 Compatibility With Other Format Implementations . . 52
4.3 Standard Formatted I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
4.3.1 stdio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
4.3.2 Standard Formatted Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
4.3.3 Standard Formatted Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
4.4 Program and Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
4.4.1 Getopt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
4.4.2 Getoptā€” . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
4.4.3 Command Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
4.4.4 Parameter lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
4.4.5 Getopt Parameter lists. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
4.4.6 Filenames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
4.4.7 Batch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
4.5 HTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
4.6 HTML Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
4.7 HTML Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
4.7.1 HTML editing tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
4.7.2 HTML databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
4.8 HTTP and CGI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
4.9 Parsing HTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
4.10 URI. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
4.11 Parsing XML. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
4.11.1 String Glue. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
iii
4.11.2 Character and Token Functions . . . . . . . . . . . . . . . . . . . . . . . . . . 80
4.11.3 Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
4.11.4 Low-Level Parsers and Scanners . . . . . . . . . . . . . . . . . . . . . . . . . 84
4.11.5 Mid-Level Parsers and Scanners. . . . . . . . . . . . . . . . . . . . . . . . . . 89
4.11.6 High-level Parsers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
4.11.7 Parsing XML to SXML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
4.12 Printing Scheme. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
4.12.1 Generic-Write . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
4.12.2 Object-To-String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
4.12.3 Pretty-Print . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
4.13 Time and Date . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
4.13.1 Time Zone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
4.13.2 Posix Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
4.13.3 Common-Lisp Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
4.13.4 ISO 8601 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
4.13.5 Time Infrastructure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
4.14 NCBI-DNA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
4.15 Schmooz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
5 Mathematical Packages. . . . . . . . . . . . . . . . . . . . . . . 103
5.1 Bit-Twiddling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
5.1.1 Bitwise Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
5.1.2 Integer Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
5.1.3 Bit Within Word . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
5.1.4 Field of Bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
5.1.5 Bits as Booleans . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
5.2 Modular Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
5.3 Irrational Integer Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
5.4 Irrational Real Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
5.5 Prime Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
5.6 Random Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
5.6.1 Exact Random Numbers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
5.6.2 Inexact Random Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
5.7 Discrete Fourier Transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
5.8 Cyclic Checksum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
5.9 Graphing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
5.9.1 Character Plotting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
5.9.2 PostScript Graphing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
5.9.2.1 Column Ranges. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
5.9.2.2 Drawing the Graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
5.9.2.3 Graphics Context . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
5.9.2.4 Rectangles. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
5.9.2.5 Legending . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
5.9.2.6 Legacy Plotting. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
5.9.2.7 Example Graph. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
5.10 Solid Modeling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
5.11 Color . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
5.11.1 Color Data-Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
iv
5.11.1.1 External Representation . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
5.11.1.2 White . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
5.11.2 Color Spaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
5.11.3 Spectra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
5.11.4 Color Diļ¬€erence Metrics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
5.11.5 Color Conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
5.11.6 Color Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
5.11.7 Daylight . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
5.12 Root Finding. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
5.13 Minimizing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
5.14 The Limit. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
5.15 Commutative Rings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
5.16 Rules and Rulesets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
5.17 How to Create a Commutative Ring . . . . . . . . . . . . . . . . . . . . . . . . . 158
5.18 Matrix Algebra. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
6 Database Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
6.1 Relational Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
6.1.1 Using Databases. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
6.1.2 Table Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
6.1.2.1 Single Row Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
6.1.2.2 Match-Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
6.1.2.3 Multi-Row Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
6.1.2.4 Indexed Sequential Access Methods . . . . . . . . . . . . . . . . . 168
6.1.2.5 Sequential Index Operations . . . . . . . . . . . . . . . . . . . . . . . . 168
6.1.2.6 Table Administration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
6.1.3 Database Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
6.1.4 Embedded Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
6.1.4.1 Database Extension. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
6.1.4.2 Command Intrinsics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
6.1.4.3 Deļ¬ne-tables Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
6.1.4.4 The *commands* Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
6.1.4.5 Command Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
6.1.4.6 Command Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
6.1.5 Database Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
6.1.5.1 Within-database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
6.1.5.2 Within-database Example . . . . . . . . . . . . . . . . . . . . . . . . . . 178
6.1.6 Database Browser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
6.2 Relational Infrastructure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
6.2.1 Base Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
6.2.1.1 The Base . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
6.2.1.2 Base Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
6.2.1.3 Base Field Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
6.2.1.4 Composite Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
6.2.1.5 Base Record Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
6.2.1.6 Match Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
6.2.1.7 Aggregate Base Operations . . . . . . . . . . . . . . . . . . . . . . . . . 184
6.2.1.8 Base ISAM Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
v
6.2.2 Catalog Representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
6.2.3 Relational Database Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
6.2.4 Database Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
6.3 Weight-Balanced Trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
6.3.1 Construction of Weight-Balanced Trees . . . . . . . . . . . . . . . . . . 189
6.3.2 Basic Operations on Weight-Balanced Trees . . . . . . . . . . . . . . 190
6.3.3 Advanced Operations on Weight-Balanced Trees . . . . . . . . . 191
6.3.4 Indexing Operations on Weight-Balanced Trees . . . . . . . . . . 194
7 Other Packages. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
7.1 Data Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
7.1.1 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
7.1.2 Subarrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
7.1.3 Array Mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
7.1.4 Array Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
7.1.5 Association Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
7.1.6 Byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
7.1.7 Byte/Number Conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
7.1.8 MAT-File Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
7.1.9 Portable Image Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
7.1.10 Collections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
7.1.11 Dynamic Data Type. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
7.1.12 Hash Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
7.1.13 Macroless Object System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
7.1.14 Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
7.1.15 Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
7.1.16 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
7.1.16.1 Inverter Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
7.1.16.2 Number Documention . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
7.1.16.3 Inverter code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
7.1.17 Priority Queues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
7.1.18 Queues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
7.1.19 Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
7.2 Sorting and Searching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
7.2.1 Common List Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
7.2.1.1 List construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
7.2.1.2 Lists as sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
7.2.1.3 Lists as sequences. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
7.2.1.4 Destructive list operations . . . . . . . . . . . . . . . . . . . . . . . . . . 230
7.2.1.5 Non-List functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
7.2.2 Tree operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
7.2.3 Chapter Ordering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
7.2.4 Sorting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
7.2.5 Topological Sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
7.2.6 Hashing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
7.2.7 Space-Filling Curves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
7.2.7.1 Multidimensional Space-Filling Curves . . . . . . . . . . . . . . 236
7.2.7.2 Hilbert Space-Filling Curve . . . . . . . . . . . . . . . . . . . . . . . . . 236
vi
7.2.7.3 Gray code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
7.2.7.4 Bitwise Lamination . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
7.2.7.5 Peano Space-Filling Curve . . . . . . . . . . . . . . . . . . . . . . . . . . 238
7.2.7.6 Sierpinski Curve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
7.2.8 Soundex. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
7.2.9 String Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
7.2.10 Sequence Comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
7.3 Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
7.3.1 Type Coercion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
7.3.2 String-Case. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
7.3.3 String Ports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
7.3.4 Line I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
7.3.5 Multi-Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
7.3.6 Metric Units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
7.3.6.1 SI Preļ¬xes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
7.3.6.2 Binary Preļ¬xes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
7.3.6.3 Unit Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
7.4 Standards Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
7.4.1 RnRS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
7.4.2 With-File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
7.4.3 Transcripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
7.4.4 Rev2 Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
7.4.5 Rev4 Optional Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
7.4.6 Multi-argument / and - . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
7.4.7 Multi-argument Apply . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
7.4.8 Rationalize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
7.4.9 Promises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
7.4.10 Dynamic-Wind . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
7.4.11 Eval. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
7.4.12 Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
7.4.13 SRFI. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
7.4.13.1 SRFI-1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
7.5 Session Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
7.5.1 Repl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
7.5.2 Quick Print . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
7.5.3 Debug. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
7.5.4 Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
7.5.5 Tracing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
7.6 System Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
7.6.1 Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
7.6.2 Transactions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
7.6.3 CVS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
7.7 Extra-SLIB Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
vii
8 About SLIB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
8.1 Installation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
8.1.1 Unpacking the SLIB Distribution . . . . . . . . . . . . . . . . . . . . . . . . 268
8.1.2 Install documentation and slib script . . . . . . . . . . . . . . . . . . . . . 268
8.1.3 Conļ¬gure Scheme Implementation to Locate SLIB . . . . . . . 268
8.1.4 Conļ¬gure Scheme Implementation to Locate
and Implementation Directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
8.1.5 Loading SLIB Initialization File . . . . . . . . . . . . . . . . . . . . . . . . . 269
8.1.6 Build New SLIB Catalog for the Implementation . . . . . . . . . 269
8.1.7 Implementation-speciļ¬c Instructions . . . . . . . . . . . . . . . . . . . . . 270
8.2 The SLIB script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272
8.3 Porting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272
8.4 Compiled and Implementation-Speciļ¬c Features . . . . . . . . . . . . . . . 272
8.5 Coding Guidelines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
8.5.1 Modiļ¬cations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
8.6 Copyrights . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
8.6.1 Putting code into the Public Domain . . . . . . . . . . . . . . . . . . . . 274
8.6.2 Explicit copying terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
8.6.3 Example: Company Copyright Disclaimer . . . . . . . . . . . . . . . . 274
8.7 About this manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
8.7.1 GNU Free Documentation License . . . . . . . . . . . . . . . . . . . . . . . 275
Procedure and Macro Index . . . . . . . . . . . . . . . . . . . . . 284
Variable Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
Concept and Feature Index . . . . . . . . . . . . . . . . . . . . . . 296
1
1 The Library System
SLIB is a portable library for the programming language Scheme. It provides a platform in-
dependent framework for using packages of Scheme procedures and syntax. As distributed,
SLIB contains useful packages for all Scheme implementations. Its catalog can be transpar-
ently extended to accomodate packages speciļ¬c to a site, implementation, user, or directory.
1.1 Feature
SLIB denotes features by symbols. SLIB maintains a list of features supported by a Scheme
session. The set of features provided by a session may change during that session. Some
features are properties of the Scheme implementation being used. The following intrinsic
features detail what sort of numbers are available from an implementation:
ā€¢ ā€™inexact
ā€¢ ā€™rational
ā€¢ ā€™real
ā€¢ ā€™complex
ā€¢ ā€™bignum
SLIB initialization (in require.scm) tests and provides any of these numeric features which
are appropriate.
Other features correspond to the presence of packages of Scheme procedures or syntax
(macros).
[Function]provided? feature
Returns #t if feature is present in the current Scheme session; otherwise #f. More
speciļ¬cally, provided? returns #t if the symbol feature is the software-type, the
scheme-implementation-type
1
, or if feature has been provided by a module already
loaded; and #f otherwise.
In some implementations provided? tests whether a module has been required by
any module or in any thread; other implementations will have provided? reļ¬‚ect only
the modules required by that particular session or thread.
To work portably in both scenarios, use provided? only to test whether intrinsic
properties (like those above) are present.
The feature argument can also be an expression calling and, or, and not of features.
The boolean result of the logical question asked by feature is returned.
The generalization of provided? for arbitrary features and catalog is feature-eval:
[Function]feature-eval expression provided?
Evaluates and, or, and not forms in expression, using the values returned by calling
provided? on the leaf symbols. feature-eval returns the boolean result of the logical
combinations.
1
scheme-implementation-type is the name symbol of the running Scheme implementation (RScheme,
|STk|, Bigloo, chez, Elk, gambit, gauche, guile, JScheme, kawa, MacScheme, MITScheme, Pocket-
Scheme, S7, Scheme48, Scheme->C, Scheme48, Scsh, SISC, T, umb-scheme, or Vscm). Dependence on
scheme-implementation-type is almost always the wrong way to do things.
Chapter 1: The Library System 2
[Procedure]provide feature
Informs SLIB that feature is supported in this session.
(provided? ā€™foo)
ā‡’
#f
(provide ā€™foo)
(provided? ā€™foo)
ā‡’
#t
1.2 Require
SLIB creates and maintains a catalog mapping features to locations of ļ¬les introducing
procedures and syntax denoted by those features.
[Variable]*catalog*
Is an association list of features (symbols) and pathnames which will supply those
features. The pathname can be either a string or a pair. If pathname is a pair then
the ļ¬rst element should be a macro feature symbol, source, compiled, or one of
the other cases described in Section 1.3 [Library Catalogs], page 3. The cdr of the
pathname should be either a string or a list.
At the beginning of each section of this manual, there is a line like (require ā€™feature).
The Scheme ļ¬les comprising SLIB are cataloged so that these feature names map to the
corresponding ļ¬les.
SLIB provides a form, require, which loads the ļ¬les providing the requested feature.
[Procedure]require feature
ā€¢ If (provided? feature) is true, then require just returns.
ā€¢ Otherwise, if feature is found in the catalog, then the corresponding ļ¬les will
be loaded and (provided? feature) will henceforth return #t. That feature is
thereafter provided.
ā€¢ Otherwise (feature not found in the catalog), an error is signaled.
There is a related form require-if, used primarily for enabling compilers to statically
include modules which would be dynamically loaded by interpreters.
[Procedure]require-if condition feature
Requires feature if condition is true.
The random module uses require-if to ļ¬‚ag object->string as a (dynamic) required
module.
(require ā€™byte)
(require ā€™logical)
(require-if ā€™compiling ā€™object->string)
The batch module uses require-if to ļ¬‚ag posix-time as a module to load if the imple-
mentation supports large precision exact integers.
(require-if ā€™(and bignum compiling) ā€™posix-time)
The catalog can also be queried using slib:in-catalog?.
Chapter 1: The Library System 3
[Function]slib:in-catalog? feature
Returns a CDR of the catalog entry if one was found for the symbol feature in the alist
*catalog* (and transitively through any symbol aliases encountered). Otherwise,
returns #f. The format of catalog entries is explained in Section 1.3 [Library Catalogs],
page 3.
1.3 Library Catalogs
Catalog ļ¬les consist of one or more association lists. In the circumstance where a feature
symbol appears in more than one list, the latter listā€™s association is retrieved. Here are the
supported formats for elements of catalog lists:
(feature . <symbol>)
Redirects to the feature named <symbol>.
(feature . "<path>")
Loads ļ¬le <path>.
(feature source "<path>")
slib:loads the Scheme source ļ¬le <path>.
(feature compiled "<path>" ...)
slib:load-compileds the ļ¬les <path> . . . .
(feature aggregate <symbol> ...)
requires the features <symbol> . . . .
The various macro styles ļ¬rst require the named macro package, then just load <path> or
load-and-macro-expand <path> as appropriate for the implementation.
(feature defmacro "<path>")
defmacro:loads the Scheme source ļ¬le <path>.
(feature macro-by-example "<path>")
defmacro:loads the Scheme source ļ¬le <path>.
(feature macro "<path>")
macro:loads the Scheme source ļ¬le <path>.
(feature macros-that-work "<path>")
macro:loads the Scheme source ļ¬le <path>.
(feature syntax-case "<path>")
macro:loads the Scheme source ļ¬le <path>.
(feature syntactic-closures "<path>")
macro:loads the Scheme source ļ¬le <path>.
1.4 Catalog Creation
At the start of an interactive session no catalog is present, but is created with the ļ¬rst
catalog inquiry (such as (require ā€™random)). Several sources of catalog information are
combined to produce the catalog:
ā€¢ standard SLIB packages.
Chapter 1: The Library System 4
ā€¢ additional packages of interest to this site.
ā€¢ packages speciļ¬cally for the variety of Scheme which this session is running. This cat-
alog, if it exists, is the ļ¬le implcat in implementation-invicinity, which is created
by loading mkimpcat.scm in implementation-invicinity if it exists.
ā€¢ packages this user wants to always have available. This catalog is the ļ¬le homecat in
the userā€™s HOME directory.
ā€¢ packages germane to working in this (current working) directory. This catalog is the ļ¬le
usercat in the directory to which it applies. One would typically cd to this directory
before starting the Scheme session.
ā€¢ packages which are part of an application program.
SLIB combines the catalog information which doesnā€™t vary per user into the ļ¬le slibcat
in the implementation-vicinity. Therefore slibcat needs change only when new software is
installed or compiled. Because the actual pathnames of ļ¬les can diļ¬€er from installation to
installation, SLIB builds a separate catalog for each implementation it is used with.
The deļ¬nition of *slib-version* in SLIB ļ¬le require.scm is checked against the catalog
association of *slib-version* to ascertain when versions have changed. It is a reasonable
practice to change the deļ¬nition of *slib-version* whenever the library is changed. If
multiple implementations of Scheme use SLIB, remember that recompiling one slibcat will
update only that implementationā€™s catalog.
The compilation scripts of Scheme implementations which work with SLIB can automati-
cally trigger catalog compilation by deleting slibcat or by invoking require of a special
feature:
[Procedure]require ā€™new-catalog
This will load mklibcat, which compiles and writes a new slibcat.
Another special feature of require erases SLIBā€™s catalog, forcing it to be reloaded the next
time the catalog is queried.
[Procedure]require #f
Removes SLIBā€™s catalog information. This should be done before saving an executable
image so that, when restored, its catalog will be loaded afresh.
1.5 Catalog Vicinities
Each ļ¬le in the table below is descibed in terms of its ļ¬le-system independent vicinity (see
Section 2.1 [Vicinity], page 11). The entries of a catalog in the table override those of
catalogs above it in the table.
implementation-vicinity slibcat
This ļ¬le contains the associations for the packages comprising SLIB, the
implcat and the sitecats. The associations in the other catalogs override
those of the standard catalog.
library-vicinity mklibcat.scm
creates slibcat.
Chapter 1: The Library System 5
library-vicinity sitecat
This ļ¬le contains the associations speciļ¬c to an SLIB installation.
implementation-vicinity implcat
This ļ¬le contains the associations speciļ¬c to an implementation of
Scheme. Diļ¬€erent implementations of Scheme should have diļ¬€erent
implementation-vicinity.
implementation-vicinity mkimpcat.scm
if present, creates implcat.
implementation-vicinity sitecat
This ļ¬le contains the associations speciļ¬c to a Scheme implementation instal-
lation.
home-vicinity homecat
This ļ¬le contains the associations speciļ¬c to an SLIB user.
user-vicinity usercat
This ļ¬le contains associations aļ¬€ecting only those sessions whose working di-
rectory is user-vicinity.
Here is an example of a usercat catalog. A program in this directory can invoke the ā€˜runā€™
feature with (require ā€™run).
;;; "usercat": SLIB catalog additions for SIMSYNCH. -*-scheme-*-
(
(simsynch . "../synch/simsynch.scm")
(run . "../synch/run.scm")
(schlep . "schlep.scm")
)
Copying usercat to many directories is inconvenient. Application programs which arenā€™t
always run in specially prepared directories can nonetheless register their features during
initialization.
[Procedure]catalog:read vicinity catalog
Reads ļ¬le named by string catalog in vicinity, resolving all paths relative to vicinity,
and adds those feature associations to *catalog*.
catalog:read would typically be used by an application program having dynamically
loadable modules. For instance, to register factoring and other modules in *catalog*,
JACAL does:
(catalog:read (program-vicinity) "jacalcat")
For an application program there are three appropriate venues for registering its catalog
associations:
ā€¢ in a usercat ļ¬le in the directory where the program runs; or
ā€¢ in an implcat ļ¬le in the implementation-vicinity; or
ā€¢ in an application program directory; loaded by calling catalog:read.
Chapter 1: The Library System 6
1.6 Compiling Scheme
To use Scheme compilers eļ¬€ectively with SLIB the compiler needs to know which SLIB
modules are to be compiled and which symbols are exported from those modules.
The procedures in this section automate the extraction of this information from SLIB
modules. They are guaranteed to work on SLIB modules; to use them on other sources,
those sources should follow SLIB conventions.
1.6.1 Module Conventions
ā€¢ All the top-level require commands have one quoted argument and are positioned
before other Scheme deļ¬nitions and expressions in the ļ¬le.
ā€¢ Any conditionally required SLIB modules
2
also appear at the beginning of their ļ¬les
conditioned on the feature compiling using require-if (see Section 1.2 [Require],
page 2).
(require ā€™logical)
(require ā€™multiarg/and-)
(require-if ā€™compiling ā€™sort)
(require-if ā€™compiling ā€™ciexyz)
ā€¢ Schmooz-style comments preceding a deļ¬nition, identify that deļ¬nition as an exported
identiļ¬er (see Section 4.15 [Schmooz], page 101). For non-schmooz ļ¬les, putting ā€˜;@ā€™ at
the beginning of the line immediately preceding the deļ¬nition (define, define-syntax,
or defmacro) suļ¬ƒces.
;@
(define (identity <obj>) <obj>)
ā€¢ Syntax (macro) deļ¬nitions are grouped at the end of a module ļ¬le.
ā€¢ Modules deļ¬ning macros do not invoke those macros. SLIB macro implementations
are exempt from this rule.
An example of how to expand macro invocations is:
(require ā€™macros-that-work)
(require ā€™yasos)
(require ā€™pprint-file)
(pprint-filter-file "collect.scm" macwork:expand)
1.6.2 Module Manifests
(require ā€™manifest)
In some of these examples, slib:catalog is the SLIB part of the catalog; it is free of compiled
and implementation-speciļ¬c entries. It would be deļ¬ned by:
(define slib:catalog (cdr (member (assq ā€™null *catalog*) *catalog*)))
[Function]file->requires ļ¬le provided? catalog
Returns a list of the features required by ļ¬le assuming the predicate provided? and
association-list catalog.
2
There are some functions with internal require calls to delay loading modules until they are needed.
While this reduces startup latency for interpreters, it can produce headaches for compilers.
Chapter 1: The Library System 7
(define (provided+? . features)
(lambda (feature)
(or (memq feature features) (provided? feature))))
(file->requires "obj2str.scm" (provided+? ā€™compiling) ā€™())
ā‡’
(string-port generic-write)
(file->requires "obj2str.scm" provided? ā€™())
ā‡’
(string-port)
[Function]feature->requires feature provided? catalog
Returns a list of the features required by feature assuming the predicate provided?
and association-list catalog.
(feature->requires ā€™batch (provided+? ā€™compiling) *catalog*)
ā‡’
(tree line-i/o databases parameters string-port
pretty-print common-list-functions posix-time)
(feature->requires ā€™batch provided? *catalog*)
ā‡’
(tree line-i/o databases parameters string-port
pretty-print common-list-functions)
(feature->requires ā€™batch provided? ā€™((batch . "batch")))
ā‡’
(tree line-i/o databases parameters string-port
pretty-print common-list-functions)
[Function]feature->requires* feature provided? catalog
Returns a list of the features transitively required by feature assuming the predicate
provided? and association-list catalog.
[Function]file->requires* ļ¬le provided? catalog
Returns a list of the features transitively required by ļ¬le assuming the predicate
provided? and association-list catalog.
[Function]file->loads ļ¬le
Returns a list of strings naming existing ļ¬les loaded (load slib:load slib:load-source
macro:load defmacro:load syncase:load synclo:load macwork:load) by ļ¬le or any of
the ļ¬les it loads.
(file->loads (in-vicinity (library-vicinity) "scainit.scm"))
ā‡’
("/usr/local/lib/slib/scaexpp.scm"
"/usr/local/lib/slib/scaglob.scm"
"/usr/local/lib/slib/scaoutp.scm")
[Function]load->path exp
Given a (load ā€™<expr>), where <expr> is a string or vicinity stuļ¬€), (load->path
<expr>) ļ¬gures a path to the ļ¬le. load->path returns that path if it names an
existing ļ¬le; otherwise #f.
Chapter 1: The Library System 8
(load->path ā€™(in-vicinity (library-vicinity) "mklibcat"))
ā‡’
"/usr/local/lib/slib/mklibcat.scm"
[Function]file->definitions ļ¬le deļ¬ner . . .
Returns a list of the identiļ¬er symbols deļ¬ned by SLIB (or SLIB-style) ļ¬le ļ¬le. The
optional arguments deļ¬ners should be symbols signifying a deļ¬ning form. If none
are supplied, then the symbols define-operation, define, define-syntax, and
defmacro are captured.
(file->definitions "random.scm")
ā‡’
(*random-state* make-random-state
seed->random-state copy-random-state random
random:chunk)
[Function]file->exports ļ¬le deļ¬ner . . .
Returns a list of the identiļ¬er symbols exported (advertised) by SLIB (or SLIB-style)
ļ¬le ļ¬le. The optional arguments deļ¬ners should be symbols signifying a deļ¬ning form.
If none are supplied, then the symbols define-operation, define, define-syntax,
and defmacro are captured.
(file->exports "random.scm")
ā‡’
(make-random-state seed->random-state
copy-random-state random)
(file->exports "randinex.scm")
ā‡’
(random:solid-sphere! random:hollow-sphere!
random:normal-vector! random:normal
random:exp random:uniform)
[Function]feature->export-alist feature catalog
Returns a list of lists; each sublist holding the name of the ļ¬le implementing feature,
and the identiļ¬er symbols exported (advertised) by SLIB (or SLIB-style) feature
feature, in catalog.
[Function]feature->exports feature catalog
Returns a list of all exports of feature.
In the case of aggregate features, more than one ļ¬le may have export lists to report:
(feature->export-alist ā€™r5rs slib:catalog))
ā‡’
(("/usr/local/lib/slib/values.scm"
call-with-values values)
("/usr/local/lib/slib/mbe.scm"
define-syntax macro:expand
macro:load macro:eval)
("/usr/local/lib/slib/eval.scm"
eval scheme-report-environment
null-environment interaction-environment))
(feature->export-alist ā€™stdio *catalog*)
Chapter 1: The Library System 9
ā‡’
(("/usr/local/lib/slib/scanf.scm"
fscanf sscanf scanf scanf-read-list)
("/usr/local/lib/slib/printf.scm"
sprintf printf fprintf)
("/usr/local/lib/slib/stdio.scm"
stderr stdout stdin))
(feature->exports ā€™stdio slib:catalog)
ā‡’
(fscanf sscanf scanf scanf-read-list
sprintf printf fprintf stderr stdout stdin)
1.6.3 Module Semantics
For the purpose of compiling Scheme code, each top-level require makes the identiļ¬ers
exported by its featureā€™s module defined (or defmacroed or deļ¬ned-syntaxed) within the
ļ¬le (being compiled) headed with those requires.
Top-level occurrences of require-if make deļ¬ned the exports from the module named
by the second argument if the feature-expression ļ¬rst argument is true in the target environ-
ment. The target feature compiling should be provided during this phase of compilation.
Non-top-level SLIB occurences of require and require-if of quoted features can be
ignored by compilers. The SLIB modules will all have top-level constructs for those features.
Note that aggregate catalog entries import more than one module. Implementations of
require may or may not be transitive; code which uses module exports without requiring
the providing module is in error.
In the SLIB modules modular, batch, hash, common-lisp-time, commutative-ring,
charplot, logical, common-list-functions, coerce and break there is code conditional
on features being provided?. Most are testing for the presence of features which are intrinsic
to implementations (inexacts, bignums, ...).
In all cases these provided? tests can be evaluated at compile-time using feature-eval
(see Section 1.1 [Feature], page 1). The simplest way to compile these constructs may be
to treat provided? as a macro.
1.6.4 Top-level Variable References
(require ā€™top-refs)
These procedures complement those in Section 1.6.2 [Module Manifests], page 6, by ļ¬nding
the top-level variable references in Scheme source code. They work by traversing expressions
and deļ¬nitions, keeping track of bindings encountered. It is certainly possible to foil these
functions, but they return useful information about SLIB source code.
[Function]top-refs obj
Returns a list of the top-level variables referenced by the Scheme expression obj.
[Function]top-refs<-file ļ¬lename
ļ¬lename should be a string naming an existing ļ¬le containing Scheme source code.
top-refs<-file returns a list of the top-level variable references made by expressions
in the ļ¬le named by ļ¬lename.
Chapter 1: The Library System 10
Code in modules which ļ¬lename requires is not traversed. Code in ļ¬les loaded
from top-level is traversed if the expression argument to load, slib:load,
slib:load-source, macro:load, defmacro:load, synclo:load, syncase:load, or
macwork:load is a literal string constant or composed of combinations of vicinity
functions and string literal constants; and the resulting ļ¬le exists (possibly with
".scm" appended).
The following function parses an Info Index.
3
[Function]exports<-info-index ļ¬le n . . .
n . . . must be an increasing series of positive integers. exports<-info-index returns
a list of all the identiļ¬ers appearing in the nth . . . (info) indexes of ļ¬le. The identiļ¬ers
have the case that the implementationā€™s read uses for symbols. Identiļ¬ers containing
spaces (eg. close-base on base-table) are not included. #f is returned if the index
is not found.
Each info index is headed by a ā€˜* Menu:ā€™ line. To list the symbols in the ļ¬rst and
third info indexes do:
(exports<-info-index "slib.info" 1 3)
1.6.5 Module Analysis
(require ā€™vet)
[Function]vet-slib ļ¬le1 . . .
Using the procedures in the top-refs and manifest modules, vet-slib analyzes
each SLIB module and ļ¬le1, . . ., reporting about any procedure or macro deļ¬ned
whether it is:
orphaned deļ¬ned, not called, not exported;
missing called, not deļ¬ned, and not exported by its required modules;
undocumented-export
Exported by module, but no index entry in slib.info;
And for the library as a whole:
documented-unexport
Index entry in slib.info, but no module exports it.
This straightforward analysis caught three full days worth of never-executed branches,
transitive require assumptions, spelling errors, undocumented procedures, missing
procedures, and cyclic dependencies in SLIB.
The optional arguments ļ¬le1, . . . provide a simple way to vet prospective SLIB
modules.
3
Although it will work on large info ļ¬les, feeding it an excerpt is much faster; and has less chance of being
confused by unusual text in the info ļ¬le. This command excerpts the SLIB index into slib-index.info:
info -f slib2d6.info -n "Index" -o slib-index.info
11
2 Universal SLIB Procedures
The procedures described in these sections are supported by all implementations as part of
the ā€˜*.initā€™ ļ¬les or by require.scm.
2.1 Vicinity
A vicinity is a descriptor for a place in the ļ¬le system. Vicinities hide from the programmer
the concepts of host, volume, directory, and version. Vicinities express only the concept
of a ļ¬le environment where a ļ¬le name can be resolved to a ļ¬le in a system independent
manner. Vicinities can even be used on ļ¬‚at ļ¬le systems (which have no directory structure)
by having the vicinity express constraints on the ļ¬le name.
All of these procedures are ļ¬le-system dependent. Use of these vicinity procedures can
make programs ļ¬le-system independent.
These procedures are provided by all implementations. On most systems a vicinity is a
string.
[Function]make-vicinity dirpath
Returns dirpath as a vicinity for use as ļ¬rst argument to in-vicinity.
[Function]pathname->vicinity path
Returns the vicinity containing path.
(pathname->vicinity "/usr/local/lib/scm/Link.scm")
ā‡’
"/usr/local/lib/scm/"
[Function]program-vicinity
Returns the vicinity of the currently loading Scheme code. For an interpreter this
would be the directory containing source code. For a compiled system (with multiple
ļ¬les) this would be the directory where the object or executable ļ¬les are. If no ļ¬le
is currently loading, then the result is undeļ¬ned. Warning: program-vicinity can
return incorrect values if your program escapes back into a load continuation.
[Function]library-vicinity
Returns the vicinity of the shared Scheme library.
[Function]implementation-vicinity
Returns the vicinity of the underlying Scheme implementation. This vicinity will
likely contain startup code and messages and a compiler.
[Function]user-vicinity
Returns the vicinity of the current directory of the user. On most systems this is ""
(the empty string).
[Function]home-vicinity
Returns the vicinity of the userā€™s HOME directory, the directory which typically
contains ļ¬les which customize a computer environment for a user. If scheme is running
without a user (eg. a daemon) or if this concept is meaningless for the platform, then
home-vicinity returns #f.
Chapter 2: Universal SLIB Procedures 12
[Function]vicinity:suffix? chr
Returns the ā€˜#tā€™ if chr is a vicinity suļ¬ƒx character; and #f otherwise. Typical vicinity
suļ¬ƒxes are ā€˜/ā€™, ā€˜:ā€™, and ā€˜\ā€™,
[Function]in-vicinity vicinity ļ¬lename
Returns a ļ¬lename suitable for use by slib:load, slib:load-source,
slib:load-compiled, open-input-file, open-output-file, etc. The returned
ļ¬lename is ļ¬lename in vicinity. in-vicinity should allow ļ¬lename to override
vicinity when ļ¬lename is an absolute pathname and vicinity is equal to the value
of (user-vicinity). The behavior of in-vicinity when ļ¬lename is absolute and
vicinity is not equal to the value of (user-vicinity) is unspeciļ¬ed. For most
systems in-vicinity can be string-append.
[Function]sub-vicinity vicinity name
Returns the vicinity of vicinity restricted to name. This is used for large systems
where names of ļ¬les in subsystems could conļ¬‚ict. On systems with directory structure
sub-vicinity will return a pathname of the subdirectory name of vicinity.
[Function]with-load-pathname path thunk
path should be a string naming a ļ¬le being read or loaded. with-load-pathname
evaluates thunk in a dynamic scope where an internal variable is bound to path; the
internal variable is used for messages and program-vicinity. with-load-pathname
returns the value returned by thunk.
2.2 Conļ¬guration
These constants and procedures describe characteristics of the Scheme and underlying op-
erating system. They are provided by all implementations.
[Constant]char-code-limit
An integer 1 larger that the largest value which can be returned by char->integer.
[Constant]most-positive-fixnum
In implementations which support integers of practically unlimited size, most-positive-
ļ¬xnum is a large exact integer within the range of exact integers that may result from
computing the length of a list, vector, or string.
In implementations which do not support integers of practically unlimited size, most-
positive-ļ¬xnum is the largest exact integer that may result from computing the length
of a list, vector, or string.
[Constant]slib:tab
The tab character.
[Constant]slib:form-feed
The form-feed character.
[Function]software-type
Returns a symbol denoting the generic operating system type. For instance, unix,
vms, macos, amiga, or ms-dos.
Chapter 2: Universal SLIB Procedures 13
[Function]slib:report-version
Displays the versions of SLIB and the underlying Scheme implementation and the
name of the operating system. An unspeciļ¬ed value is returned.
(slib:report-version)
ā‡’
slib "3b6" on scm "5b1" on unix
[Function]slib:report
Displays the information of (slib:report-version) followed by almost all the infor-
mation neccessary for submitting a problem report. An unspeciļ¬ed value is returned.
[Function]slib:report #t
provides a more verbose listing.
[Function]slib:report ļ¬lename
Writes the verbose report to ļ¬le filename.
(slib:report)
ā‡’
slib "3b6" on scm "5b1" on unix
(implementation-vicinity) is "/usr/local/lib/scm/"
(library-vicinity) is "/usr/local/lib/slib/"
(scheme-file-suffix) is ".scm"
loaded slib:features :
trace alist qp sort
common-list-functions macro values getopt
compiled
implementation slib:features :
bignum complex real rational
inexact vicinity ed getenv
tmpnam abort transcript with-file
ieee-p1178 r4rs rev4-optional-procedures hash
object-hash delay eval dynamic-wind
multiarg-apply multiarg/and- logical defmacro
string-port source current-time record
rev3-procedures rev2-procedures sun-dl string-case
array dump char-ready? full-continuation
system
implementation *catalog* :
(i/o-extensions compiled "/usr/local/lib/scm/ioext.so")
...
2.3 Input/Output
These procedures are provided by all implementations.
[Function]file-exists? ļ¬lename
Returns #t if the speciļ¬ed ļ¬le exists. Otherwise, returns #f. If the underlying imple-
mentation does not support this feature then #f is always returned.
Chapter 2: Universal SLIB Procedures 14
[Function]delete-file ļ¬lename
Deletes the ļ¬le speciļ¬ed by ļ¬lename. If ļ¬lename can not be deleted, #f is returned.
Otherwise, #t is returned.
[Function]open-file ļ¬lename modes
ļ¬lename should be a string naming a ļ¬le. open-file returns a port depending on
the symbol modes:
r an input port capable of delivering characters from the ļ¬le.
rb a binary input port capable of delivering characters from the ļ¬le.
w an output port capable of writing characters to a new ļ¬le by that name.
wb a binary output port capable of writing characters to a new ļ¬le by that
name.
If an implementation does not distinguish between binary and non-binary ļ¬les, then
it must treat rb as r and wb as w.
If the ļ¬le cannot be opened, either #f is returned or an error is signalled. For output,
if a ļ¬le with the given name already exists, the eļ¬€ect is unspeciļ¬ed.
[Function]port? obj
Returns #t if obj is an input or output port, otherwise returns #f.
[Procedure]close-port port
Closes the ļ¬le associated with port, rendering the port incapable of delivering or
accepting characters.
close-file has no eļ¬€ect if the ļ¬le has already been closed. The value returned is
unspeciļ¬ed.
[Function]call-with-open-ports proc ports . . .
[Function]call-with-open-ports ports . . . proc
Proc should be a procedure that accepts as many arguments as there are ports passed
to call-with-open-ports. call-with-open-ports calls proc with ports . . .. If
proc returns, then the ports are closed automatically and the value yielded by the proc
is returned. If proc does not return, then the ports will not be closed automatically
unless it is possible to prove that the ports will never again be used for a read or
write operation.
[Function]tmpnam
Returns a pathname for a ļ¬le which will likely not be used by any other process.
Successive calls to (tmpnam) will return diļ¬€erent pathnames.
[Function]current-error-port
Returns the current port to which diagnostic and error output is directed.
[Procedure]force-output
[Procedure]force-output port
Forces any pending output on port to be delivered to the output device and returns
an unspeciļ¬ed value. The port argument may be omitted, in which case it defaults
to the value returned by (current-output-port).
Chapter 2: Universal SLIB Procedures 15
[Function]file-position port
[Function]file-position port #f
port must be open to a ļ¬le. file-position returns the current position of the
character in port which will next be read or written. If the implementation does not
support ļ¬le-position, then #f is returned.
[Function]file-position port k
port must be open to a ļ¬le. file-position sets the current position in port which
will next be read or written. If successful, #t is returned; otherwise file-position
returns #f.
[Function]output-port-width
[Function]output-port-width port
Returns the width of port, which defaults to (current-output-port) if absent. If
the width cannot be determined 79 is returned.
[Function]output-port-height
[Function]output-port-height port
Returns the height of port, which defaults to (current-output-port) if absent. If
the height cannot be determined 24 is returned.
2.4 System
These procedures are provided by all implementations.
[Procedure]slib:load-source name
Loads a ļ¬le of Scheme source code from name with the default ļ¬lename extension
used in SLIB. For instance if the ļ¬lename extension used in SLIB is .scm then
(slib:load-source "foo") will load from ļ¬le foo.scm.
[Procedure]slib:load-compiled name
On implementations which support separtely loadable compiled modules, loads a
ļ¬le of compiled code from name with the implementationā€™s ļ¬lename extension for
compiled code appended.
[Procedure]slib:load name
Loads a ļ¬le of Scheme source or compiled code from name with the appropriate
suļ¬ƒxes appended. If both source and compiled code are present with the appropriate
names then the implementation will load just one. It is up to the implementation to
choose which one will be loaded.
If an implementation does not support compiled code then slib:load will be identical
to slib:load-source.
[Procedure]slib:eval obj
eval returns the value of obj evaluated in the current top level environment.
Section 7.4.11 [Eval], page 251, provides a more general evaluation facility.
[Procedure]slib:eval-load ļ¬lename eval
ļ¬lename should be a string. If ļ¬lename names an existing ļ¬le, the Scheme source
code expressions and deļ¬nitions are read from the ļ¬le and eval called with them
Chapter 2: Universal SLIB Procedures 16
sequentially. The slib:eval-load procedure does not aļ¬€ect the values returned by
current-input-port, current-error-port, and current-output-port.
[Procedure]slib:warn arg1 arg2 . . .
Outputs a warning message containing the arguments.
[Procedure]slib:error arg1 arg2 . . .
Outputs an error message containing the arguments, aborts evaluation of the current
form and responds in a system dependent way to the error. Typical responses are to
abort the program or to enter a read-eval-print loop.
[Procedure]slib:exit n
[Procedure]slib:exit
Exits from the Scheme session returning status n to the system. If n is omitted or #t,
a success status is returned to the system (if possible). If n is #f a failure is returned
to the system (if possible). If n is an integer, then n is returned to the system (if
possible). If the Scheme session cannot exit, then an unspeciļ¬ed value is returned
from slib:exit.
[Function]browse-url url
Web browsers have become so ubiquitous that programming languagues should sup-
port a uniform interface to them.
If a browser is running, browse-url causes the browser to display the page speciļ¬ed
by string url and returns #t.
If the browser is not running, browse-url starts a browser displaying the argument
url. If the browser starts as a background job, browse-url returns #t immediately; if
the browser starts as a foreground job, then browse-url returns #t when the browser
exits; otherwise (if no browser) it returns #f.
2.5 Miscellany
These procedures are provided by all implementations.
[Function]identity x
identity returns its argument.
Example:
(identity 3)
ā‡’
3
(identity ā€™(foo bar))
ā‡’
(foo bar)
(map identity lst)
ā‰” (copy-list lst)
2.5.1 Mutual Exclusion
An exchanger is a procedure of one argument regulating mutually exclusive access to a
resource. When a exchanger is called, its current content is returned, while being replaced
by its argument in an atomic operation.
Chapter 2: Universal SLIB Procedures 17
[Function]make-exchanger obj
Returns a new exchanger with the argument obj as its initial content.
(define queue (make-exchanger (list a)))
A queue implemented as an exchanger holding a list can be protected from reentrant
execution thus:
(define (pop queue)
(let ((lst #f))
(dynamic-wind
(lambda () (set! lst (queue #f)))
(lambda () (and lst (not (null? lst))
(let ((ret (car lst)))
(set! lst (cdr lst))
ret)))
(lambda () (and lst (queue lst))))))
(pop queue)
ā‡’
a
(pop queue)
ā‡’
#f
2.5.2 Legacy
The following procedures were present in Scheme until R4RS (see Section ā€œLanguage
changes ā€ in Revised(4) Scheme). They are provided by all SLIB implementations.
[Constant]t
Deļ¬ned as #t.
[Constant]nil
Deļ¬ned as #f.
[Function]last-pair l
Returns the last pair in the list l. Example:
(last-pair (cons 1 2))
ā‡’
(1 . 2)
(last-pair ā€™(1 2))
ā‡’
(2)
ā‰” (cons 2 ā€™())
18
3 Scheme Syntax Extension Packages
3.1 Defmacro
Defmacros are supported by all implementations.
[Function]gentemp
Returns a new (interned) symbol each time it is called. The symbol names are
implementation-dependent
(gentemp)
ā‡’
scm:G0
(gentemp)
ā‡’
scm:G1
[Function]defmacro:eval e
Returns the slib:eval of expanding all defmacros in scheme expression e.
[Function]defmacro:load ļ¬lename
ļ¬lename should be a string. If ļ¬lename names an existing ļ¬le, the defmacro:load
procedure reads Scheme source code expressions and deļ¬nitions from the ļ¬le and eval-
uates them sequentially. These source code expressions and deļ¬nitions may contain
defmacro deļ¬nitions. The defmacro:load procedure does not aļ¬€ect the values re-
turned by current-input-port, current-error-port, and current-output-port.
[Function]defmacro? sym
Returns #t if sym has been deļ¬ned by defmacro, #f otherwise.
[Function]macroexpand-1 form
[Function]macroexpand form
If form is a macro call, macroexpand-1 will expand the macro call once and return
it. A form is considered to be a macro call only if it is a cons whose car is a symbol
for which a defmacro has been deļ¬ned.
macroexpand is similar to macroexpand-1, but repeatedly expands form until it is no
longer a macro call.
[Macro]defmacro name lambda-list form . . .
When encountered by defmacro:eval, defmacro:macroexpand*, or defmacro:load
deļ¬nes a new macro which will henceforth be expanded when encountered by
defmacro:eval, defmacro:macroexpand*, or defmacro:load.
3.1.1 Defmacroexpand
(require ā€™defmacroexpand)
[Function]defmacro:expand* e
Returns the result of expanding all defmacros in scheme expression e.
Chapter 3: Scheme Syntax Extension Packages 19
3.2 R4RS Macros
(require ā€™macro) is the appropriate call if you want R4RS high-level macros but donā€™t
care about the low level implementation. If an SLIB R4RS macro implementation is already
loaded it will be used. Otherwise, one of the R4RS macros implemetations is loaded.
The SLIB R4RS macro implementations support the following uniform interface:
[Function]macro:expand sexpression
Takes an R4RS expression, macro-expands it, and returns the result of the macro
expansion.
[Function]macro:eval sexpression
Takes an R4RS expression, macro-expands it, evals the result of the macro expansion,
and returns the result of the evaluation.
[Procedure]macro:load ļ¬lename
ļ¬lename should be a string. If ļ¬lename names an existing ļ¬le, the macro:load pro-
cedure reads Scheme source code expressions and deļ¬nitions from the ļ¬le and eval-
uates them sequentially. These source code expressions and deļ¬nitions may contain
macro deļ¬nitions. The macro:load procedure does not aļ¬€ect the values returned by
current-input-port, current-error-port, and current-output-port.
3.3 Macro by Example
(require ā€™macro-by-example)
A vanilla implementation of Macro by Example (Eugene Kohlbecker, R4RS) by Dorai
Sitaram, (dorai @ cs.rice.edu) using defmacro.
ā€¢ generating hygienic global define-syntax Macro-by-Example macros cheaply.
ā€¢ can deļ¬ne macros which use ....
ā€¢ neednā€™t worry about a lexical variable in a macro deļ¬nition clashing with a variable
from the macro use context
ā€¢ donā€™t suļ¬€er the overhead of redeļ¬ning the repl if defmacro natively supported (most
implementations)
3.3.1 Caveat
These macros are not referentially transparent (see Section ā€œMacrosā€ in Revised(4) Scheme).
Lexically scoped macros (i.e., let-syntax and letrec-syntax) are not supported. In any
case, the problem of referential transparency gains poignancy only when let-syntax and
letrec-syntax are used. So you will not be courting large-scale disaster unless youā€™re
using system-function names as local variables with unintuitive bindings that the macro
canā€™t use. However, if you must have the full r4rs macro functionality, look to the more
featureful (but also more expensive) versions of syntax-rules available in slib Section 3.4
[Macros That Work], page 20, Section 3.5 [Syntactic Closures], page 23, and Section 3.6
[Syntax-Case Macros], page 30.
[Macro]define-syntax keyword transformer-spec
The keyword is an identiļ¬er, and the transformer-spec should be an instance of
syntax-rules.
Chapter 3: Scheme Syntax Extension Packages 20
The top-level syntactic environment is extended by binding the keyword to the spec-
iļ¬ed transformer.
(define-syntax let*
(syntax-rules ()
((let* () body1 body2 ...)
(let () body1 body2 ...))
((let* ((name1 val1) (name2 val2) ...)
body1 body2 ...)
(let ((name1 val1))
(let* (( name2 val2) ...)
body1 body2 ...)))))
[Macro]syntax-rules literals syntax-rule . . .
literals is a list of identiļ¬ers, and each syntax-rule should be of the form
(pattern template)
where the pattern and template are as in the grammar above.
An instance of syntax-rules produces a new macro transformer by specifying a
sequence of hygienic rewrite rules. A use of a macro whose keyword is associated with
a transformer speciļ¬ed by syntax-rules is matched against the patterns contained
in the syntax-rules, beginning with the leftmost syntax-rule. When a match is found,
the macro use is trancribed hygienically according to the template.
Each pattern begins with the keyword for the macro. This keyword is not involved
in the matching and is not considered a pattern variable or literal identiļ¬er.
3.4 Macros That Work
(require ā€™macros-that-work)
Macros That Work diļ¬€ers from the other R4RS macro implementations in that it does
not expand derived expression types to primitive expression types.
[Function]macro:expand expression
[Function]macwork:expand expression
Takes an R4RS expression, macro-expands it, and returns the result of the macro
expansion.
[Function]macro:eval expression
[Function]macwork:eval expression
macro:eval returns the value of expression in the current top level environment.
expression can contain macro deļ¬nitions. Side eļ¬€ects of expression will aļ¬€ect the top
level environment.
[Procedure]macro:load ļ¬lename
[Procedure]macwork:load ļ¬lename
ļ¬lename should be a string. If ļ¬lename names an existing ļ¬le, the macro:load pro-
cedure reads Scheme source code expressions and deļ¬nitions from the ļ¬le and eval-
uates them sequentially. These source code expressions and deļ¬nitions may contain
Chapter 3: Scheme Syntax Extension Packages 21
macro deļ¬nitions. The macro:load procedure does not aļ¬€ect the values returned by
current-input-port, current-error-port, and current-output-port.
References:
The Revised^4 Report on the Algorithmic Language Scheme Clinger and Rees [editors].
To appear in LISP Pointers. Also available as a technical report from the University of
Oregon, MIT AI Lab, and Cornell.
Macros That Work. Clinger and Rees. POPL ā€™91.
The supported syntax diļ¬€ers from the R4RS in that vectors are allowed as patterns
and as templates and are not allowed as pattern or template data.
transformer spec 7ā†’ (syntax-rules literals rules)
rules 7ā†’ ()
| (rule . rules)
rule 7ā†’ (pattern template)
pattern 7ā†’ pattern_var ; a symbol not in literals
| symbol ; a symbol in literals
| ()
| (pattern . pattern)
| (ellipsis_pattern)
| #(pattern*) ; extends R4RS
| #(pattern* ellipsis_pattern) ; extends R4RS
| pattern_datum
template 7ā†’ pattern_var
| symbol
| ()
| (template2 . template2)
| #(template*) ; extends R4RS
| pattern_datum
template2 7ā†’ template
| ellipsis_template
pattern_datum 7ā†’ string ; no vector
| character
| boolean
| number
ellipsis_pattern 7ā†’ pattern ...
ellipsis_template 7ā†’ template ...
pattern_var 7ā†’ symbol ; not in literals
Chapter 3: Scheme Syntax Extension Packages 22
literals 7ā†’ ()
| (symbol . literals)
3.4.1 Deļ¬nitions
Scope of an ellipsis
Within a pattern or template, the scope of an ellipsis (...) is the pattern or
template that appears to its left.
Rank of a pattern variable
The rank of a pattern variable is the number of ellipses within whose scope it
appears in the pattern.
Rank of a subtemplate
The rank of a subtemplate is the number of ellipses within whose scope it
appears in the template.
Template rank of an occurrence of a pattern variable
The template rank of an occurrence of a pattern variable within a template is
the rank of that occurrence, viewed as a subtemplate.
Variables bound by a pattern
The variables bound by a pattern are the pattern variables that appear within
it.
Referenced variables of a subtemplate
The referenced variables of a subtemplate are the pattern variables that appear
within it.
Variables opened by an ellipsis template
The variables opened by an ellipsis template are the referenced pattern variables
whose rank is greater than the rank of the ellipsis template.
3.4.2 Restrictions
No pattern variable appears more than once within a pattern.
For every occurrence of a pattern variable within a template, the template rank of the
occurrence must be greater than or equal to the pattern variableā€™s rank.
Every ellipsis template must open at least one variable.
For every ellipsis template, the variables opened by an ellipsis template must all be
bound to sequences of the same length.
The compiled form of a rule is
rule 7ā†’ (pattern template inserted)
pattern 7ā†’ pattern_var
| symbol
| ()
| (pattern . pattern)
| ellipsis_pattern
Chapter 3: Scheme Syntax Extension Packages 23
| #(pattern)
| pattern_datum
template 7ā†’ pattern_var
| symbol
| ()
| (template2 . template2)
| #(pattern)
| pattern_datum
template2 7ā†’ template
| ellipsis_template
pattern_datum 7ā†’ string
| character
| boolean
| number
pattern_var 7ā†’ #(V symbol rank)
ellipsis_pattern 7ā†’ #(E pattern pattern_vars)
ellipsis_template 7ā†’ #(E template pattern_vars)
inserted 7ā†’ ()
| (symbol . inserted)
pattern_vars 7ā†’ ()
| (pattern_var . pattern_vars)
rank 7ā†’ exact non-negative integer
where V and E are unforgeable values.
The pattern variables associated with an ellipsis pattern are the variables bound by
the pattern, and the pattern variables associated with an ellipsis template are the variables
opened by the ellipsis template.
If the template contains a big chunk that contains no pattern variables or inserted
identiļ¬ers, then the big chunk will be copied unnecessarily. That shouldnā€™t matter very
often.
3.5 Syntactic Closures
(require ā€™syntactic-closures)
Chapter 3: Scheme Syntax Extension Packages 24
[Function]macro:expand expression
[Function]synclo:expand expression
Returns scheme code with the macros and derived expression types of expression
expanded to primitive expression types.
[Function]macro:eval expression
[Function]synclo:eval expression
macro:eval returns the value of expression in the current top level environment.
expression can contain macro deļ¬nitions. Side eļ¬€ects of expression will aļ¬€ect the top
level environment.
[Procedure]macro:load ļ¬lename
[Procedure]synclo:load ļ¬lename
ļ¬lename should be a string. If ļ¬lename names an existing ļ¬le, the macro:load pro-
cedure reads Scheme source code expressions and deļ¬nitions from the ļ¬le and eval-
uates them sequentially. These source code expressions and deļ¬nitions may contain
macro deļ¬nitions. The macro:load procedure does not aļ¬€ect the values returned by
current-input-port, current-error-port, and current-output-port.
3.5.1 Syntactic Closure Macro Facility
A Syntactic Closures Macro Facility
by Chris Hanson
9 November 1991
This document describes syntactic closures, a low-level macro facility for the Scheme pro-
gramming language. The facility is an alternative to the low-level macro facility described
in the Revised^4 Report on Scheme. This document is an addendum to that report.
The syntactic closures facility extends the BNF rule for transformer spec to allow a
new keyword that introduces a low-level macro transformer:
transformer spec := (transformer expression)
Additionally, the following procedures are added:
make-syntactic-closure
capture-syntactic-environment
identifier?
identifier=?
The description of the facility is divided into three parts. The ļ¬rst part deļ¬nes basic
terminology. The second part describes how macro transformers are deļ¬ned. The third
part describes the use of identiļ¬ers, which extend the syntactic closure mechanism to be
compatible with syntax-rules.
3.5.1.1 Terminology
This section deļ¬nes the concepts and data types used by the syntactic closures facility.
ā€¢ Forms are the syntactic entities out of which programs are recursively constructed. A
form is any expression, any deļ¬nition, any syntactic keyword, or any syntactic closure.
The variable name that appears in a set! special form is also a form. Examples of
forms:
Chapter 3: Scheme Syntax Extension Packages 25
17
#t
car
(+ x 4)
(lambda (x) x)
(define pi 3.14159)
if
define
ā€¢ An alias is an alternate name for a given symbol. It can appear anywhere in a form that
the symbol could be used, and when quoted it is replaced by the symbol; however, it
does not satisfy the predicate symbol?. Macro transformers rarely distinguish symbols
from aliases, referring to both as identiļ¬ers.
ā€¢ A syntactic environment maps identiļ¬ers to their meanings. More precisely, it deter-
mines whether an identiļ¬er is a syntactic keyword or a variable. If it is a keyword,
the meaning is an interpretation for the form in which that keyword appears. If it
is a variable, the meaning identiļ¬es which binding of that variable is referenced. In
short, syntactic environments contain all of the contextual information necessary for
interpreting the meaning of a particular form.
ā€¢ A syntactic closure consists of a form, a syntactic environment, and a list of identiļ¬ers.
All identiļ¬ers in the form take their meaning from the syntactic environment, except
those in the given list. The identiļ¬ers in the list are to have their meanings determined
later. A syntactic closure may be used in any context in which its form could have
been used. Since a syntactic closure is also a form, it may not be used in contexts
where a form would be illegal. For example, a form may not appear as a clause in the
cond special form. A syntactic closure appearing in a quoted structure is replaced by
its form.
3.5.1.2 Transformer Deļ¬nition
This section describes the transformer special form and the procedures make-syntactic-
closure and capture-syntactic-environment.
[Syntax]transformer expression
Syntax: It is an error if this syntax occurs except as a transformer spec.
Semantics: The expression is evaluated in the standard transformer environment to
yield a macro transformer as described below. This macro transformer is bound to
a macro keyword by the special form in which the transformer expression appears
(for example, let-syntax).
A macro transformer is a procedure that takes two arguments, a form and a syntactic
environment, and returns a new form. The ļ¬rst argument, the input form, is the form
in which the macro keyword occurred. The second argument, the usage environment,
is the syntactic environment in which the input form occurred. The result of the
transformer, the output form, is automatically closed in the transformer environment,
which is the syntactic environment in which the transformer expression occurred.
For example, here is a deļ¬nition of a push macro using syntax-rules:
(define-syntax push
Chapter 3: Scheme Syntax Extension Packages 26
(syntax-rules ()
((push item list)
(set! list (cons item list)))))
Here is an equivalent deļ¬nition using transformer:
(define-syntax push
(transformer
(lambda (exp env)
(let ((item
(make-syntactic-closure env ā€™() (cadr exp)))
(list
(make-syntactic-closure env ā€™() (caddr exp))))
ā€˜(set! ,list (cons ,item ,list))))))
In this example, the identiļ¬ers set! and cons are closed in the transformer environ-
ment, and thus will not be aļ¬€ected by the meanings of those identiļ¬ers in the usage
environment env.
Some macros may be non-hygienic by design. For example, the following deļ¬nes a
loop macro that implicitly binds exit to an escape procedure. The binding of exit
is intended to capture free references to exit in the body of the loop, so exit must
be left free when the body is closed:
(define-syntax loop
(transformer
(lambda (exp env)
(let ((body (cdr exp)))
ā€˜(call-with-current-continuation
(lambda (exit)
(let f ()
,@(map (lambda (exp)
(make-syntactic-closure env ā€™(exit)
exp))
body)
(f))))))))
To assign meanings to the identiļ¬ers in a form, use make-syntactic-closure to close
the form in a syntactic environment.
[Function]make-syntactic-closure environment free-names form
environment must be a syntactic environment, free-names must be a list of identiļ¬ers,
and form must be a form. make-syntactic-closure constructs and returns a syn-
tactic closure of form in environment, which can be used anywhere that form could
have been used. All the identiļ¬ers used in form, except those explicitly excepted by
free-names, obtain their meanings from environment.
Here is an example where free-names is something other than the empty list. It is
instructive to compare the use of free-names in this example with its use in the loop
example above: the examples are similar except for the source of the identiļ¬er being
left free.
Chapter 3: Scheme Syntax Extension Packages 27
(define-syntax let1
(transformer
(lambda (exp env)
(let ((id (cadr exp))
(init (caddr exp))
(exp (cadddr exp)))
ā€˜((lambda (,id)
,(make-syntactic-closure env (list id) exp))
,(make-syntactic-closure env ā€™() init))))))
let1 is a simpliļ¬ed version of let that only binds a single identiļ¬er, and whose body
consists of a single expression. When the body expression is syntactically closed in
its original syntactic environment, the identiļ¬er that is to be bound by let1 must be
left free, so that it can be properly captured by the lambda in the output form.
To obtain a syntactic environment other than the usage environment, use
capture-syntactic-environment.
[Function]capture-syntactic-environment procedure
capture-syntactic-environment returns a form that will, when transformed, call
procedure on the current syntactic environment. procedure should compute and
return a new form to be transformed, in that same syntactic environment, in place of
the form.
An example will make this clear. Suppose we wanted to deļ¬ne a simple loop-until
keyword equivalent to
(define-syntax loop-until
(syntax-rules ()
((loop-until id init test return step)
(letrec ((loop
(lambda (id)
(if test return (loop step)))))
(loop init)))))
The following attempt at deļ¬ning loop-until has a subtle bug:
(define-syntax loop-until
(transformer
(lambda (exp env)
(let ((id (cadr exp))
(init (caddr exp))
(test (cadddr exp))
(return (cadddr (cdr exp)))
(step (cadddr (cddr exp)))
(close
(lambda (exp free)
(make-syntactic-closure env free exp))))
ā€˜(letrec ((loop
(lambda (,id)
(if ,(close test (list id))
Chapter 3: Scheme Syntax Extension Packages 28
,(close return (list id))
(loop ,(close step (list id)))))))
(loop ,(close init ā€™())))))))
This deļ¬nition appears to take all of the proper precautions to prevent unintended
captures. It carefully closes the subexpressions in their original syntactic environment
and it leaves the id identiļ¬er free in the test, return, and step expressions, so that it
will be captured by the binding introduced by the lambda expression. Unfortunately
it uses the identiļ¬ers if and loop within that lambda expression, so if the user of
loop-until just happens to use, say, if for the identiļ¬er, it will be inadvertently
captured.
The syntactic environment that if and loop want to be exposed to is the one just
outside the lambda expression: before the userā€™s identiļ¬er is added to the syntactic
environment, but after the identiļ¬er loop has been added. capture-syntactic-
environment captures exactly that environment as follows:
(define-syntax loop-until
(transformer
(lambda (exp env)
(let ((id (cadr exp))
(init (caddr exp))
(test (cadddr exp))
(return (cadddr (cdr exp)))
(step (cadddr (cddr exp)))
(close
(lambda (exp free)
(make-syntactic-closure env free exp))))
ā€˜(letrec ((loop
,(capture-syntactic-environment
(lambda (env)
ā€˜(lambda (,id)
(,(make-syntactic-closure env ā€™() ā€˜if)
,(close test (list id))
,(close return (list id))
(,(make-syntactic-closure env ā€™()
ā€˜loop)
,(close step (list id)))))))))
(loop ,(close init ā€™())))))))
In this case, having captured the desired syntactic environment, it is convenient to
construct syntactic closures of the identiļ¬ers if and the loop and use them in the
body of the lambda.
A common use of capture-syntactic-environment is to get the transformer envi-
ronment of a macro transformer:
(transformer
(lambda (exp env)
(capture-syntactic-environment
(lambda (transformer-env)
Chapter 3: Scheme Syntax Extension Packages 29
...))))
3.5.1.3 Identiļ¬ers
This section describes the procedures that create and manipulate identiļ¬ers. Previous
syntactic closure proposals did not have an identiļ¬er data type ā€“ they just used symbols.
The identiļ¬er data type extends the syntactic closures facility to be compatible with the
high-level syntax-rules facility.
As discussed earlier, an identiļ¬er is either a symbol or an alias. An alias is implemented
as a syntactic closure whose form is an identiļ¬er:
(make-syntactic-closure env ā€™() ā€™a)
ā‡’
an alias
Aliases are implemented as syntactic closures because they behave just like syntactic
closures most of the time. The diļ¬€erence is that an alias may be bound to a new value (for
example by lambda or let-syntax); other syntactic closures may not be used this way. If
an alias is bound, then within the scope of that binding it is looked up in the syntactic
environment just like any other identiļ¬er.
Aliases are used in the implementation of the high-level facility syntax-rules. A
macro transformer created by syntax-rules uses a template to generate its output form,
substituting subforms of the input form into the template. In a syntactic closures implemen-
tation, all of the symbols in the template are replaced by aliases closed in the transformer
environment, while the output form itself is closed in the usage environment. This guaran-
tees that the macro transformation is hygienic, without requiring the transformer to know
the syntactic roles of the substituted input subforms.
[Function]identifier? object
Returns #t if object is an identiļ¬er, otherwise returns #f. Examples:
(identifier? ā€™a)
ā‡’
#t
(identifier? (make-syntactic-closure env ā€™() ā€™a))
ā‡’
#t
(identifier? "a")
ā‡’
#f
(identifier? #\a)
ā‡’
#f
(identifier? 97)
ā‡’
#f
(identifier? #f)
ā‡’
#f
(identifier? ā€™(a))
ā‡’
#f
(identifier? ā€™#(a))
ā‡’
#f
The predicate eq? is used to determine if two identifers are ā€œthe sameā€. Thus eq?
can be used to compare identiļ¬ers exactly as it would be used to compare symbols.
Often, though, it is useful to know whether two identiļ¬ers ā€œmean the same thingā€.
Chapter 3: Scheme Syntax Extension Packages 30
For example, the cond macro uses the symbol else to identify the ļ¬nal clause in the
conditional. A macro transformer for cond cannot just look for the symbol else, be-
cause the cond form might be the output of another macro transformer that replaced
the symbol else with an alias. Instead the transformer must look for an identiļ¬er
that ā€œmeans the same thingā€ in the usage environment as the symbol else means in
the transformer environment.
[Function]identifier=? environment1 identiļ¬er1 environment2 identiļ¬er2
environment1 and environment2 must be syntactic environments, and identiļ¬er1 and
identiļ¬er2 must be identiļ¬ers. identifier=? returns #t if the meaning of identiļ¬er1
in environment1 is the same as that of identiļ¬er2 in environment2, otherwise it returns
#f. Examples:
(let-syntax
((foo
(transformer
(lambda (form env)
(capture-syntactic-environment
(lambda (transformer-env)
(identifier=? transformer-env ā€™x env ā€™x)))))))
(list (foo)
(let ((x 3))
(foo))))
ā‡’
(#t #f)
(let-syntax ((bar foo))
(let-syntax
((foo
(transformer
(lambda (form env)
(capture-syntactic-environment
(lambda (transformer-env)
(identifier=? transformer-env ā€™foo
env (cadr form))))))))
(list (foo foo)
(foobar))))
ā‡’
(#f #t)
3.5.1.4 Acknowledgements
The syntactic closures facility was invented by Alan Bawden and Jonathan Rees. The use
of aliases to implement syntax-rules was invented by Alan Bawden (who prefers to call
them synthetic names). Much of this proposal is derived from an earlier proposal by Alan
Bawden.
3.6 Syntax-Case Macros
(require ā€™syntax-case)
Chapter 3: Scheme Syntax Extension Packages 31
[Function]macro:expand expression
[Function]syncase:expand expression
Returns scheme code with the macros and derived expression types of expression
expanded to primitive expression types.
[Function]macro:eval expression
[Function]syncase:eval expression
macro:eval returns the value of expression in the current top level environment.
expression can contain macro deļ¬nitions. Side eļ¬€ects of expression will aļ¬€ect the top
level environment.
[Procedure]macro:load ļ¬lename
[Procedure]syncase:load ļ¬lename
ļ¬lename should be a string. If ļ¬lename names an existing ļ¬le, the macro:load pro-
cedure reads Scheme source code expressions and deļ¬nitions from the ļ¬le and eval-
uates them sequentially. These source code expressions and deļ¬nitions may contain
macro deļ¬nitions. The macro:load procedure does not aļ¬€ect the values returned by
current-input-port, current-error-port, and current-output-port.
This is version 2.1 of syntax-case, the low-level macro facility proposed and imple-
mented by Robert Hieb and R. Kent Dybvig.
This version is further adapted by Harald Hanche-Olsen <hanche @ imf.unit.no> to
make it compatible with, and easily usable with, SLIB. Mainly, these adaptations consisted
of:
ā€¢ Removing white space from expand.pp to save space in the distribution. This ļ¬le is
not meant for human readers anyway. . .
ā€¢ Removed a couple of Chez scheme dependencies.
ā€¢ Renamed global variables used to minimize the possibility of name conļ¬‚icts.
ā€¢ Adding an SLIB-speciļ¬c initialization ļ¬le.
ā€¢ Removing a couple extra ļ¬les, most notably the documentation (but see below).
If you wish, you can see exactly what changes were done by reading the shell script in
the ļ¬le syncase.sh.
The two PostScript ļ¬les were omitted in order to not burden the SLIB distribution
with them. If you do intend to use syntax-case, however, you should get these ļ¬les and
print them out on a PostScript printer. They are available with the original syntax-case
distribution by anonymous FTP in cs.indiana.edu:/pub/scheme/syntax-case.
In order to use syntax-case from an interactive top level, execute:
(require ā€™syntax-case)
(require ā€™repl)
(repl:top-level macro:eval)
See the section Repl (see Section 7.5.1 [Repl], page 258) for more information.
To check operation of syntax-case get cs.indiana.edu:/pub/scheme/syntax-case,
and type
(require ā€™syntax-case)
Chapter 3: Scheme Syntax Extension Packages 32
(syncase:sanity-check)
Beware that syntax-case takes a long time to load ā€“ about 20s on a SPARCstation
SLC (with SCM) and about 90s on a Macintosh SE/30 (with Gambit).
3.6.1 Notes
All R4RS syntactic forms are deļ¬ned, including delay. Along with delay are simple deļ¬-
nitions for make-promise (into which delay expressions expand) and force.
syntax-rules and with-syntax (described in TR356) are deļ¬ned.
syntax-case is actually deļ¬ned as a macro that expands into calls to the procedure
syntax-dispatch and the core form syntax-lambda; do not redeļ¬ne these names.
Several other top-level bindings not documented in TR356 are created:
ā€¢ the ā€œhooksā€ in hooks.ss
ā€¢ the build- procedures in output.ss
ā€¢ expand-syntax (the expander)
The syntax of deļ¬ne has been extended to allow (define id), which assigns id to some
unspeciļ¬ed value.
We have attempted to maintain R4RS compatibility where possible. The incompati-
bilities should be conļ¬ned to hooks.ss. Please let us know if there is some incompatibility
that is not ļ¬‚agged as such.
Send bug reports, comments, suggestions, and questions to Kent Dybvig (dyb @ iu-
vax.cs.indiana.edu).
3.7 Deļ¬ne-Structure
(require ā€™structure)
Included with the syntax-case ļ¬les was structure.scm which deļ¬nes a macro
define-structure. Here is its documentation from Gambit-4.0:
[special form]define-structure (name field. . . )
Record data types similar to Pascal records and C struct types can be deļ¬ned using
the define-structure special form. The identiļ¬er name speciļ¬es the name of the
new data type. The structure name is followed by k identiļ¬ers naming each ļ¬eld of
the record. The define-structure expands into a set of deļ¬nitions of the following
procedures:
ā€¢ ā€˜make-nameā€™ ā€“ A k argument procedure which constructs a new record from the
value of its k ļ¬elds.
ā€¢ ā€˜name?ā€™ ā€“ A procedure which tests if its single argument is of the given record
type.
ā€¢ ā€˜name-ļ¬eldā€™ ā€“ For each ļ¬eld, a procedure taking as its single argument a value
of the given record type and returning the content of the corresponding ļ¬eld of
the record.
Chapter 3: Scheme Syntax Extension Packages 33
ā€¢ ā€˜name-ļ¬eld-set!ā€™ ā€“ For each ļ¬eld, a two argument procedure taking as its ļ¬rst
argument a value of the given record type. The second argument gets assigned
to the corresponding ļ¬eld of the record and the void object is returned.
Gambit record data types have a printed representation that includes the name of
the type and the name and value of each ļ¬eld.
For example:
> (require ā€™syntax-case)
> (require ā€™repl)
> (repl:top-level macro:eval)
> (require ā€™structure)
> (deļ¬ne-structure (point x y color))
> (deļ¬ne p (make-point 3 5 ā€™red))
> p
#<point #3 x: 3 y: 5 color: red>
> (point-x p)
3
> (point-color p)
red
> (point-color-set! p ā€™black)
> p
#<point #3 x: 3 y: 5 color: black>
3.8 Deļ¬ne-Record-Type
(require ā€™define-record-type) or (require ā€™srfi-9)
http://srfi.schemers.org/srfi-9/srfi-9.html
[Special Form]define-record-type <type-name> (<constructor-name>
<ļ¬eld-tag> ...) <predicate-name> <ļ¬eld-spec> ...
Where
<field-spec> ā‰” (<field-tag> <accessor-name>)
ā‰” (<field-tag> <accessor-name> <modifier-name>)
define-record-type is a syntax wrapper for the SLIB record module.
3.9 Fluid-Let
(require ā€™fluid-let)
Note: fluid-let is not thread-safe. It is better to use Section 3.10 [Parameter
Objects], page 34, (srļ¬-39) or Section 7.1.11 [Dynamic Data Type], page 213,
both of which will be made thread-safe in the future.
[Syntax]fluid-let (bindings ...) forms. . .
(fluid-let ((variable init) ...)
expression expression ...)
The inits are evaluated in the current environment (in some unspeciļ¬ed order), the
current values of the variables are saved, the results are assigned to the variables, the
expressions are evaluated sequentially in the current environment, the variables are restored
to their original values, and the value of the last expression is returned.
Chapter 3: Scheme Syntax Extension Packages 34
The syntax of this special form is similar to that of let, but fluid-let temporarily
rebinds existing variables. Unlike let, fluid-let creates no new bindings; instead it
assigns the values of each init to the binding (determined by the rules of lexical scoping) of
its corresponding variable.
3.10 Parameter Objects
(require ā€™srfi-39)
http://srfi.schemers.org/srfi-39/srfi-39.html
3.11 Binding to multiple values
(require ā€™receive) or (require ā€™srfi-8)
[Special Form]receive formals expression body . . .
http://srfi.schemers.org/srfi-8/srfi-8.html
(require ā€™let-values) or (require ā€™srfi-11)
[Special Form]let-values ((formals expression) ...) body . . .
[Special Form]let-values* ((formals expression) ...) body . . .
http://srfi.schemers.org/srfi-11/srfi-11.html
3.12 Guarded LET* special form
(require ā€™and-let*) or (require ā€™srfi-2)
[Macro]and-let* claws body . . .
http://srfi.schemers.org/srfi-2/srfi-2.html
3.13 Guarded COND Clause
(require ā€™guarded-cond-clause) or (require ā€™srfi-61)
http://srfi.schemers.org/srfi-61/srfi-61.html
[library syntax]cond <clause1> <clause2> . . .
Syntax: Each <clause> should be of the form
(<test> <expression1> ...)
where <test> is any expression. Alternatively, a <clause> may be of the form
(<test> => <expression>)
The <clause> production in the formal syntax of Scheme as written by R5RS in section
7.1.3 is extended with a new option:
<clause> => (<generator> <guard> => <receiver>)
Chapter 3: Scheme Syntax Extension Packages 35
where <generator>, <guard>, & <receiver> are all <expression>s.
Clauses of this form have the following semantics: <generator> is evalu-
ated. It may return arbitrarily many values. <Guard> is applied to an
argument list containing the values in order that <generator> returned.
If <guard> returns a true value for that argument list, <receiver> is ap-
plied with an equivalent argument list. If <guard> returns a false value,
however, the clause is abandoned and the next one is tried.
The last <clause> may be an ā€œelse clause,ā€ which has the form
(else <expression1> <expression2> ...).
This port->char-list procedure accepts an input port and returns a list of all the char-
acters it produces until the end.
(define (port->char-list port)
(cond ((read-char port) char?
=> (lambda (c) (cons c (port->char-list port))))
(else ā€™())))
(call-with-input-string "foo" port->char-list) ==> (#\f #\o #\o)
3.14 Yasos
(require ā€™oop) or (require ā€™yasos)
ā€˜Yet Another Scheme Object Systemā€™ is a simple object system for Scheme based on the
paper by Norman Adams and Jonathan Rees: Object Oriented Programming in Scheme,
Proceedings of the 1988 ACM Conference on LISP and Functional Programming, July 1988
[ACM #552880].
Another reference is:
Ken Dickey.
Scheming with Objects
AI Expert Volume 7, Number 10 (October 1992), pp. 24-33.
ftp://ftp.cs.indiana.edu/pub/scheme-repository/doc/pubs/swob.txt
3.14.1 Terms
Object Any Scheme data object.
Instance An instance of the OO system; an object.
Operation A method.
Notes: The object system supports multiple inheritance. An instance can inherit from
0 or more ancestors. In the case of multiple inherited operations with the same
identity, the operation used is that from the ļ¬rst ancestor which contains it (in
Chapter 3: Scheme Syntax Extension Packages 36
the ancestor let). An operation may be applied to any Scheme data objectā€”
not just instances. As code which creates instances is just code, there are no
classes and no meta-anything. Method dispatch is by a procedure call a la
CLOS rather than by send syntax a la Smalltalk.
Disclaimer:
There are a number of optimizations which can be made. This implementation
is expository (although performance should be quite reasonable). See the L&FP
paper for some suggestions.
3.14.2 Interface
[Syntax]define-operation (opname self arg . . .) default-body
Deļ¬nes a default behavior for data objects which donā€™t handle the operation opname.
The default behavior (for an empty default-body) is to generate an error.
[Syntax]define-predicate opname?
Deļ¬nes a predicate opname?, usually used for determining the type of an object,
such that (opname? object) returns #t if object has an operation opname? and #f
otherwise.
[Syntax]object ((name self arg ...) body) . . .
Returns an object (an instance of the object system) with operations. Invoking (name
object arg ...) executes the body of the object with self bound to object and with
argument(s) arg . . ..
[Syntax]object-with-ancestors ((ancestor1 init1) . . .) operation . . .
A let-like form of object for multiple inheritance. It returns an object inheriting the
behaviour of ancestor1 etc. An operation will be invoked in an ancestor if the object
itself does not provide such a method. In the case of multiple inherited operations
with the same identity, the operation used is the one found in the ļ¬rst ancestor in
the ancestor list.
[Syntax]operate-as component operation self arg . . .
Used in an operation deļ¬nition (of self ) to invoke the operation in an ancestor com-
ponent but maintain the objectā€™s identity. Also known as ā€œsend-to-superā€.
[Procedure]print obj port
A default print operation is provided which is just (format port obj) (see
Section 4.2 [Format], page 46) for non-instances and prints obj preceded by
ā€˜#<INSTANCE>ā€™ for instances.
[Function]size obj
The default method returns the number of elements in obj if it is a vector, string or
list, 2 for a pair, 1 for a character and by default id an error otherwise. Objects such
as collections (see Section 7.1.10 [Collections], page 210) may override the default in
an obvious way.
Chapter 3: Scheme Syntax Extension Packages 37
3.14.3 Setters
Setters implement generalized locations for objects associated with some sort of mutable
state. A getter operation retrieves a value from a generalized location and the corresponding
setter operation stores a value into the location. Only the getter is named ā€“ the setter
is speciļ¬ed by a procedure call as below. (Dylan uses special syntax.) Typically, but
not necessarily, getters are access operations to extract values from Yasos objects (see
Section 3.14 [Yasos], page 35). Several setters are predeļ¬ned, corresponding to getters car,
cdr, string-ref and vector-ref e.g., (setter car) is equivalent to set-car!.
This implementation of setters is similar to that in Dylan(TM) (Dylan: An object-
oriented dynamic language, Apple Computer Eastern Research and Technology). Common
LISP provides similar facilities through setf.
[Function]setter getter
Returns the setter for the procedure getter. E.g., since string-ref is the getter
corresponding to a setter which is actually string-set!:
(define foo "foo")
((setter string-ref) foo 0 #\F) ; set element 0 of foo
foo
ā‡’
"Foo"
[Syntax]set place new-value
If place is a variable name, set is equivalent to set!. Otherwise, place must have
the form of a procedure call, where the procedure name refers to a getter and the call
indicates an accessible generalized location, i.e., the call would return a value. The
return value of set is usually unspeciļ¬ed unless used with a setter whose deļ¬nition
guarantees to return a useful value.
(set (string-ref foo 2) #\O) ; generalized location with getter
foo
ā‡’
"FoO"
(set foo "foo") ; like set!
foo
ā‡’
"foo"
[Procedure]add-setter getter setter
Add procedures getter and setter to the (inaccessible) list of valid setter/getter pairs.
setter implements the store operation corresponding to the getter access operation
for the relevant state. The return value is unspeciļ¬ed.
[Procedure]remove-setter-for getter
Removes the setter corresponding to the speciļ¬ed getter from the list of valid setters.
The return value is unspeciļ¬ed.
[Syntax]define-access-operation getter-name
Shorthand for a Yasos define-operation deļ¬ning an operation getter-name that
objects may support to return the value of some mutable state. The default operation
is to signal an error. The return value is unspeciļ¬ed.
3.14.4 Examples
;;; These definitions for PRINT and SIZE are
;;; already supplied by
Chapter 3: Scheme Syntax Extension Packages 38
(require ā€™yasos)
(define-operation (print obj port)
(format port
(if (instance? obj) "#<instance>" "~s")
obj))
(define-operation (size obj)
(cond
((vector? obj) (vector-length obj))
((list? obj) (length obj))
((pair? obj) 2)
((string? obj) (string-length obj))
((char? obj) 1)
(else
(slib:error "Operation not supported: size" obj))))
(define-predicate cell?)
(define-operation (fetch obj))
(define-operation (store! obj newValue))
(define (make-cell value)
(object
((cell? self) #t)
((fetch self) value)
((store! self newValue)
(set! value newValue)
newValue)
((size self) 1)
((print self port)
(format port "#<Cell: ~s>" (fetch self)))))
(define-operation (discard obj value)
(format #t "Discarding ~s~%" value))
(define (make-filtered-cell value filter)
(object-with-ancestors
((cell (make-cell value)))
((store! self newValue)
(if (filter newValue)
(store! cell newValue)
(discard self newValue)))))
(define-predicate array?)
(define-operation (array-ref array index))
(define-operation (array-set! array index value))
39
(define (make-array num-slots)
(let ((anArray (make-vector num-slots)))
(object
((array? self) #t)
((size self) num-slots)
((array-ref self index)
(vector-ref anArray index))
((array-set! self index newValue)
(vector-set! anArray index newValue))
((print self port)
(format port "#<Array ~s>" (size self))))))
(define-operation (position obj))
(define-operation (discarded-value obj))
(define (make-cell-with-history value filter size)
(let ((pos 0) (most-recent-discard #f))
(object-with-ancestors
((cell (make-filtered-call value filter))
(sequence (make-array size)))
((array? self) #f)
((position self) pos)
((store! self newValue)
(operate-as cell store! self newValue)
(array-set! self pos newValue)
(set! pos (+ pos 1)))
((discard self value)
(set! most-recent-discard value))
((discarded-value self) most-recent-discard)
((print self port)
(format port "#<Cell-with-history ~s>"
(fetch self))))))
(define-access-operation fetch)
(add-setter fetch store!)
(define foo (make-cell 1))
(print foo #f)
ā‡’
"#<Cell: 1>"
(set (fetch foo) 2)
ā‡’
(print foo #f)
ā‡’
"#<Cell: 2>"
(fetch foo)
ā‡’
2
40
4 Textual Conversion Packages
4.1 Precedence Parsing
(require ā€™precedence-parse) or (require ā€™parse)
This package implements:
ā€¢ a Pratt style precedence parser;
ā€¢ a tokenizer which congeals tokens according to assigned classes of constituent charac-
ters;
ā€¢ procedures giving direct control of parser rulesets;
ā€¢ procedures for higher level speciļ¬cation of rulesets.
4.1.1 Precedence Parsing Overview
This package oļ¬€ers improvements over previous parsers.
ā€¢ Common computer language constructs are concisely speciļ¬ed.
ā€¢ Grammars can be changed dynamically. Operators can be assigned diļ¬€erent meanings
within a lexical context.
ā€¢ Rulesets donā€™t need compilation. Grammars can be changed incrementally.
ā€¢ Operator precedence is speciļ¬ed by integers.
ā€¢ All possibilities of bad input are handled
1
and return as much structure as was parsed
when the error occured; The symbol ? is substituted for missing input.
The notion of binding power may be unfamiliar to those accustomed to BNF grammars.
When two consecutive objects are parsed, the ļ¬rst might be the preļ¬x to the second, or the
second might be a suļ¬ƒx of the ļ¬rst. Comparing the left and right binding powers of the
two objects decides which way to interpret them.
Objects at each level of syntactic grouping have binding powers.
A syntax tree is not built unless the rules explicitly do so. The call graph of grammar rules
eļ¬€ectively instantiate the sytnax tree.
The JACAL symbolic math system (http://people.csail.mit.edu/jaffer/JACAL) uses
precedence-parse. Its grammar deļ¬nitions in the ļ¬le jacal/English.scm can serve as
examples of use.
4.1.2 Rule Types
Here are the higher-level syntax types and an example of each. Precedence considerations
are omitted for clarity. See Section 4.1.6 [Grammar Rule Deļ¬nition], page 44, for full details.
[Grammar]nofix bye exit
bye
calls the function exit with no arguments.
1
How do I know this? I parsed 250kbyte of random input (an e-mail ļ¬le) with a non-trivial grammar
utilizing all constructs.
Chapter 4: Textual Conversion Packages 41
[Grammar]prefix - negate
- 42
Calls the function negate with the argument 42.
[Grammar]infix - diļ¬€erence
x - y
Calls the function difference with arguments x and y.
[Grammar]nary + sum
x + y + z
Calls the function sum with arguments x, y, and y.
[Grammar]postfix ! factorial
5 !
Calls the function factorial with the argument 5.
[Grammar]prestfix set set!
set foo bar
Calls the function set! with the arguments foo and bar.
[Grammar]commentfix /* */
/* almost any text here */
Ignores the comment delimited by /* and */.
[Grammar]matchfix { list }
{0, 1, 2}
Calls the function list with the arguments 0, 1, and 2.
[Grammar]inmatchfix ( funcall )
f(x, y)
Calls the function funcall with the arguments f, x, and y.
[Grammar]delim ;
set foo bar;
delimits the extent of the restļ¬x operator set.
4.1.3 Ruleset Deļ¬nition and Use
[Variable]*syn-defs*
A grammar is built by one or more calls to prec:define-grammar. The rules are
appended to *syn-defs*. The value of *syn-defs* is the grammar suitable for passing
as an argument to prec:parse.
[Constant]*syn-ignore-whitespace*
Is a nearly empty grammar with whitespace characters set to group 0, which means
they will not be made into tokens. Most rulesets will want to start with *syn-ignore-
whitespace*
Chapter 4: Textual Conversion Packages 42
In order to start deļ¬ning a grammar, either
(set! *syn-defs* ā€™())
or
(set! *syn-defs* *syn-ignore-whitespace*)
[Function]prec:define-grammar rule1 . . .
Appends rule1 . . . to *syn-defs*. prec:define-grammar is used to deļ¬ne both the
character classes and rules for tokens.
Once your grammar is deļ¬ned, save the value of *syn-defs* in a variable (for use when
calling prec:parse).
(define my-ruleset *syn-defs*)
[Function]prec:parse ruleset delim column
[Function]prec:parse ruleset delim column port
The ruleset argument must be a list of rules as constructed by prec:define-grammar
and extracted from *syn-defs*.
The token delim may be a character, symbol, or string. A character delim argument
will match only a character token; i.e. a character for which no token-group is as-
signed. A symbol or string will match only a token string; i.e. a token resulting from
a token group.
prec:parse reads a ruleset grammar expression delimited by delim from the given
input port. prec:parse returns the next object parsable from the given input port,
updating port to point to the ļ¬rst character past the end of the external representation
of the object.
For the purpose of reporting problems in error messages, this package keeps track of
the current column. Its initial value is passed as the third argument to prec:parse.
If an end of ļ¬le is encountered in the input before any characters are found that can
begin an object, then an end of ļ¬le object is returned. If a delimiter (such as delim) is
found before any characters are found that can begin an object, then #f is returned.
The port argument may be omitted, in which case it defaults to the value returned
by current-input-port. It is an error to parse from a closed port.
4.1.4 Token deļ¬nition
[Function]tok:char-group group chars chars-proc
The argument chars may be a single character, a list of characters, or a string. Each
character in chars is treated as though tok:char-group was called with that character
alone.
The argument chars-proc must be a procedure of one argument, a list of characters.
After tokenize has ļ¬nished accumulating the characters for a token, it calls chars-
proc with the list of characters. The value returned is the token which tokenize
returns.
Chapter 4: Textual Conversion Packages 43
The argument group may be an exact integer or a procedure of one character argu-
ment. The following discussion concerns the treatment which the tokenizing routine,
tokenize, will accord to characters on the basis of their groups.
When group is a non-zero integer, characters whose group number is equal to or
exactly one less than group will continue to accumulate. Any other character causes
the accumulation to stop (until a new token is to be read).
The group of zero is special. These characters are ignored when parsed pending a
token, and stop the accumulation of token characters when the accumulation has
already begun. Whitespace characters are usually put in group 0.
If group is a procedure, then, when triggerd by the occurence of an initial (no accumu-
lation) chars character, this procedure will be repeatedly called with each successive
character from the input stream until the group procedure returns a non-false value.
The following convenient constants are provided for use with tok:char-group.
[Constant]tok:decimal-digits
Is the string "0123456789".
[Constant]tok:upper-case
Is the string consisting of all upper-case letters ("ABCDEFGHIJKLMNOPQRSTU-
VWXYZ").
[Constant]tok:lower-case
Is the string consisting of all lower-case letters ("abcdefghijklmnopqrstuvwxyz").
[Constant]tok:whitespaces
Is the string consisting of all characters between 0 and 255 for which
char-whitespace? returns true.
4.1.5 Nud and Led Deļ¬nition
This section describes advanced features. You can skip this section on ļ¬rst reading.
The Null Denotation (or nud) of a token is the procedure and arguments applying for that
token when Left, an unclaimed parsed expression is not extant.
The Left Denotation (or led) of a token is the procedure, arguments, and lbp applying for
that token when there is a Left, an unclaimed parsed expression.
In his paper,
Pratt, V. R. Top Down Operator Precendence. SIGACT/SIGPLAN Sympo-
sium on Principles of Programming Languages, Boston, 1973, pages 41-51
the left binding power (or lbp) was an independent property of tokens. I think this
was done in order to allow tokens with NUDs but not LEDs to also be used as delimiters,
which was a problem for statically deļ¬ned syntaxes. It turns out that dynamically binding
NUDs and LEDs allows them independence.
For the rule-deļ¬ning procedures that follow, the variable tk may be a character, string,
or symbol, or a list composed of characters, strings, and symbols. Each element of tk is
treated as though the procedure were called for each element.
Chapter 4: Textual Conversion Packages 44
Character tk arguments will match only character tokens; i.e. characters for which no
token-group is assigned. Symbols and strings will both match token strings; i.e. tokens
resulting from token groups.
[Function]prec:make-nud tk sop arg1 . . .
Returns a rule specifying that sop be called when tk is parsed. If sop is a procedure,
it is called with tk and arg1 . . . as its arguments; the resulting value is incorporated
into the expression being built. Otherwise, (list sop arg1 ...) is incorporated.
If no NUD has been deļ¬ned for a token; then if that token is a string, it is converted to a
symbol and returned; if not a string, the token is returned.
[Function]prec:make-led tk sop arg1 . . .
Returns a rule specifying that sop be called when tk is parsed and left has an un-
claimed parsed expression. If sop is a procedure, it is called with left, tk, and arg1
. . . as its arguments; the resulting value is incorporated into the expression being
built. Otherwise, left is incorporated.
If no LED has been deļ¬ned for a token, and left is set, the parser issues a warning.
4.1.6 Grammar Rule Deļ¬nition
Here are procedures for deļ¬ning rules for the syntax types introduced in Section 4.1.1
[Precedence Parsing Overview], page 40.
For the rule-deļ¬ning procedures that follow, the variable tk may be a character, string,
or symbol, or a list composed of characters, strings, and symbols. Each element of tk is
treated as though the procedure were called for each element.
For procedures prec:delim, . . . , prec:prestļ¬x, if the sop argument is #f, then the token
which triggered this rule is converted to a symbol and returned. A false sop argument to
the procedures prec:commentļ¬x, prec:matchļ¬x, or prec:inmatchļ¬x has a diļ¬€erent meaning.
Character tk arguments will match only character tokens; i.e. characters for which no
token-group is assigned. Symbols and strings will both match token strings; i.e. tokens
resulting from token groups.
[Function]prec:delim tk
Returns a rule specifying that tk should not be returned from parsing; i.e. tkā€™s
function is purely syntactic. The end-of-ļ¬le is always treated as a delimiter.
[Function]prec:nofix tk sop
Returns a rule specifying the following actions take place when tk is parsed:
ā€¢ If sop is a procedure, it is called with no arguments; the resulting value is incor-
porated into the expression being built. Otherwise, the list of sop is incorporated.
[Function]prec:prefix tk sop bp rule1 . . .
Returns a rule specifying the following actions take place when tk is parsed:
ā€¢ The rules rule1 . . . augment and, in case of conļ¬‚ict, override rules currently in
eļ¬€ect.
ā€¢ prec:parse1 is called with binding-power bp.
Chapter 4: Textual Conversion Packages 45
ā€¢ If sop is a procedure, it is called with the expression returned from prec:parse1;
the resulting value is incorporated into the expression being built. Otherwise,
the list of sop and the expression returned from prec:parse1 is incorporated.
ā€¢ The ruleset in eļ¬€ect before tk was parsed is restored; rule1 . . . are forgotten.
[Function]prec:infix tk sop lbp bp rule1 . . .
Returns a rule declaring the left-binding-precedence of the token tk is lbp and speci-
fying the following actions take place when tk is parsed:
ā€¢ The rules rule1 . . . augment and, in case of conļ¬‚ict, override rules currently in
eļ¬€ect.
ā€¢ One expression is parsed with binding-power lbp. If instead a delimiter is en-
countered, a warning is issued.
ā€¢ If sop is a procedure, it is applied to the list of left and the parsed expression;
the resulting value is incorporated into the expression being built. Otherwise,
the list of sop, the left expression, and the parsed expression is incorporated.
ā€¢ The ruleset in eļ¬€ect before tk was parsed is restored; rule1 . . . are forgotten.
[Function]prec:nary tk sop bp
Returns a rule declaring the left-binding-precedence of the token tk is bp and speci-
fying the following actions take place when tk is parsed:
ā€¢ Expressions are parsed with binding-power bp as far as they are interleaved with
the token tk.
ā€¢ If sop is a procedure, it is applied to the list of left and the parsed expressions;
the resulting value is incorporated into the expression being built. Otherwise,
the list of sop, the left expression, and the parsed expressions is incorporated.
[Function]prec:postfix tk sop lbp
Returns a rule declaring the left-binding-precedence of the token tk is lbp and speci-
fying the following actions take place when tk is parsed:
ā€¢ If sop is a procedure, it is called with the left expression; the resulting value is
incorporated into the expression being built. Otherwise, the list of sop and the
left expression is incorporated.
[Function]prec:prestfix tk sop bp rule1 . . .
Returns a rule specifying the following actions take place when tk is parsed:
ā€¢ The rules rule1 . . . augment and, in case of conļ¬‚ict, override rules currently in
eļ¬€ect.
ā€¢ Expressions are parsed with binding-power bp until a delimiter is reached.
ā€¢ If sop is a procedure, it is applied to the list of parsed expressions; the resulting
value is incorporated into the expression being built. Otherwise, the list of sop
and the parsed expressions is incorporated.
ā€¢ The ruleset in eļ¬€ect before tk was parsed is restored; rule1 . . . are forgotten.
[Function]prec:commentfix tk stp match rule1 . . .
Returns rules specifying the following actions take place when tk is parsed:
Chapter 4: Textual Conversion Packages 46
ā€¢ The rules rule1 . . . augment and, in case of conļ¬‚ict, override rules currently in
eļ¬€ect.
ā€¢ Characters are read until and end-of-ļ¬le or a sequence of characters is read which
matches the string match.
ā€¢ If stp is a procedure, it is called with the string of all that was read between the
tk and match (exclusive).
ā€¢ The ruleset in eļ¬€ect before tk was parsed is restored; rule1 . . . are forgotten.
Parsing of commentļ¬x syntax diļ¬€ers from the others in several ways. It reads directly
from input without tokenizing; It calls stp but does not return its value; nay any value.
I added the stp argument so that comment text could be echoed.
[Function]prec:matchfix tk sop sep match rule1 . . .
Returns a rule specifying the following actions take place when tk is parsed:
ā€¢ The rules rule1 . . . augment and, in case of conļ¬‚ict, override rules currently in
eļ¬€ect.
ā€¢ A rule declaring the token match a delimiter takes eļ¬€ect.
ā€¢ Expressions are parsed with binding-power 0 until the token match is reached. If
the token sep does not appear between each pair of expressions parsed, a warning
is issued.
ā€¢ If sop is a procedure, it is applied to the list of parsed expressions; the resulting
value is incorporated into the expression being built. Otherwise, the list of sop
and the parsed expressions is incorporated.
ā€¢ The ruleset in eļ¬€ect before tk was parsed is restored; rule1 . . . are forgotten.
[Function]prec:inmatchfix tk sop sep match lbp rule1 . . .
Returns a rule declaring the left-binding-precedence of the token tk is lbp and speci-
fying the following actions take place when tk is parsed:
ā€¢ The rules rule1 . . . augment and, in case of conļ¬‚ict, override rules currently in
eļ¬€ect.
ā€¢ A rule declaring the token match a delimiter takes eļ¬€ect.
ā€¢ Expressions are parsed with binding-power 0 until the token match is reached. If
the token sep does not appear between each pair of expressions parsed, a warning
is issued.
ā€¢ If sop is a procedure, it is applied to the list of left and the parsed expressions;
the resulting value is incorporated into the expression being built. Otherwise,
the list of sop, the left expression, and the parsed expressions is incorporated.
ā€¢ The ruleset in eļ¬€ect before tk was parsed is restored; rule1 . . . are forgotten.
4.2 Format (version 3.1)
(require ā€™format) or (require ā€™srfi-28)
Chapter 4: Textual Conversion Packages 47
4.2.1 Format Interface
[Function]format destination format-string . arguments
An almost complete implementation of Common LISP format description according
to the CL reference book Common LISP from Guy L. Steele, Digital Press. Backward
compatible to most of the available Scheme format implementations.
Returns #t, #f or a string; has side eļ¬€ect of printing according to format-string. If
destination is #t, the output is to the current output port and #t is returned. If
destination is #f, a formatted string is returned as the result of the call. NEW: If
destination is a string, destination is regarded as the format string; format-string is
then the ļ¬rst argument and the output is returned as a string. If destination is a
number, the output is to the current error port if available by the implementation.
Otherwise destination must be an output port and #t is returned.
format-string must be a string. In case of a formatting error format returns #f and
prints a message on the current output or error port. Characters are output as if
the string were output by the display function with the exception of those preļ¬xed
by a tilde (~). For a detailed description of the format-string syntax please consult
a Common LISP format reference manual. For a test suite to verify this format
implementation load formatst.scm.
4.2.2 Format Speciļ¬cation (Format version 3.1)
Please consult a Common LISP format reference manual for a detailed description of the
format string syntax. For a demonstration of the implemented directives see formatst.scm.
This implementation supports directive parameters and modiļ¬ers (: and @ characters).
Multiple parameters must be separated by a comma (,). Parameters can be numerical pa-
rameters (positive or negative), character parameters (preļ¬xed by a quote character (ā€™),
variable parameters (v), number of rest arguments parameter (#), empty and default pa-
rameters. Directive characters are case independent. The general form of a directive is:
directive ::= ~{directive-parameter,}[:][@]directive-character
directive-parameter ::= [ [-|+]{0-9}+ | ā€™character | v | # ]
4.2.2.1 Implemented CL Format Control Directives
Documentation syntax: Uppercase characters represent the corresponding control directive
characters. Lowercase characters represent control directive parameter descriptions.
~A Any (print as display does).
~@A left pad.
~mincol,colinc,minpad,padcharA
full padding.
~S S-expression (print as write does).
~@S left pad.
~mincol,colinc,minpad,padcharS
full padding.
Chapter 4: Textual Conversion Packages 48
~D Decimal.
~@D print number sign always.
~:D print comma separated.
~mincol,padchar,commacharD
padding.
~X Hexadecimal.
~@X print number sign always.
~:X print comma separated.
~mincol,padchar,commacharX
padding.
~O Octal.
~@O print number sign always.
~:O print comma separated.
~mincol,padchar,commacharO
padding.
~B Binary.
~@B print number sign always.
~:B print comma separated.
~mincol,padchar,commacharB
padding.
~nR Radix n.
~n,mincol,padchar,commacharR
padding.
~@R print a number as a Roman numeral.
~:@R print a number as an ā€œold fashionedā€ Roman numeral.
~:R print a number as an ordinal English number.
~R print a number as a cardinal English number.
~P Plural.
~@P prints y and ies.
~:P as ~P but jumps 1 argument backward.
~:@P as ~@P but jumps 1 argument backward.
~C Character.
~@C prints a character as the reader can understand it (i.e. #\ preļ¬xing).
~:C prints a character as emacs does (eg. ^C for ASCII 03).
Chapter 4: Textual Conversion Packages 49
~F Fixed-format ļ¬‚oating-point (prints a ļ¬‚onum like mmm.nnn).
~width,digits,scale,overflowchar,padcharF
~@F If the number is positive a plus sign is printed.
~E Exponential ļ¬‚oating-point (prints a ļ¬‚onum like mmm.nnnEee).
~width,digits,exponentdigits,scale,overflowchar,padchar,exponentcharE
~@E If the number is positive a plus sign is printed.
~G General ļ¬‚oating-point (prints a ļ¬‚onum either ļ¬xed or exponential).
~width,digits,exponentdigits,scale,overflowchar,padchar,exponentcharG
~@G If the number is positive a plus sign is printed.
~$ Dollars ļ¬‚oating-point (prints a ļ¬‚onum in ļ¬xed with signs separated).
~digits,scale,width,padchar$
~@$ If the number is positive a plus sign is printed.
~:@$ A sign is always printed and appears before the padding.
~:$ The sign appears before the padding.
~% Newline.
~n% print n newlines.
~& print newline if not at the beginning of the output line.
~n& prints ~& and then n-1 newlines.
~| Page Separator.
~n| print n page separators.
~~ Tilde.
~n~ print n tildes.
~<newline>
Continuation Line.
~:<newline>
newline is ignored, white space left.
~@<newline>
newline is left, white space ignored.
~T Tabulation.
~@T relative tabulation.
~colnum,colincT
full tabulation.
~? Indirection (expects indirect arguments as a list).
~@? extracts indirect arguments from format arguments.
~(str~) Case conversion (converts by string-downcase).
~:(str~) converts by string-capitalize.
Chapter 4: Textual Conversion Packages 50
~@(str~) converts by string-capitalize-first.
~:@(str~)
converts by string-upcase.
~* Argument Jumping (jumps 1 argument forward).
~n* jumps n arguments forward.
~:* jumps 1 argument backward.
~n:* jumps n arguments backward.
~@* jumps to the 0th argument.
~n@* jumps to the nth argument (beginning from 0)
~[str0~;str1~;...~;strn~]
Conditional Expression (numerical clause conditional).
~n[ take argument from n.
~@[ true test conditional.
~:[ if-else-then conditional.
~; clause separator.
~:; default clause follows.
~{str~} Iteration (args come from the next argument (a list)). Iteration bounding is
controlled by conļ¬guration variables format:iteration-bounded and format:max-
iterations. With both variables default, a maximum of 100 iterations will be
performed.
~n{ at most n iterations.
~:{ args from next arg (a list of lists).
~@{ args from the rest of arguments.
~:@{ args from the rest args (lists).
~^ Up and out.
~n^ aborts if n = 0
~n,m^ aborts if n = m
~n,m,k^ aborts if n < = m <= k
4.2.2.2 Not Implemented CL Format Control Directives
~:A print #f as an empty list (see below).
~:S print #f as an empty list (see below).
~<~> Justiļ¬cation.
~:^ (sorry I donā€™t understand its semantics completely)
Chapter 4: Textual Conversion Packages 51
4.2.2.3 Extended, Replaced and Additional Control Directives
~mincol,padchar,commachar,commawidthD
~mincol,padchar,commachar,commawidthX
~mincol,padchar,commachar,commawidthO
~mincol,padchar,commachar,commawidthB
~n,mincol,padchar,commachar,commawidthR
commawidth is the number of characters between two comma characters.
~I print a R4RS complex number as ~F~@Fi with passed parameters for ~F.
~Y Pretty print formatting of an argument for scheme code lists.
~K Same as ~?.
~! Flushes the output if format destination is a port.
~_ Print a #\space character
~n_ print n #\space characters.
~/ Print a #\tab character
~n/ print n #\tab characters.
~nC Takes n as an integer representation for a character. No arguments are con-
sumed. n is converted to a character by integer->char. n must be a positive
decimal number.
~:S Print out readproof. Prints out internal objects represented as #<...> as strings
"#<...>" so that the format output can always be processed by read.
~:A Print out readproof. Prints out internal objects represented as #<...> as strings
"#<...>" so that the format output can always be processed by read.
~Q Prints information and a copyright notice on the format implementation.
~:Q prints format version.
~F, ~E, ~G, ~$
may also print number strings, i.e. passing a number as a string and format it
accordingly.
4.2.2.4 Conļ¬guration Variables
Format has some conļ¬guration variables at the beginning of format.scm to suit the systems
and users needs. There should be no modiļ¬cation necessary for the conļ¬guration that
comes with SLIB. If modiļ¬cation is desired the variable should be set after the format code
is loaded. Format detects automatically if the running scheme system implements ļ¬‚oating
point numbers and complex numbers.
format:symbol-case-conv
Symbols are converted by symbol->string so the case type of the printed
symbols is implementation dependent. format:symbol-case-conv is a one arg
closure which is either #f (no conversion), string-upcase, string-downcase
or string-capitalize. (default #f)
Chapter 4: Textual Conversion Packages 52
format:iobj-case-conv
As format:symbol-case-conv but applies for the representation of implementa-
tion internal objects. (default #f)
format:expch
The character preļ¬xing the exponent value in ~E printing. (default #\E)
format:iteration-bounded
When #t, a ~{...~} control will iterate no more than the number of times
speciļ¬ed by format:max-iterations regardless of the number of iterations implied
by modiļ¬ers and arguments. When #f, a ~{...~} control will iterate the
number of times implied by modiļ¬ers and arguments, unless termination is
forced by language or system limitations. (default #t)
format:max-iterations
The maximum number of iterations performed by a ~{...~} control. Has eļ¬€ect
only when format:iteration-bounded is #t. (default 100)
4.2.2.5 Compatibility With Other Format Implementations
SLIB format 2.x:
See format.doc.
SLIB format 1.4:
Downward compatible except for padding support and ~A, ~S, ~P, ~X upper-
case printing. SLIB format 1.4 uses C-style printf padding support which is
completely replaced by the CL format padding style.
MIT C-Scheme 7.1:
Downward compatible except for ~, which is not documented (ignores all char-
acters inside the format string up to a newline character). (7.1 implements ~a,
~s, ~newline, ~~, ~%, numerical and variable parameters and :/@ modiļ¬ers in
the CL sense).
Elk 1.5/2.0:
Downward compatible except for ~A and ~S which print in uppercase. (Elk
implements ~a, ~s, ~~, and ~% (no directive parameters or modiļ¬ers)).
Scheme->C 01nov91:
Downward compatible except for an optional destination parameter: S2C ac-
cepts a format call without a destination which returns a formatted string. This
is equivalent to a #f destination in S2C. (S2C implements ~a, ~s, ~c, ~%, and
~~ (no directive parameters or modiļ¬ers)).
This implementation of format is solely useful in the SLIB context because it requires
other components provided by SLIB.
4.3 Standard Formatted I/O
4.3.1 stdio
(require ā€™stdio)
requires printf and scanf and additionally deļ¬nes the symbols:
Chapter 4: Textual Conversion Packages 53
[Variable]stdin
Deļ¬ned to be (current-input-port).
[Variable]stdout
Deļ¬ned to be (current-output-port).
[Variable]stderr
Deļ¬ned to be (current-error-port).
4.3.2 Standard Formatted Output
(require ā€™printf)
[Procedure]printf format arg1 . . .
[Procedure]fprintf port format arg1 . . .
[Procedure]sprintf str format arg1 . . .
[Procedure]sprintf #f format arg1 . . .
[Procedure]sprintf k format arg1 . . .
Each function converts, formats, and outputs its arg1 . . . arguments according to
the control string format argument and returns the number of characters output.
printf sends its output to the port (current-output-port). fprintf sends its
output to the port port. sprintf string-set!s locations of the non-constant string
argument str to the output characters.
Two extensions of sprintf return new strings. If the ļ¬rst argument is #f, then the
returned stringā€™s length is as many characters as speciļ¬ed by the format and data; if
the ļ¬rst argument is a non-negative integer k, then the length of the returned string
is also bounded by k.
The string format contains plain characters which are copied to the output stream,
and conversion speciļ¬cations, each of which results in fetching zero or more of the
arguments arg1 . . . . The results are undeļ¬ned if there are an insuļ¬ƒcient number
of arguments for the format. If format is exhausted while some of the arg1 . . .
arguments remain unused, the excess arg1 . . . arguments are ignored.
The conversion speciļ¬cations in a format string have the form:
% [ flags ] [ width ] [ . precision ] [ type ] conversion
An output conversion speciļ¬cations consist of an initial ā€˜%ā€™ character followed in se-
quence by:
ā€¢ Zero or more ļ¬‚ag characters that modify the normal behavior of the conversion
speciļ¬cation.
ā€˜-ā€™ Left-justify the result in the ļ¬eld. Normally the result is right-
justiļ¬ed.
ā€˜+ā€™ For the signed ā€˜%dā€™ and ā€˜%iā€™ conversions and all inexact conversions,
preļ¬x a plus sign if the value is positive.
ā€˜ ā€™ For the signed ā€˜%dā€™ and ā€˜%iā€™ conversions, if the result doesnā€™t start
with a plus or minus sign, preļ¬x it with a space character instead.
Since the ā€˜+ā€™ ļ¬‚ag ensures that the result includes a sign, this ļ¬‚ag is
ignored if both are speciļ¬ed.
Chapter 4: Textual Conversion Packages 54
ā€˜#ā€™ For inexact conversions, ā€˜#ā€™ speciļ¬es that the result should always
include a decimal point, even if no digits follow it. For the ā€˜%gā€™ and
ā€˜%Gā€™ conversions, this also forces trailing zeros after the decimal point
to be printed where they would otherwise be elided.
For the ā€˜%oā€™ conversion, force the leading digit to be ā€˜0ā€™, as if by
increasing the precision. For ā€˜%xā€™ or ā€˜%Xā€™, preļ¬x a leading ā€˜0xā€™ or ā€˜0Xā€™
(respectively) to the result. This doesnā€™t do anything useful for the
ā€˜%dā€™, ā€˜%iā€™, or ā€˜%uā€™ conversions. Using this ļ¬‚ag produces output which
can be parsed by the scanf functions with the ā€˜%iā€™ conversion (see
Section 4.3.3 [Standard Formatted Input], page 56).
ā€˜0ā€™ Pad the ļ¬eld with zeros instead of spaces. The zeros are placed after
any indication of sign or base. This ļ¬‚ag is ignored if the ā€˜-ā€™ ļ¬‚ag is
also speciļ¬ed, or if a precision is speciļ¬ed for an exact converson.
ā€¢ An optional decimal integer specifying the minimum ļ¬eld width. If the normal
conversion produces fewer characters than this, the ļ¬eld is padded (with spaces
or zeros per the ā€˜0ā€™ ļ¬‚ag) to the speciļ¬ed width. This is a minimum width; if the
normal conversion produces more characters than this, the ļ¬eld is not truncated.
Alternatively, if the ļ¬eld width is ā€˜*ā€™, the next argument in the argument list
(before the actual value to be printed) is used as the ļ¬eld width. The width
value must be an integer. If the value is negative it is as though the ā€˜-ā€™ ļ¬‚ag is
set (see above) and the absolute value is used as the ļ¬eld width.
ā€¢ An optional precision to specify the number of digits to be written for numeric
conversions and the maximum ļ¬eld width for string conversions. The precision is
speciļ¬ed by a period (ā€˜.ā€™) followed optionally by a decimal integer (which defaults
to zero if omitted).
Alternatively, if the precision is ā€˜.*ā€™, the next argument in the argument list
(before the actual value to be printed) is used as the precision. The value must
be an integer, and is ignored if negative. If you specify ā€˜*ā€™ for both the ļ¬eld width
and precision, the ļ¬eld width argument precedes the precision argument. The
ā€˜.*ā€™ precision is an enhancement. C library versions may not accept this syntax.
For the ā€˜%fā€™, ā€˜%eā€™, and ā€˜%Eā€™ conversions, the precision speciļ¬es how many digits
follow the decimal-point character. The default precision is 6. If the precision is
explicitly 0, the decimal point character is suppressed.
For the ā€˜%gā€™ and ā€˜%Gā€™ conversions, the precision speciļ¬es how many signiļ¬cant
digits to print. Signiļ¬cant digits are the ļ¬rst digit before the decimal point,
and all the digits after it. If the precision is 0 or not speciļ¬ed for ā€˜%gā€™ or ā€˜%Gā€™,
it is treated like a value of 1. If the value being printed cannot be expressed
accurately in the speciļ¬ed number of digits, the value is rounded to the nearest
number that ļ¬ts.
For exact conversions, if a precision is supplied it speciļ¬es the minimum number
of digits to appear; leading zeros are produced if necessary. If a precision is not
supplied, the number is printed with as many digits as necessary. Converting an
exact ā€˜0ā€™ with an explicit precision of zero produces no characters.
Chapter 4: Textual Conversion Packages 55
ā€¢ An optional one of ā€˜lā€™, ā€˜hā€™ or ā€˜Lā€™, which is ignored for numeric conversions. It is
an error to specify these modiļ¬ers for non-numeric conversions.
ā€¢ A character that speciļ¬es the conversion to be applied.
Exact Conversions
ā€˜bā€™, ā€˜Bā€™ Print an integer as an unsigned binary number.
Note: ā€˜%bā€™ and ā€˜%Bā€™ are SLIB extensions.
ā€˜dā€™, ā€˜iā€™ Print an integer as a signed decimal number. ā€˜%dā€™ and ā€˜%iā€™ are synony-
mous for output, but are diļ¬€erent when used with scanf for input (see
Section 4.3.3 [Standard Formatted Input], page 56).
ā€˜oā€™ Print an integer as an unsigned octal number.
ā€˜uā€™ Print an integer as an unsigned decimal number.
ā€˜xā€™, ā€˜Xā€™ Print an integer as an unsigned hexadecimal number. ā€˜%xā€™ prints
using the digits ā€˜0123456789abcdefā€™. ā€˜%Xā€™ prints using the digits
ā€˜0123456789ABCDEFā€™.
Inexact Conversions
ā€˜fā€™ Print a ļ¬‚oating-point number in ļ¬xed-point notation.
ā€˜eā€™, ā€˜Eā€™ Print a ļ¬‚oating-point number in exponential notation. ā€˜%eā€™ prints ā€˜eā€™
between mantissa and exponont. ā€˜%Eā€™ prints ā€˜Eā€™ between mantissa and
exponont.
ā€˜gā€™, ā€˜Gā€™ Print a ļ¬‚oating-point number in either ļ¬xed or exponential notation,
whichever is more appropriate for its magnitude. Unless an ā€˜#ā€™ ļ¬‚ag has
been supplied, trailing zeros after a decimal point will be stripped oļ¬€.
ā€˜%gā€™ prints ā€˜eā€™ between mantissa and exponont. ā€˜%Gā€™ prints ā€˜Eā€™ between
mantissa and exponent.
ā€˜kā€™, ā€˜Kā€™ Print a number like ā€˜%gā€™, except that an SI preļ¬x is output after the
number, which is scaled accordingly. ā€˜%Kā€™ outputs a dot between number
and preļ¬x, ā€˜%kā€™ does not.
Other Conversions
ā€˜cā€™ Print a single character. The ā€˜-ā€™ ļ¬‚ag is the only one which can be speciļ¬ed.
It is an error to specify a precision.
ā€˜sā€™ Print a string. The ā€˜-ā€™ ļ¬‚ag is the only one which can be speciļ¬ed. A pre-
cision speciļ¬es the maximum number of characters to output; otherwise
all characters in the string are output.
ā€˜aā€™, ā€˜Aā€™ Print a scheme expression. The ā€˜-ā€™ ļ¬‚ag left-justiļ¬es the output. The ā€˜#ā€™
ļ¬‚ag speciļ¬es that strings and characters should be quoted as by write
(which can be read using read); otherwise, output is as display prints.
A precision speciļ¬es the maximum number of characters to output; oth-
erwise as many characters as needed are output.
Note: ā€˜%aā€™ and ā€˜%Aā€™ are SLIB extensions.
Chapter 4: Textual Conversion Packages 56
ā€˜%ā€™ Print a literal ā€˜%ā€™ character. No argument is consumed. It is an error to
specify ļ¬‚ags, ļ¬eld width, precision, or type modiļ¬ers with ā€˜%%ā€™.
4.3.3 Standard Formatted Input
(require ā€™scanf)
[Function]scanf-read-list format
[Function]scanf-read-list format port
[Function]scanf-read-list format string
[Macro]scanf format arg1 . . .
[Macro]fscanf port format arg1 . . .
[Macro]sscanf str format arg1 . . .
Each function reads characters, interpreting them according to the control string
format argument.
scanf-read-list returns a list of the items speciļ¬ed as far as the input matches
format. scanf, fscanf, and sscanf return the number of items successfully matched
and stored. scanf, fscanf, and sscanf also set the location corresponding to arg1
. . . using the methods:
symbol set!
car expression
set-car!
cdr expression
set-cdr!
vector-ref expression
vector-set!
substring expression
substring-move-left!
The argument to a substring expression in arg1 . . . must be a non-constant string.
Characters will be stored starting at the position speciļ¬ed by the second argument
to substring. The number of characters stored will be limited by either the position
speciļ¬ed by the third argument to substring or the length of the matched string,
whichever is less.
The control string, format, contains conversion speciļ¬cations and other characters
used to direct interpretation of input sequences. The control string contains:
ā€¢ White-space characters (blanks, tabs, newlines, or formfeeds) that cause input
to be read (and discarded) up to the next non-white-space character.
ā€¢ An ordinary character (not ā€˜%ā€™) that must match the next character of the input
stream.
ā€¢ Conversion speciļ¬cations, consisting of the character ā€˜%ā€™, an optional assignment
suppressing character ā€˜*ā€™, an optional numerical maximum-ļ¬eld width, an op-
tional ā€˜lā€™, ā€˜hā€™ or ā€˜Lā€™ which is ignored, and a conversion code.
Chapter 4: Textual Conversion Packages 57
Unless the speciļ¬cation contains the ā€˜nā€™ conversion character (described below), a
conversion speciļ¬cation directs the conversion of the next input ļ¬eld. The result of
a conversion speciļ¬cation is returned in the position of the corresponding argument
points, unless ā€˜*ā€™ indicates assignment suppression. Assignment suppression provides
a way to describe an input ļ¬eld to be skipped. An input ļ¬eld is deļ¬ned as a string
of characters; it extends to the next inappropriate character or until the ļ¬eld width,
if speciļ¬ed, is exhausted.
Note: This speciļ¬cation of format strings diļ¬€ers from the ANSI C and
POSIX speciļ¬cations. In SLIB, white space before an input ļ¬eld is not
skipped unless white space appears before the conversion speciļ¬cation in
the format string. In order to write format strings which work identically
with ANSI C and SLIB, prepend whitespace to all conversion speciļ¬ca-
tions except ā€˜[ā€™ and ā€˜cā€™.
The conversion code indicates the interpretation of the input ļ¬eld; For a suppressed
ļ¬eld, no value is returned. The following conversion codes are legal:
ā€˜%ā€™ A single % is expected in the input at this point; no value is returned.
ā€˜dā€™, ā€˜Dā€™ A decimal integer is expected.
ā€˜uā€™, ā€˜Uā€™ An unsigned decimal integer is expected.
ā€˜oā€™, ā€˜Oā€™ An octal integer is expected.
ā€˜xā€™, ā€˜Xā€™ A hexadecimal integer is expected.
ā€˜iā€™ An integer is expected. Returns the value of the next input item, inter-
preted according to C conventions; a leading ā€˜0ā€™ implies octal, a leading
ā€˜0xā€™ implies hexadecimal; otherwise, decimal is assumed.
ā€˜nā€™ Returns the total number of bytes (including white space) read by scanf.
No input is consumed by %n.
ā€˜fā€™, ā€˜Fā€™, ā€˜eā€™, ā€˜Eā€™, ā€˜gā€™, ā€˜Gā€™
A ļ¬‚oating-point number is expected. The input format for ļ¬‚oating-point
numbers is an optionally signed string of digits, possibly containing a
radix character ā€˜.ā€™, followed by an optional exponent ļ¬eld consisting of
an ā€˜Eā€™ or an ā€˜eā€™, followed by an optional ā€˜+ā€™, ā€˜-ā€™, or space, followed by an
integer.
ā€˜cā€™, ā€˜Cā€™ Width characters are expected. The normal skip-over-white-space is sup-
pressed in this case; to read the next non-space character, use ā€˜%1sā€™. If a
ļ¬eld width is given, a string is returned; up to the indicated number of
characters is read.
ā€˜sā€™, ā€˜Sā€™ A character string is expected The input ļ¬eld is terminated by a white-
space character. scanf cannot read a null string.
ā€˜[ā€™ Indicates string data and the normal skip-over-leading-white-space is sup-
pressed. The left bracket is followed by a set of characters, called the
scanset, and a right bracket; the input ļ¬eld is the maximal sequence of
input characters consisting entirely of characters in the scanset. ā€˜^ā€™, when
Chapter 4: Textual Conversion Packages 58
it appears as the ļ¬rst character in the scanset, serves as a complement
operator and redeļ¬nes the scanset as the set of all characters not con-
tained in the remainder of the scanset string. Construction of the scanset
follows certain conventions. A range of characters may be represented by
the construct ļ¬rst-last, enabling ā€˜[0123456789]ā€™ to be expressed ā€˜[0-9]ā€™.
Using this convention, ļ¬rst must be lexically less than or equal to last;
otherwise, the dash stands for itself. The dash also stands for itself when
it is the ļ¬rst or the last character in the scanset. To include the right
square bracket as an element of the scanset, it must appear as the ļ¬rst
character (possibly preceded by a ā€˜^ā€™) of the scanset, in which case it
will not be interpreted syntactically as the closing bracket. At least one
character must match for this conversion to succeed.
The scanf functions terminate their conversions at end-of-ļ¬le, at the end of the
control string, or when an input character conļ¬‚icts with the control string. In the
latter case, the oļ¬€ending character is left unread in the input stream.
4.4 Program and Arguments
4.4.1 Getopt
(require ā€™getopt)
This routine implements Posix command line argument parsing. Notice that returning
values through global variables means that getopt is not reentrant.
Obedience to Posix format for the getopt calls sows confusion. Passing argc and
argv as arguments while referencing optind as a global variable leads to strange behavior,
especially when the calls to getopt are buried in other procedures.
Even in C, argc can be derived from argv; what purpose does it serve beyond providing
an opportunity for argv/argc mismatch? Just such a mismatch existed for years in a SLIB
getopt-- example.
I have removed the argc and argv arguments to getopt procedures; and replaced them
with a global variable:
[Variable]*argv*
Deļ¬ne *argv* with a list of arguments before calling getopt procedures. If you donā€™t
want the ļ¬rst (0th) element to be ignored, set *optind* to 0 (after requiring getopt).
[Variable]*optind*
Is the index of the current element of the command line. It is initially one. In order
to parse a new command line or reparse an old one, *optind* must be reset.
[Variable]*optarg*
Is set by getopt to the (string) option-argument of the current option.
[Function]getopt optstring
Returns the next option letter in *argv* (starting from (vector-ref argv
*optind*)) that matches a letter in optstring. *argv* is a vector or list of strings,
the 0th of which getopt usually ignores. optstring is a string of recognized option
Chapter 4: Textual Conversion Packages 59
characters; if a character is followed by a colon, the option takes an argument which
may be immediately following it in the string or in the next element of *argv*.
*optind* is the index of the next element of the *argv* vector to be processed. It
is initialized to 1 by getopt.scm, and getopt updates it when it ļ¬nishes with each
element of *argv*.
getopt returns the next option character from *argv* that matches a character in
optstring, if there is one that matches. If the option takes an argument, getopt sets
the variable *optarg* to the option-argument as follows:
ā€¢ If the option was the last character in the string pointed to by an element of
*argv*, then *optarg* contains the next element of *argv*, and *optind* is
incremented by 2. If the resulting value of *optind* is greater than or equal to
(length *argv*), this indicates a missing option argument, and getopt returns
an error indication.
ā€¢ Otherwise, *optarg* is set to the string following the option character in that
element of *argv*, and *optind* is incremented by 1.
If, when getopt is called, the string (vector-ref argv *optind*) either does not
begin with the character #\- or is just "-", getopt returns #f without changing
*optind*. If (vector-ref argv *optind*) is the string "--", getopt returns #f
after incrementing *optind*.
If getopt encounters an option character that is not contained in optstring, it returns
the question-mark #\? character. If it detects a missing option argument, it returns
the colon character #\: if the ļ¬rst character of optstring was a colon, or a question-
mark character otherwise. In either case, getopt sets the variable getopt:opt to the
option character that caused the error.
The special option "--" can be used to delimit the end of the options; #f is returned,
and "--" is skipped.
RETURN VALUE
getopt returns the next option character speciļ¬ed on the command line. A colon #\:
is returned if getopt detects a missing argument and the ļ¬rst character of optstring
was a colon #\:.
A question-mark #\? is returned if getopt encounters an option character not in
optstring or detects a missing argument and the ļ¬rst character of optstring was not
a colon #\:.
Otherwise, getopt returns #f when all command line options have been parsed.
Example:
#! /usr/local/bin/scm
(require ā€™program-arguments)
(require ā€™getopt)
(define argv (program-arguments))
(define opts ":a:b:cd")
(let loop ((opt (getopt (length argv) argv opts)))
(case opt
Chapter 4: Textual Conversion Packages 60
((#\a) (print "option a: " *optarg*))
((#\b) (print "option b: " *optarg*))
((#\c) (print "option c"))
((#\d) (print "option d"))
((#\?) (print "error" getopt:opt))
((#\:) (print "missing arg" getopt:opt))
((#f) (if (< *optind* (length argv))
(print "argv[" *optind* "]="
(list-ref argv *optind*)))
(set! *optind* (+ *optind* 1))))
(if (< *optind* (length argv))
(loop (getopt (length argv) argv opts))))
(slib:exit)
4.4.2 Getoptā€”
[Function]getopt-- optstring
The procedure getopt-- is an extended version of getopt which parses long op-
tion names of the form ā€˜--hold-the-onionsā€™ and ā€˜--verbosity-level=extremeā€™.
Getopt-- behaves as getopt except for non-empty options beginning with ā€˜--ā€™.
Options beginning with ā€˜--ā€™ are returned as strings rather than characters. If a value
is assigned (using ā€˜=ā€™) to a long option, *optarg* is set to the value. The ā€˜=ā€™ and
value are not returned as part of the option string.
No information is passed to getopt-- concerning which long options should be ac-
cepted or whether such options can take arguments. If a long option did not have
an argument, *optarg* will be set to #f. The caller is responsible for detecting and
reporting errors.
(define opts ":-:b:")
(define *argv* ā€™("foo" "-b9" "--f1" "--2=" "--g3=35234.342" "--"))
(define *optind* 1)
(define *optarg* #f)
(require ā€™qp)
(do ((i 5 (+ -1 i)))
((zero? i))
(let ((opt (getopt-- opts)))
(print *optind* opt *optarg*)))
a
2 #\b "9"
3 "f1" #f
4 "2" ""
5 "g3" "35234.342"
5 #f "35234.342"
4.4.3 Command Line
(require ā€™read-command)
Chapter 4: Textual Conversion Packages 61
[Function]read-command port
[Function]read-command
read-command converts a command line into a list of strings suitable for parsing by
getopt. The syntax of command lines supported resembles that of popular shells.
read-command updates port to point to the ļ¬rst character past the command delim-
iter.
If an end of ļ¬le is encountered in the input before any characters are found that can
begin an object or comment, then an end of ļ¬le object is returned.
The port argument may be omitted, in which case it defaults to the value returned
by current-input-port.
The ļ¬elds into which the command line is split are delimited by whitespace as de-
ļ¬ned by char-whitespace?. The end of a command is delimited by end-of-ļ¬le or
unescaped semicolon (;) or newline. Any character can be literally included in a
ļ¬eld by escaping it with a backslach (\).
The initial character and types of ļ¬elds recognized are:
ā€˜\ā€™ The next character has is taken literally and not interpreted as a ļ¬eld
delimiter. If \ is the last character before a newline, that newline is
just ignored. Processing continues from the characters after the newline
as though the backslash and newline were not there.
ā€˜"ā€™ The characters up to the next unescaped " are taken literally, according
to [R4RS] rules for literal strings (see Section ā€œStringsā€ in Revised(4)
Scheme).
ā€˜(ā€™, ā€˜%ā€™ā€™ One scheme expression is read starting with this character. The read ex-
pression is evaluated, converted to a string (using display), and replaces
the expression in the returned ļ¬eld.
ā€˜;ā€™ Semicolon delimits a command. Using semicolons more than one com-
mand can appear on a line. Escaped semicolons and semicolons inside
strings do not delimit commands.
The comment ļ¬eld diļ¬€ers from the previous ļ¬elds in that it must be the ļ¬rst character
of a command or appear after whitespace in order to be recognized. # can be part of
ļ¬elds if these conditions are not met. For instance, ab#c is just the ļ¬eld ab#c.
ā€˜#ā€™ Introduces a comment. The comment continues to the end of the line on
which the semicolon appears. Comments are treated as whitespace by
read-dommand-line and backslashes before newlines in comments are
also ignored.
[Function]read-options-file ļ¬lename
read-options-file converts an options ļ¬le into a list of strings suitable for parsing
by getopt. The syntax of options ļ¬les is the same as the syntax for command lines,
except that newlines do not terminate reading (only ; or end of ļ¬le).
If an end of ļ¬le is encountered before any characters are found that can begin an
object or comment, then an end of ļ¬le object is returned.
Chapter 4: Textual Conversion Packages 62
4.4.4 Parameter lists
(require ā€™parameters)
Arguments to procedures in scheme are distinguished from each other by their position in
the procedure call. This can be confusing when a procedure takes many arguments, many
of which are not often used.
A parameter-list is a way of passing named information to a procedure. Procedures are
also deļ¬ned to set unused parameters to default values, check parameters, and combine
parameter lists.
A parameter has the form (parameter-name value1 ...). This format allows for more than
one value per parameter-name.
A parameter-list is a list of parameters, each with a diļ¬€erent parameter-name.
[Function]make-parameter-list parameter-names
Returns an empty parameter-list with slots for parameter-names.
[Function]parameter-list-ref parameter-list parameter-name
parameter-name must name a valid slot of parameter-list. parameter-list-ref re-
turns the value of parameter parameter-name of parameter-list.
[Function]remove-parameter parameter-name parameter-list
Removes the parameter parameter-name from parameter-list. remove-parameter
does not alter the argument parameter-list.
If there are more than one parameter-name parameters, an error is signaled.
[Procedure]adjoin-parameters! parameter-list parameter1 . . .
Returns parameter-list with parameter1 . . . merged in.
[Procedure]parameter-list-expand expanders parameter-list
expanders is a list of procedures whose order matches the order of the parameter-
names in the call to make-parameter-list which created parameter-list. For each
non-false element of expanders that procedure is mapped over the corresponding
parameter value and the returned parameter lists are merged into parameter-list.
This process is repeated until parameter-list stops growing. The value returned from
parameter-list-expand is unspeciļ¬ed.
[Function]fill-empty-parameters defaulters parameter-list
defaulters is a list of procedures whose order matches the order of the
parameter-names in the call to make-parameter-list which created parameter-list.
fill-empty-parameters returns a new parameter-list with each empty parameter
replaced with the list returned by calling the corresponding defaulter with
parameter-list as its argument.
[Function]check-parameters checks parameter-list
checks is a list of procedures whose order matches the order of the parameter-names
in the call to make-parameter-list which created parameter-list.
check-parameters returns parameter-list if each check of the corresponding
parameter-list returns non-false. If some check returns #f a warning is signaled.
Chapter 4: Textual Conversion Packages 63
In the following procedures arities is a list of symbols. The elements of arities can be:
single Requires a single parameter.
optional A single parameter or no parameter is acceptable.
boolean A single boolean parameter or zero parameters is acceptable.
nary Any number of parameters are acceptable.
nary1 One or more of parameters are acceptable.
[Function]parameter-list->arglist positions arities parameter-list
Returns parameter-list converted to an argument list. Parameters of arity type
single and boolean are converted to the single value associated with them. The
other arity types are converted to lists of the value(s).
positions is a list of positive integers whose order matches the order of the parameter-
names in the call to make-parameter-list which created parameter-list. The inte-
gers specify in which argument position the corresponding parameter should appear.
4.4.5 Getopt Parameter lists
(require ā€™getopt-parameters)
[Function]getopt->parameter-list optnames arities types aliases desc . . .
Returns *argv* converted to a parameter-list. optnames are the parameter-names.
arities and types are lists of symbols corresponding to optnames.
aliases is a list of lists of strings or integers paired with elements of optnames. Each
one-character string will be treated as a single ā€˜-ā€™ option by getopt. Longer strings
will be treated as long-named options (see Section 4.4.1 [Getopt], page 58).
If the aliases association list has only strings as its cars, then all the option-arguments
after an option (and before the next option) are adjoined to that option.
If the aliases association list has integers, then each (string) option will take at most
one option-argument. Unoptioned arguments are collected in a list. A ā€˜-1ā€™ alias will
take the last argument in this list; ā€˜+1ā€™ will take the ļ¬rst argument in the list. The
aliases -2 then +2; -3 then +3; . . . are tried so long as a positive or negative consecutive
alias is found and arguments remain in the list. Finally a ā€˜0ā€™ alias, if found, absorbs
any remaining arguments.
In all cases, if unclaimed arguments remain after processing, a warning is signaled
and #f is returned.
[Function]getopt->arglist optnames positions arities types defaulters checks
aliases desc . . .
Like getopt->parameter-list, but converts *argv* to an argument-list as speciļ¬ed
by optnames, positions, arities, types, defaulters, checks, and aliases. If the options
supplied violate the arities or checks constraints, then a warning is signaled and #f
is returned.
These getopt functions can be used with SLIB relational databases. For an example, See
Section 6.1.1 [Using Databases], page 162.
Chapter 4: Textual Conversion Packages 64
If errors are encountered while processing options, directions for using the options (and
argument strings desc . . .) are printed to current-error-port.
(begin
(set! *optind* 1)
(set! *argv* ā€™("cmd" "-?")
(getopt->parameter-list
ā€™(flag number symbols symbols string flag2 flag3 num2 num3)
ā€™(boolean optional nary1 nary single boolean boolean nary nary)
ā€™(boolean integer symbol symbol string boolean boolean integer integer)
ā€™(("flag" flag)
("f" flag)
("Flag" flag2)
("B" flag3)
("optional" number)
("o" number)
("nary1" symbols)
("N" symbols)
("nary" symbols)
("n" symbols)
("single" string)
("s" string)
("a" num2)
("Abs" num3))))
a
Usage: cmd [OPTION ARGUMENT ...] ...
-f, --flag
-o, --optional=<number>
-n, --nary=<symbols> ...
-N, --nary1=<symbols> ...
-s, --single=<string>
--Flag
-B
-a <num2> ...
--Abs=<num3> ...
ERROR: getopt->parameter-list "unrecognized option" "-?"
4.4.6 Filenames
(require ā€™filename)
[Function]filename:match?? pattern
[Function]filename:match-ci?? pattern
Returns a predicate which returns a non-false value if its string argument matches
(the string) pattern, false otherwise. Filename matching is like glob expansion de-
scribed the bash manpage, except that names beginning with ā€˜.ā€™ are matched and ā€˜/ā€™
characters are not treated specially.
Chapter 4: Textual Conversion Packages 65
These functions interpret the following characters specially in pattern strings:
ā€˜*ā€™ Matches any string, including the null string.
ā€˜?ā€™ Matches any single character.
ā€˜[...]ā€™ Matches any one of the enclosed characters. A pair of characters sepa-
rated by a minus sign (-) denotes a range; any character lexically between
those two characters, inclusive, is matched. If the ļ¬rst character following
the ā€˜[ā€™ is a ā€˜!ā€™ or a ā€˜^ā€™ then any character not enclosed is matched. A ā€˜-ā€™
or ā€˜]ā€™ may be matched by including it as the ļ¬rst or last character in the
set.
[Function]filename:substitute?? pattern template
[Function]filename:substitute-ci?? pattern template
Returns a function transforming a single string argument according to glob patterns
pattern and template. pattern and template must have the same number of wildcard
speciļ¬cations, which need not be identical. pattern and template may have a diļ¬€erent
number of literal sections. If an argument to the function matches pattern in the sense
of filename:match?? then it returns a copy of template in which each wildcard
speciļ¬cation is replaced by the part of the argument matched by the corresponding
wildcard speciļ¬cation in pattern. A * wildcard matches the longest leftmost string
possible. If the argument does not match pattern then false is returned.
template may be a function accepting the same number of string arguments as there
are wildcard speciļ¬cations in pattern. In the case of a match the result of applying
template to a list of the substrings matched by wildcard speciļ¬cations will be returned,
otherwise template will not be called and #f will be returned.
((filename:substitute?? "scm_[0-9]*.html" "scm5c4_??.htm")
"scm_10.html")
ā‡’
"scm5c4_10.htm"
((filename:substitute?? "??" "beg?mid?end") "AZ")
ā‡’
"begAmidZend"
((filename:substitute?? "*na*" "?NA?") "banana")
ā‡’
"banaNA"
((filename:substitute?? "?*?" (lambda (s1 s2 s3) (string-append s3 s1)))
"ABZ")
ā‡’
"ZA"
[Function]replace-suffix str old new
str can be a string or a list of strings. Returns a new string (or strings) similar to
str but with the suļ¬ƒx string old removed and the suļ¬ƒx string new appended. If the
end of str does not match old, an error is signaled.
(replace-suffix "/usr/local/lib/slib/batch.scm" ".scm" ".c")
ā‡’
"/usr/local/lib/slib/batch.c"
[Function]call-with-tmpnam proc k
[Function]call-with-tmpnam proc
Calls proc with k arguments, strings returned by successive calls to tmpnam. If proc
returns, then any ļ¬les named by the arguments to proc are deleted automatically and
Chapter 4: Textual Conversion Packages 66
the value(s) yielded by the proc is(are) returned. k may be ommited, in which case
it defaults to 1.
[Function]call-with-tmpnam proc suļ¬ƒx1 . . .
Calls proc with strings returned by successive calls to tmpnam, each with the cor-
responding suļ¬ƒx string appended. If proc returns, then any ļ¬les named by the
arguments to proc are deleted automatically and the value(s) yielded by the proc
is(are) returned.
4.4.7 Batch
(require ā€™batch)
The batch procedures provide a way to write and execute portable scripts for a variety
of operating systems. Each batch: procedure takes as its ļ¬rst argument a parameter-list
(see Section 4.4.4 [Parameter lists], page 62). This parameter-list argument parms contains
named associations. Batch currently uses 2 of these:
batch-port
The port on which to write lines of the batch ļ¬le.
batch-dialect
The syntax of batch ļ¬le to generate. Currently supported are:
ā€¢ unix
ā€¢ dos
ā€¢ vms
ā€¢ amigaos
ā€¢ system
ā€¢ *unknown*
The ā€˜batchā€™ module uses 2 enhanced relational tables (see Section 6.1.1 [Using
Databases], page 162) to store information linking the names of operating-systems to
batch-dialectes.
[Function]batch:initialize! database
Deļ¬nes operating-system and batch-dialect tables and adds the domain
operating-system to the enhanced relational database database.
[Variable]*operating-system*
Is batchā€™s best guess as to which operating-system it is running under.
*operating-system* is set to (software-type) (see Section 2.2 [Conļ¬guration],
page 12) unless (software-type) is unix, in which case ļ¬ner distinctions are made.
[Function]batch:call-with-output-script parms ļ¬le proc
proc should be a procedure of one argument. If ļ¬le is an output-port,
batch:call-with-output-script writes an appropriate header to ļ¬le and then
calls proc with ļ¬le as the only argument. If ļ¬le is a string, batch:call-with-
output-script opens a output-ļ¬le of name ļ¬le, writes an appropriate header
to ļ¬le, and then calls proc with the newly opened port as the only argument.
Otherwise, batch:call-with-output-script acts as if it was called with the result
of (current-output-port) as its third argument.
Chapter 4: Textual Conversion Packages 67
The rest of the batch: procedures write (or execute if batch-dialect is system) commands
to the batch port which has been added to parms or (copy-tree parms) by the code:
(adjoin-parameters! parms (list ā€™batch-port port))
[Function]batch:command parms string1 string2 . . .
Calls batch:try-command (below) with arguments, but signals an error if
batch:try-command returns #f.
These functions return a non-false value if the command was successfully translated into
the batch dialect and #f if not. In the case of the system dialect, the value is non-false if
the operation suceeded.
[Function]batch:try-command parms string1 string2 . . .
Writes a command to the batch-port in parms which executes the program named
string1 with arguments string2 . . . .
[Function]batch:try-chopped-command parms arg1 arg2 . . . list
breaks the last argument list into chunks small enough so that the command:
arg1 arg2 ... chunk
ļ¬ts withing the platformā€™s maximum command-line length.
batch:try-chopped-command calls batch:try-command with the command and re-
turns non-false only if the commands all ļ¬t and batch:try-command of each command
line returned non-false.
[Function]batch:run-script parms string1 string2 . . .
Writes a command to the batch-port in parms which executes the batch script named
string1 with arguments string2 . . . .
Note: batch:run-script and batch:try-command are not the same for some oper-
ating systems (VMS).
[Function]batch:comment parms line1 . . .
Writes comment lines line1 . . . to the batch-port in parms.
[Function]batch:lines->file parms ļ¬le line1 . . .
Writes commands to the batch-port in parms which create a ļ¬le named ļ¬le with
contents line1 . . . .
[Function]batch:delete-file parms ļ¬le
Writes a command to the batch-port in parms which deletes the ļ¬le named ļ¬le.
[Function]batch:rename-file parms old-name new-name
Writes a command to the batch-port in parms which renames the ļ¬le old-name to
new-name.
In addition, batch provides some small utilities very useful for writing scripts:
[Function]truncate-up-to path char
[Function]truncate-up-to path string
Chapter 4: Textual Conversion Packages 68
[Function]truncate-up-to path charlist
path can be a string or a list of strings. Returns path sans any preļ¬xes ending with
a character of the second argument. This can be used to derive a ļ¬lename moved
locally from elsewhere.
(truncate-up-to "/usr/local/lib/slib/batch.scm" "/")
ā‡’
"batch.scm"
[Function]string-join joiner string1 . . .
Returns a new string consisting of all the strings string1 . . . in order appended
together with the string joiner between each adjacent pair.
[Function]must-be-first list1 list2
Returns a new list consisting of the elements of list2 ordered so that if some elements
of list1 are equal? to elements of list2, then those elements will appear ļ¬rst and in
the order of list1.
[Function]must-be-last list1 list2
Returns a new list consisting of the elements of list1 ordered so that if some elements
of list2 are equal? to elements of list1, then those elements will appear last and in
the order of list2.
[Function]os->batch-dialect osname
Returns its best guess for the batch-dialect to be used for the operating-system
named osname. os->batch-dialect uses the tables added to database by
batch:initialize!.
Here is an example of the use of most of batchā€™s procedures:
(require ā€™databases)
(require ā€™parameters)
(require ā€™batch)
(require ā€™filename)
(define batch (create-database #f ā€™alist-table))
(batch:initialize! batch)
(define my-parameters
(list (list ā€™batch-dialect (os->batch-dialect *operating-system*))
(list ā€™operating-system *operating-system*)
(list ā€™batch-port (current-output-port)))) ;gets filled in later
(batch:call-with-output-script
my-parameters
"my-batch"
(lambda (batch-port)
(adjoin-parameters! my-parameters (list ā€™batch-port batch-port))
(and
(batch:comment my-parameters
Chapter 4: Textual Conversion Packages 69
"================ Write file with C program.")
(batch:rename-file my-parameters "hello.c" "hello.c~")
(batch:lines->file my-parameters "hello.c"
"#include <stdio.h>"
"int main(int argc, char **argv)"
"{"
" printf(\"hello world\\n\");"
" return 0;"
"}" )
(batch:command my-parameters "cc" "-c" "hello.c")
(batch:command my-parameters "cc" "-o" "hello"
(replace-suffix "hello.c" ".c" ".o"))
(batch:command my-parameters "hello")
(batch:delete-file my-parameters "hello")
(batch:delete-file my-parameters "hello.c")
(batch:delete-file my-parameters "hello.o")
(batch:delete-file my-parameters "my-batch")
)))
Produces the ļ¬le my-batch:
#! /bin/sh
# "my-batch" script created by SLIB/batch Sun Oct 31 18:24:10 1999
# ================ Write file with C program.
mv -f hello.c hello.c~
rm -f hello.c
echo ā€™#include <stdio.h>ā€™>>hello.c
echo ā€™int main(int argc, char **argv)ā€™>>hello.c
echo ā€™{ā€™>>hello.c
echo ā€™ printf("hello world\n");ā€™>>hello.c
echo ā€™ return 0;ā€™>>hello.c
echo ā€™}ā€™>>hello.c
cc -c hello.c
cc -o hello hello.o
hello
rm -f hello
rm -f hello.c
rm -f hello.o
rm -f my-batch
When run, my-batch prints:
bash$ my-batch
mv: hello.c: No such file or directory
hello world
4.5 HTML
(require ā€™html-form)
Chapter 4: Textual Conversion Packages 70
[Function]html:atval txt
Returns a string with character substitutions appropriate to send txt as an attribute-
value.
[Function]html:plain txt
Returns a string with character substitutions appropriate to send txt as an plain-text.
[Function]html:meta name content
Returns a tag of meta-information suitable for passing as the third argument to
html:head. The tag produced is ā€˜<META NAME="name" CONTENT="content">ā€™. The
string or symbol name can be ā€˜authorā€™, ā€˜copyrightā€™, ā€˜keywordsā€™, ā€˜descriptionā€™,
ā€˜dateā€™, ā€˜robotsā€™, . . . .
[Function]html:http-equiv name content
Returns a tag of HTTP information suitable for passing as the third argument to
html:head. The tag produced is ā€˜<META HTTP-EQUIV="name" CONTENT="content">ā€™.
The string or symbol name can be ā€˜Expiresā€™, ā€˜PICS-Labelā€™, ā€˜Content-Typeā€™,
ā€˜Refreshā€™, . . . .
[Function]html:meta-refresh delay uri
[Function]html:meta-refresh delay
Returns a tag suitable for passing as the third argument to html:head. If uri argu-
ment is supplied, then delay seconds after displaying the page with this tag, Netscape
or IE browsers will fetch and display uri. Otherwise, delay seconds after displaying
the page with this tag, Netscape or IE browsers will fetch and redisplay this page.
[Function]html:head title backlink tags . . .
[Function]html:head title backlink
[Function]html:head title
Returns header string for an HTML page named title. If backlink is a string, it is
used verbatim between the ā€˜H1ā€™ tags; otherwise title is used. If string arguments tags
... are supplied, then they are included verbatim within the <HEAD> section.
[Function]html:body body . . .
Returns HTML string to end a page.
[Function]html:pre line1 line . . .
Returns the strings line1, lines as PREformmated plain text (rendered in ļ¬xed-width
font). Newlines are inserted between line1, lines. HTML tags (ā€˜<tag>ā€™) within lines
will be visible verbatim.
[Function]html:comment line1 line . . .
Returns the strings line1 as HTML comments.
4.6 HTML Forms
[Function]html:form method action body . . .
The symbol method is either get, head, post, put, or delete. The strings body
form the body of the form. html:form returns the HTML form.
Chapter 4: Textual Conversion Packages 71
[Function]html:hidden name value
Returns HTML string which will cause name=value in form.
[Function]html:checkbox pname default
Returns HTML string for check box.
[Function]html:text pname default size . . .
Returns HTML string for one-line text box.
[Function]html:text-area pname default-list
Returns HTML string for multi-line text box.
[Function]html:select pname arity default-list foreign-values
Returns HTML string for pull-down menu selector.
[Function]html:buttons pname arity default-list foreign-values
Returns HTML string for any-of selector.
[Function]form:submit submit-label command
[Function]form:submit submit-label
The string or symbol submit-label appears on the button which submits the form.
If the optional second argument command is given, then *command*=command and
*button*=submit-label are set in the query. Otherwise, *command*=submit-label
is set in the query.
[Function]form:image submit-label image-src
The image-src appears on the button which submits the form.
[Function]form:reset
Returns a string which generates a reset button.
[Function]form:element pname arity default-list foreign-values
Returns a string which generates an INPUT element for the ļ¬eld named pname. The
element appears in the created form with its representation determined by its arity
and domain. For domains which are foreign-keys:
single select menu
optional select menu
nary check boxes
nary1 check boxes
If the foreign-key table has a ļ¬eld named ā€˜visible-nameā€™, then the contents of that
ļ¬eld are the names visible to the user for those choices. Otherwise, the foreign-key
itself is visible.
For other types of domains:
single text area
optional text area
Chapter 4: Textual Conversion Packages 72
boolean check box
nary text area
nary1 text area
[Function]form:delimited pname doc aliat arity default-list foreign-values
Returns a HTML string for a form element embedded in a line of a delimited list.
Apply map form:delimited to the list returned by command->p-specs.
[Function]html:delimited-list row . . .
Wraps its arguments with delimited-list (ā€˜DLā€™ command.
[Function]get-foreign-choices tab
Returns a list of the ā€˜visible-nameā€™ or ļ¬rst ļ¬elds of table tab.
[Function]command->p-specs rdb command-table command
The symbol command-table names a command table in the rdb relational database.
The symbol command names a key in command-table.
command->p-specs returns a list of lists of pname, doc, aliat, arity, default-list, and
foreign-values. The returned list has one element for each parameter of command
command.
This example demonstrates how to create a HTML-form for the ā€˜buildā€™ command.
(require (in-vicinity (implementation-vicinity) "build.scm"))
(call-with-output-file "buildscm.html"
(lambda (port)
(display
(string-append
(html:head ā€™commands)
(html:body
(sprintf #f "<H2>%s:</H2><BLOCKQUOTE>%s</BLOCKQUOTE>\\n"
(html:plain ā€™build)
(html:plain ((comtab ā€™get ā€™documentation) ā€™build)))
(html:form
ā€™post
(or "http://localhost:8081/buildscm" "/cgi-bin/build.cgi")
(apply html:delimited-list
(apply map form:delimited
(command->p-specs build ā€™*commands* ā€™build)))
(form:submit ā€™build)
(form:reset))))
port)))
4.7 HTML Tables
(require ā€™db->html)
[Function]html:table options row . . .
[Function]html:caption caption align
Chapter 4: Textual Conversion Packages 73
[Function]html:caption caption
align can be ā€˜top ā€™ or ā€˜bottomā€™.
[Function]html:heading columns
Outputs a heading row for the currently-started table.
[Function]html:href-heading columns uris
Outputs a heading row with column-names columns linked to URIs uris.
[Function]html:linked-row-converter k foreigns
The positive integer k is the primary-key-limit (number of primary-keys) of the table.
foreigns is a list of the ļ¬lenames of foreign-key ļ¬eld pages and #f for non foreign-key
ļ¬elds.
html:linked-row-converter returns a procedure taking a row for its single argu-
ment. This returned procedure returns the html string for that table row.
[Function]table-name->filename table-name
Returns the symbol table-name converted to a ļ¬lename.
[Function]table->linked-html caption db table-name match-key1 . . .
Returns HTML string for db table table-name chopped into 50-row HTML tables.
Every foreign-key value is linked to the page (of the table) deļ¬ning that key.
The optional match-key1 . . . arguments restrict actions to a subset of the table. See
Section 6.1.2 [Table Operations], page 165.
[Function]table->linked-page db table-name index-ļ¬lename arg . . .
Returns a complete HTML page. The string index-ļ¬lename names the page which
refers to this one.
The optional args . . . arguments restrict actions to a subset of the table. See
Section 6.1.2 [Table Operations], page 165.
[Function]catalog->html db caption arg . . .
Returns HTML string for the catalog table of db.
4.7.1 HTML editing tables
A client can modify one row of an editable table at a time. For any change submitted, these
routines check if that row has been modiļ¬ed during the time the user has been editing the
form. If so, an error page results.
The behavior of edited rows is:
ā€¢ If no ļ¬elds are changed, then no change is made to the table.
ā€¢ If the primary keys equal null-keys (parameter defaults), and no other user has modiļ¬ed
that row, then that row is deleted.
ā€¢ If only primary keys are changed, there are non-key ļ¬elds, and no row with the new
keys is in the table, then the old row is deleted and one with the new keys is inserted.
ā€¢ If only non-key ļ¬elds are changed, and that row has not been modiļ¬ed by another user,
then the row is changed to reļ¬‚ect the ļ¬elds.
Chapter 4: Textual Conversion Packages 74
ā€¢ If both keys and non-key ļ¬elds are changed, and no row with the new keys is in the
table, then a row is created with the new keys and ļ¬elds.
ā€¢ If ļ¬elds are changed, all ļ¬elds are primary keys, and no row with the new keys is in
the table, then a row is created with the new keys.
After any change to the table, a sync-database of the database is performed.
[Function]command:modify-table table-name null-keys update delete retrieve
[Function]command:modify-table table-name null-keys update delete
[Function]command:modify-table table-name null-keys update
[Function]command:modify-table table-name null-keys
Returns procedure (of db) which returns procedure to modify row of table-name. null-
keys is the list of null keys indicating the row is to be deleted when any matches its
corresponding primary key. Optional arguments update, delete, and retrieve default
to the row:update, row:delete, and row:retrieve of table-name in db.
[Function]command:make-editable-table rdb table-name arg . . .
Given table-name in rdb, creates parameter and *command* tables for editing one row
of table-name at a time. command:make-editable-table returns a procedure taking
a row argument which returns the HTML string for editing that row.
Optional args are expressions (lists) added to the call to command:modify-table.
The domain name of a column determines the expected arity of the data stored in
that column. Domain names ending in:
ā€˜*ā€™ have arity ā€˜naryā€™;
ā€˜+ā€™ have arity ā€˜nary1ā€™.
[Function]html:editable-row-converter k names edit-point edit-converter
The positive integer k is the primary-key-limit (number of primary-keys) of the table.
names is a list of the ļ¬eld-names. edit-point is the list of primary-keys denoting the
row to edit (or #f). edit-converter is the procedure called with k, names, and the
row to edit.
html:editable-row-converter returns a procedure taking a row for its single argu-
ment. This returned procedure returns the html string for that table row.
Each HTML table constructed using html:editable-row-converter has ļ¬rst k ļ¬elds
(typically the primary key ļ¬elds) of each row linked to a text encoding of these ļ¬elds
(the result of calling row->anchor). The page so referenced typically allows the user
to edit ļ¬elds of that row.
4.7.2 HTML databases
[Function]db->html-files db dir index-ļ¬lename caption
db must be a relational database. dir must be #f or a non-empty string naming an
existing sub-directory of the current directory.
db->html-files creates an html page for each table in the database db in the sub-
directory named dir, or the current directory if dir is #f. The top level page with the
catalog of tables (captioned caption) is written to a ļ¬le named index-ļ¬lename.
Chapter 4: Textual Conversion Packages 75
[Function]db->html-directory db dir index-ļ¬lename
[Function]db->html-directory db dir
db must be a relational database. dir must be a non-empty string naming an existing
sub-directory of the current directory or one to be created. The optional string index-
ļ¬lename names the ļ¬lename of the top page, which defaults to index.html.
db->html-directory creates sub-directory dir if neccessary, and calls (db->html-
files db dir index-filename dir). The ā€˜file:ā€™ URI of index-ļ¬lename is returned.
[Function]db->netscape db dir index-ļ¬lename
[Function]db->netscape db dir
db->netscape is just like db->html-directory, but calls browse-url with the uri
for the top page after the pages are created.
4.8 HTTP and CGI
(require ā€™http) or (require ā€™cgi)
[Function]http:header alist
Returns a string containing lines for each element of alist; the car of which is followed
by ā€˜: ā€™, then the cdr.
[Function]http:content alist body . . .
Returns the concatenation of strings body with the (http:header alist) and the
ā€˜Content-Lengthā€™ prepended.
[Variable]*http:byline*
String appearing at the bottom of error pages.
[Function]http:error-page status-code reason-phrase html-string . . .
status-code and reason-phrase should be an integer and string as speciļ¬ed in RFC
2068. The returned page (string) will show the status-code and reason-phrase and
any additional html-strings . . .; with *http:byline* or SLIBā€™s default at the bottom.
[Function]http:forwarding-page title dly uri html-string . . .
The string or symbol title is the page title. dly is a non-negative integer. The html-
strings . . . are typically used to explain to the user why this page is being forwarded.
http:forwarding-page returns an HTML string for a page which automatically for-
wards to uri after dly seconds. The returned page (string) contains any html-strings
. . . followed by a manual link to uri, in case the browser does not forward automati-
cally.
[Function]http:serve-query serve-proc input-port output-port
reads the URI and query-string from input-port. If the query is a valid ā€˜"POST"ā€™
or ā€˜"GET"ā€™ query, then http:serve-query calls serve-proc with three arguments,
the request-line, query-string, and header-alist. Otherwise, http:serve-query calls
serve-proc with the request-line, #f, and header-alist.
If serve-proc returns a string, it is sent to output-port. If serve-proc returns a list
whose ļ¬rst element is an integer, then an error page with the status integer which
Chapter 4: Textual Conversion Packages 76
is the ļ¬rst element of the list and strings from the list. If serve-proc returns a list
whose ļ¬rst element isnā€™t an number, then an error page with the status code 500 and
strings from the list. If serve-proc returns #f, then a ā€˜Bad Requestā€™ (400) page is sent
to output-port.
Otherwise, http:serve-query replies (to output-port) with appropriate HTML de-
scribing the problem.
This example services HTTP queries from port-number:
(define socket (make-stream-socket AF_INET 0))
(and (socket:bind socket port-number) ; AF_INET INADDR_ANY
(socket:listen socket 10) ; Queue up to 10 requests.
(dynamic-wind
(lambda () #f)
(lambda ()
(do ((port (socket:accept socket) (socket:accept socket)))
(#f)
(let ((iport (duplicate-port port "r"))
(oport (duplicate-port port "w")))
(http:serve-query build:serve iport oport)
(close-port iport)
(close-port oport))
(close-port port)))
(lambda () (close-port socket))))
[Function]cgi:serve-query serve-proc
reads the URI and query-string from (current-input-port). If the query is a valid
ā€˜"POST"ā€™ or ā€˜"GET"ā€™ query, then cgi:serve-query calls serve-proc with three argu-
ments, the request-line, query-string, and header-alist. Otherwise, cgi:serve-query
calls serve-proc with the request-line, #f, and header-alist.
If serve-proc returns a string, it is sent to (current-ouput-port). If serve-proc
returns a list whose ļ¬rst element is an integer, then an error page with the status
integer which is the ļ¬rst element of the list and strings from the list. If serve-proc
returns a list whose ļ¬rst element isnā€™t an number, then an error page with the status
code 500 and strings from the list. If serve-proc returns #f, then a ā€˜Bad Requestā€™
(400) page is sent to (current-ouput-port).
Otherwise, cgi:serve-query replies (to (current-output-port)) with appropriate
HTML describing the problem.
[Function]make-query-alist-command-server rdb command-table
[Function]make-query-alist-command-server rdb command-table #t
Returns a procedure of one argument. When that procedure is called with a query-
alist (as returned by uri:decode-query, the value of the ā€˜*command*ā€™ association will
be the command invoked in command-table. If ā€˜*command*ā€™ is not in the query-alist
then the value of ā€˜*suggest*ā€™ is tried. If neither name is in the query-alist, then the
literal value ā€˜*default*ā€™ is tried in command-table.
Chapter 4: Textual Conversion Packages 77
If optional third argument is non-false, then the command is called with just the
parameter-list; otherwise, command is called with the arguments described in its
table.
4.9 Parsing HTML
(require ā€™html-for-each)
[Function]html-for-each ļ¬le word-proc markup-proc white-proc newline-proc
ļ¬le is an input port or a string naming an existing ļ¬le containing HTML text. word-
proc is a procedure of one argument or #f. markup-proc is a procedure of one
argument or #f. white-proc is a procedure of one argument or #f. newline-proc is a
procedure of no arguments or #f.
html-for-each opens and reads characters from port ļ¬le or the ļ¬le named by string
ļ¬le. Sequential groups of characters are assembled into strings which are either
ā€¢ enclosed by ā€˜<ā€™ and ā€˜>ā€™ (hypertext markups or comments);
ā€¢ end-of-line;
ā€¢ whitespace; or
ā€¢ none of the above (words).
Procedures are called according to these distinctions in order of the stringā€™s occurrence
in ļ¬le.
newline-proc is called with no arguments for end-of-line not within a markup or com-
ment.
white-proc is called with strings of non-newline whitespace.
markup-proc is called with hypertext markup strings (including ā€˜<ā€™ and ā€˜>ā€™).
word-proc is called with the remaining strings.
html-for-each returns an unspeciļ¬ed value.
[Function]html:read-title ļ¬le limit
[Function]html:read-title ļ¬le
ļ¬le is an input port or a string naming an existing ļ¬le containing HTML text. If
supplied, limit must be an integer. limit defaults to 1000.
html:read-title opens and reads HTML from port ļ¬le or the ļ¬le named by string
ļ¬le, until reaching the (mandatory) ā€˜TITLEā€™ ļ¬eld. html:read-title returns the title
string with adjacent whitespaces collapsed to one space. html:read-title returns
#f if the title ļ¬eld is empty, absent, if the ļ¬rst character read from ļ¬le is not ā€˜#\<ā€™,
or if the end of title is not found within the ļ¬rst (approximately) limit words.
[Function]htm-fields htm
htm is a hypertext markup string.
If htm is a (hypertext) comment or DTD, then htm-fields returns #f. Otherwise
htm-fields returns the hypertext element string consed onto an association list of the
attribute name-symbols and values. If the tag ends with "/>", then "/" is appended to
the hypertext element string. The name-symbols are created by string-ci->symbol.
Each value is a string; or #t if the name had no value assigned within the markup.
Chapter 4: Textual Conversion Packages 78
4.10 URI
(require ā€™uri)
Implements Uniform Resource Identiļ¬ers (URI) as described in RFC 2396.
[Function]make-uri
[Function]make-uri fragment
[Function]make-uri query fragment
[Function]make-uri path query fragment
[Function]make-uri authority path query fragment
[Function]make-uri scheme authority path query fragment
Returns a Uniform Resource Identiļ¬er string from component arguments.
[Function]uri:make-path path
Returns a URI string combining the components of list path.
[Function]html:anchor name
Returns a string which deļ¬nes this location in the (HTML) ļ¬le as name. The hyper-
text ā€˜<A HREF="#name">ā€™ will link to this point.
(html:anchor "(section 7)")
ā‡’
"<A NAME=\"(section%207)\"></A>"
[Function]html:link uri highlighted
Returns a string which links the highlighted text to uri.
(html:link (make-uri "(section 7)") "section 7")
ā‡’
"<A HREF=\"#(section%207)\">section 7</A>"
[Function]html:base uri
Returns a string specifying the base uri of a document, for inclusion in the HEAD of
the document (see Section 4.5 [HTML], page 69).
[Function]html:isindex prompt
Returns a string specifying the search prompt of a document, for inclusion in the
HEAD of the document (see Section 4.5 [HTML], page 69).
[Function]uri->tree uri-reference base-tree
[Function]uri->tree uri-reference
Returns a list of 5 elements corresponding to the parts (scheme authority path query
fragment) of string uri-reference. Elements corresponding to absent parts are #f.
The path is a list of strings. If the ļ¬rst string is empty, then the path is absolute;
otherwise relative. The optional base-tree is a tree as returned by uri->tree; and is
used as the base address for relative URIs.
If the authority component is a Server-based Naming Authority, then it is a list of
the userinfo, host, and port strings (or #f). For other types of authority components
the authority will be a string.
(uri->tree "http://www.ics.uci.edu/pub/ietf/uri/#Related")
Chapter 4: Textual Conversion Packages 79
ā‡’
(http "www.ics.uci.edu" ("" "pub" "ietf" "uri" "") #f "Related")
[Function]uri:split-fields txt chr
Returns a list of txt split at each occurrence of chr. chr does not appear in the
returned list of strings.
[Function]uri:decode-query query-string
Converts a URI encoded query-string to a query-alist.
uric: preļ¬xes indicate procedures dealing with URI-components.
[Function]uric:encode uri-component allows
Returns a copy of the string uri-component in which all unsafe octets (as deļ¬ned
in RFC 2396) have been ā€˜%ā€™ escaped. uric:decode decodes strings encoded by
uric:encode.
[Function]uric:decode uri-component
Returns a copy of the string uri-component in which each ā€˜%ā€™ escaped characters in
uri-component is replaced with the character it encodes. This routine is useful for
showing URI contents on error pages.
[Function]uri:path->keys path-list ptypes
path-list is a path-list as returned by uri:split-fields. uri:path->keys returns
a list of items returned by uri:decode-path, coerced to types ptypes.
File-system Locators and Predicates
[Function]path->uri path
Returns a URI-string for path on the local host.
[Function]absolute-uri? str
Returns #t if str is an absolute-URI as indicated by a syntactically valid (per RFC
2396) scheme; otherwise returns #f.
[Function]absolute-path? ļ¬le-name
Returns #t if ļ¬le-name is a fully speciļ¬ed pathname (does not depend on the current
working directory); otherwise returns #f.
[Function]null-directory? str
Returns #t if changing directory to str would leave the current directory unchanged;
otherwise returns #f.
[Function]glob-pattern? str
Returns #t if the string str contains characters used for specifying glob patterns,
namely ā€˜*ā€™, ā€˜?ā€™, or ā€˜[ā€™.
Before RFC 2396, the File Transfer Protocol (FTP) served a similar purpose.
Chapter 4: Textual Conversion Packages 80
[Function]parse-ftp-address uri
Returns a list of the decoded FTP uri; or #f if indecipherable. FTP Uniform Resource
Locator, ange-ftp, and getit formats are handled. The returned list has four elements
which are strings or #f:
0. username
1. password
2. remote-site
3. remote-directory
4.11 Parsing XML
(require ā€™xml-parse) or (require ā€™ssax)
The XML standard document referred to in this module is
http://www.w3.org/TR/1998/REC-xml-19980210.html.
The present frameworks fully supports the XML Namespaces Recommendation
http://www.w3.org/TR/REC-xml-names.
4.11.1 String Glue
[Function]ssax:reverse-collect-str list-of-frags
Given the list of fragments (some of which are text strings), reverse the list and
concatenate adjacent text strings. If LIST-OF-FRAGS has zero or one element, the
result of the procedure is equal? to its argument.
[Function]ssax:reverse-collect-str-drop-ws list-of-frags
Given the list of fragments (some of which are text strings), reverse the list and
concatenate adjacent text strings while dropping "unsigniļ¬cant" whitespace, that is,
whitespace in front, behind and between elements. The whitespace that is included
in character data is not aļ¬€ected.
Use this procedure to "intelligently" drop "insigniļ¬cant" whitespace in the parsed
SXML. If the strict compliance with the XML Recommendation regarding the white-
space is desired, use the ssax:reverse-collect-str procedure instead.
4.11.2 Character and Token Functions
The following functions either skip, or build and return tokens, according to inclusion or
delimiting semantics. The list of characters to expect, include, or to break at may vary
from one invocation of a function to another. This allows the functions to easily parse even
context-sensitive languages.
Exceptions are mentioned speciļ¬cally. The list of expected characters (characters to
skip until, or break-characters) may include an EOF "character", which is coded as symbol
*eof*
The input stream to parse is speciļ¬ed as a PORT, which is the last argument.
Chapter 4: Textual Conversion Packages 81
[Function]ssax:assert-current-char char-list string port
Reads a character from the port and looks it up in the char-list of expected characters.
If the read character was found among expected, it is returned. Otherwise, the
procedure writes a message using string as a comment and quits.
[Function]ssax:skip-while char-list port
Reads characters from the port and disregards them, as long as they are mentioned
in the char-list. The ļ¬rst character (which may be EOF) peeked from the stream that
is not a member of the char-list is returned.
[Function]ssax:init-buffer
Returns an initial buļ¬€er for ssax:next-token* procedures. ssax:init-buffer may
allocate a new buļ¬€er at each invocation.
[Function]ssax:next-token preļ¬x-char-list break-char-list comment-string port
Skips any number of the preļ¬x characters (members of the preļ¬x-char-list), if any,
and reads the sequence of characters up to (but not including) a break character, one
of the break-char-list.
The string of characters thus read is returned. The break character is left on the
input stream. break-char-list may include the symbol *eof*; otherwise, EOF is fatal,
generating an error message including a speciļ¬ed comment-string.
ssax:next-token-of is similar to ssax:next-token except that it implements an inclusion
rather than delimiting semantics.
[Function]ssax:next-token-of inc-charset port
Reads characters from the port that belong to the list of characters inc-charset. The
reading stops at the ļ¬rst character which is not a member of the set. This character
is left on the stream. All the read characters are returned in a string.
[Function]ssax:next-token-of pred port
Reads characters from the port for which pred (a procedure of one argument) returns
non-#f. The reading stops at the ļ¬rst character for which pred returns #f. That
character is left on the stream. All the results of evaluating of pred up to #f are
returned in a string.
pred is a procedure that takes one argument (a character or the EOF object) and
returns a character or #f. The returned character does not have to be the same as
the input argument to the pred. For example,
(ssax:next-token-of (lambda (c)
(cond ((eof-object? c) #f)
((char-alphabetic? c) (char-downcase c))
(else #f)))
(current-input-port))
will try to read an alphabetic token from the current input port, and return it in
lower case.
Chapter 4: Textual Conversion Packages 82
[Function]ssax:read-string len port
Reads len characters from the port, and returns them in a string. If EOF is encoun-
tered before len characters are read, a shorter string will be returned.
4.11.3 Data Types
TAG-KIND
A symbol ā€˜STARTā€™, ā€˜ENDā€™, ā€˜PIā€™, ā€˜DECLā€™, ā€˜COMMENTā€™, ā€˜CDSECTā€™, or ā€˜ENTITY-REFā€™ that
identiļ¬es a markup token
UNRES-NAME
a name (called GI in the XML Recommendation) as given in an XML document
for a markup token: start-tag, PI target, attribute name. If a GI is an NCName,
UNRES-NAME is this NCName converted into a Scheme symbol. If a GI is a
QName, ā€˜UNRES-NAMEā€™ is a pair of symbols: (PREFIX . LOCALPART).
RES-NAME
An expanded name, a resolved version of an ā€˜UNRES-NAMEā€™. For an element or
an attribute name with a non-empty namespace URI, ā€˜RES-NAMEā€™ is a pair of
symbols, (URI-SYMB . LOCALPART). Otherwise, itā€™s a single symbol.
ELEM-CONTENT-MODEL
A symbol:
ā€˜ANYā€™ anything goes, expect an END tag.
ā€˜EMPTY-TAGā€™
no content, and no END-tag is coming
ā€˜EMPTYā€™ no content, expect the END-tag as the next token
ā€˜PCDATAā€™ expect character data only, and no children elements
ā€˜MIXEDā€™
ā€˜ELEM-CONTENTā€™
URI-SYMB
A symbol representing a namespace URI ā€“ or other symbol chosen by the user
to represent URI. In the former case, URI-SYMB is created by %-quoting of bad
URI characters and converting the resulting string into a symbol.
NAMESPACES
A list representing namespaces in eļ¬€ect. An element of the list has one of the
following forms:
(prefix uri-symb . uri-symb) or
(prefix user-prefix . uri-symb)
user-preļ¬x is a symbol chosen by the user to represent the URI.
(#f user-prefix . uri-symb)
Speciļ¬cation of the user-chosen preļ¬x and a URI-SYMBOL.
(*DEFAULT* user-prefix . uri-symb)
Declaration of the default namespace
Chapter 4: Textual Conversion Packages 83
(*DEFAULT* #f . #f)
Un-declaration of the default namespace. This notation represents
overriding of the previous declaration
A NAMESPACES list may contain several elements for the same preļ¬x. The
one closest to the beginning of the list takes eļ¬€ect.
ATTLIST
An ordered collection of (NAME . VALUE) pairs, where NAME is a RES-
NAME or an UNRES-NAME. The collection is an ADT.
STR-HANDLER
A procedure of three arguments: string1 string2 seed returning a new seed.
The procedure is supposed to handle a chunk of character data string1 followed
by a chunk of character data string2. string2 is a short string, often ā€˜"\n"ā€™ and
even ā€˜""ā€™.
ENTITIES An assoc list of pairs:
(named-entity-name . named-entity-body)
where named-entity-name is a symbol under which the entity was declared,
named-entity-body is either a string, or (for an external entity) a thunk that
will return an input port (from which the entity can be read). named-entity-
body may also be #f. This is an indication that a named-entity-name is cur-
rently being expanded. A reference to this named-entity-name will be an error:
violation of the WFC nonrecursion.
XML-TOKEN
This record represents a markup, which is, according to the XML Recommen-
dation, "takes the form of start-tags, end-tags, empty-element tags, entity ref-
erences, character references, comments, CDATA section delimiters, document
type declarations, and processing instructions."
kind a TAG-KIND
head an UNRES-NAME. For XML-TOKENs of kinds ā€™COMMENT and
ā€™CDSECT, the head is #f.
For example,
<P> => kind=START, head=P
</P> => kind=END, head=P
<BR/> => kind=EMPTY-EL, head=BR
<!DOCTYPE OMF ...> => kind=DECL, head=DOCTYPE
<?xml version="1.0"?> => kind=PI, head=xml
&my-ent; => kind=ENTITY-REF, head=my-ent
Character references are not represented by xml-tokens as these references are
transparently resolved into the corresponding characters.
XML-DECL
The record represents a datatype of an XML document: the list of declared
elements and their attributes, declared notations, list of replacement strings or
loading procedures for parsed general entities, etc. Normally an XML-DECL
Chapter 4: Textual Conversion Packages 84
record is created from a DTD or an XML Schema, although it can be created
and ļ¬lled in in many other ways (e.g., loaded from a ļ¬le).
elems an (assoc) list of decl-elem or #f. The latter instructs the parser
to do no validation of elements and attributes.
decl-elem declaration of one element:
(elem-name elem-content decl-attrs)
elem-name is an UNRES-NAME for the element.
elem-content is an ELEM-CONTENT-MODEL.
decl-attrs is an ATTLIST, of (attr-name . value) associations.
This element can declare a user procedure to handle parsing of an
element (e.g., to do a custom validation, or to build a hash of IDs
as theyā€™re encountered).
decl-attr an element of an ATTLIST, declaration of one attribute:
(attr-name content-type use-type default-value)
attr-name is an UNRES-NAME for the declared attribute.
content-type is a symbol: CDATA, NMTOKEN, NMTOKENS, . . . or a list
of strings for the enumerated type.
use-type is a symbol: REQUIRED, IMPLIED, or FIXED.
default-value is a string for the default value, or #f if not given.
4.11.4 Low-Level Parsers and Scanners
These procedures deal with primitive lexical units (Names, whitespaces, tags) and with
pieces of more generic productions. Most of these parsers must be called in appropriate
context. For example, ssax:complete-start-tag must be called only when the start-tag
has been detected and its GI has been read.
[Function]ssax:skip-s port
Skip the S (whitespace) production as deļ¬ned by
[3] S ::= (#x20 | #x09 | #x0D | #x0A)
ssax:skip-s returns the ļ¬rst not-whitespace character it encounters while scanning
the port. This character is left on the input stream.
[Function]ssax:read-ncname port
Read a NCName starting from the current position in the port and return it as a
symbol.
[4] NameChar ::= Letter | Digit | ā€™.ā€™ | ā€™-ā€™ | ā€™_ā€™ | ā€™:ā€™
| CombiningChar | Extender
[5] Name ::= (Letter | ā€™_ā€™ | ā€™:ā€™) (NameChar)*
This code supports the XML Namespace Recommendation REC-xml-names, which
modiļ¬es the above productions as follows:
[4] NCNameChar ::= Letter | Digit | ā€™.ā€™ | ā€™-ā€™ | ā€™_ā€™
| CombiningChar | Extender
Chapter 4: Textual Conversion Packages 85
[5] NCName ::= (Letter | ā€™_ā€™) (NCNameChar)*
As the Rec-xml-names says,
"An XML document conforms to this speciļ¬cation if all other tokens
[other than element types and attribute names] in the document which
are required, for XML conformance, to match the XML production for
Name, match this speciļ¬cationā€™s production for NCName."
Element types and attribute names must match the production QName, deļ¬ned be-
low.
[Function]ssax:read-qname port
Read a (namespace-) Qualiļ¬ed Name, QName, from the current position in port; and
return an UNRES-NAME.
From REC-xml-names:
[6] QName ::= (Prefix ā€™:ā€™)? LocalPart
[7] Prefix ::= NCName
[8] LocalPart ::= NCName
[Function]ssax:read-markup-token port
This procedure starts parsing of a markup token. The current position in the stream
must be ā€˜<ā€™. This procedure scans enough of the input stream to ļ¬gure out what kind
of a markup token it is seeing. The procedure returns an XML-TOKEN structure
describing the token. Note, generally reading of the current markup is not ļ¬nished!
In particular, no attributes of the start-tag token are scanned.
Hereā€™s a detailed break out of the return values and the position in the PORT when
that particular value is returned:
PI-token
only PI-target is read. To ļ¬nish the Processing-Instruction and disregard
it, call ssax:skip-pi. ssax:read-attributes may be useful as well (for
PIs whose content is attribute-value pairs).
END-token
The end tag is read completely; the current position is right after the
terminating ā€˜>ā€™ character.
COMMENT
is read and skipped completely. The current position is right after ā€˜-->ā€™
that terminates the comment.
CDSECT
The current position is right after ā€˜<!CDATA[ā€™. Use ssax:read-cdata-
body to read the rest.
DECL
We have read the keyword (the one that follows ā€˜<!ā€™) identifying this
declaration markup. The current position is after the keyword (usually a
whitespace character)
Chapter 4: Textual Conversion Packages 86
START-token
We have read the keyword (GI) of this start tag. No attributes are
scanned yet. We donā€™t know if this tag has an empty content either.
Use ssax:complete-start-tag to ļ¬nish parsing of the token.
[Function]ssax:skip-pi port
The current position is inside a PI. Skip till the rest of the PI
[Function]ssax:read-pi-body-as-string port
The current position is right after reading the PITarget. We read the body of PI and
return is as a string. The port will point to the character right after ā€˜?>ā€™ combination
that terminates PI.
[16] PI ::= ā€™<?ā€™ PITarget (S (Char* - (Char* ā€™?>ā€™ Char*)))? ā€™?>ā€™
[Function]ssax:skip-internal-dtd port
The current pos in the port is inside an internal DTD subset (e.g., after reading ā€˜#\[ā€™
that begins an internal DTD subset) Skip until the ā€˜]>ā€™ combination that terminates
this DTD.
[Function]ssax:read-cdata-body port str-handler seed
This procedure must be called after we have read a string ā€˜<![CDATA[ā€™ that begins a
CDATA section. The current position must be the ļ¬rst position of the CDATA body.
This function reads lines of the CDATA body and passes them to a str-handler, a
character data consumer.
str-handler is a procedure taking arguments: string1, string2, and seed. The ļ¬rst
string1 argument to str-handler never contains a newline; the second string2 argu-
ment often will. On the ļ¬rst invocation of str-handler, seed is the one passed to
ssax:read-cdata-body as the third argument. The result of this ļ¬rst invocation
will be passed as the seed argument to the second invocation of the line consumer,
and so on. The result of the last invocation of the str-handler is returned by the
ssax:read-cdata-body. Note a similarity to the fundamental fold iterator.
Within a CDATA section all characters are taken at their face value, with three
exceptions:
ā€¢ CR, LF, and CRLF are treated as line delimiters, and passed as a single
ā€˜#\newlineā€™ to str-handler
ā€¢ ā€˜]]>ā€™ combination is the end of the CDATA section. ā€˜&gt;ā€™ is treated as an
embedded ā€˜>ā€™ character.
ā€¢ ā€˜&lt;ā€™ and ā€˜&amp;ā€™ are not specially recognized (and are not expanded)!
[Function]ssax:read-char-ref port
[66] CharRef ::= ā€™&#ā€™ [0-9]+ ā€™;ā€™
| ā€™&#xā€™ [0-9a-fA-F]+ ā€™;ā€™
This procedure must be called after we we have read ā€˜&#ā€™ that introduces a char
reference. The procedure reads this reference and returns the corresponding char.
The current position in PORT will be after the ā€˜;ā€™ that terminates the char reference.
Chapter 4: Textual Conversion Packages 87
Faults detected:
WFC: XML-Spec.html#wf-Legalchar
According to Section 4.1 Character and Entity References of the XML Recommen-
dation:
"[Deļ¬nition: A character reference refers to a speciļ¬c character in the
ISO/IEC 10646 character set, for example one not directly accessible
from available input devices.]"
[Function]ssax:handle-parsed-entity port name entities content-handler
str-handler seed
Expands and handles a parsed-entity reference.
name is a symbol, the name of the parsed entity to expand. content-handler is a
procedure of arguments port, entities, and seed that returns a seed. str-handler is
called if the entity in question is a pre-declared entity.
ssax:handle-parsed-entity returns the result returned by content-handler or str-
handler.
Faults detected:
WFC: XML-Spec.html#wf-entdeclared
WFC: XML-Spec.html#norecursion
[Function]attlist-add attlist name-value
Add a name-value pair to the existing attlist, preserving its sorted ascending order;
and return the new list. Return #f if a pair with the same name already exists in
attlist
[Function]attlist-remove-top attlist
Given an non-null attlist, return a pair of values: the top and the rest.
[Function]ssax:read-attributes port entities
This procedure reads and parses a production Attribute.
[41] Attribute ::= Name Eq AttValue
[10] AttValue ::= ā€™"ā€™ ([^<&"] | Reference)* ā€™"ā€™
| "ā€™" ([^<&ā€™] | Reference)* "ā€™"
[25] Eq ::= S? ā€™=ā€™ S?
The procedure returns an ATTLIST, of Name (as UNRES-NAME), Value (as string)
pairs. The current character on the port is a non-whitespace character that is not an
NCName-starting character.
Note the following rules to keep in mind when reading an AttValue:
Before the value of an attribute is passed to the application or checked
for validity, the XML processor must normalize it as follows:
ā€¢ A character reference is processed by appending the referenced char-
acter to the attribute value.
ā€¢ An entity reference is processed by recursively processing the replace-
ment text of the entity. The named entities ā€˜ampā€™, ā€˜ltā€™, ā€˜gtā€™, ā€˜quotā€™,
and ā€˜aposā€™ are pre-declared.
Chapter 4: Textual Conversion Packages 88
ā€¢ A whitespace character (#x20, #x0D, #x0A, #x09) is processed by
appending #x20 to the normalized value, except that only a single
#x20 is appended for a "#x0D#x0A" sequence that is part of an
external parsed entity or the literal entity value of an internal parsed
entity.
ā€¢ Other characters are processed by appending them to the normalized
value.
Faults detected:
WFC: XML-Spec.html#CleanAttrVals
WFC: XML-Spec.html#uniqattspec
[Function]ssax:resolve-name port unres-name namespaces apply-default-ns?
Convert an unres-name to a RES-NAME, given the appropriate namespaces decla-
rations. The last parameter, apply-default-ns?, determines if the default namespace
applies (for instance, it does not for attribute names).
Per REC-xml-names/#nsc-NSDeclared, the "xml" preļ¬x is considered pre-declared
and bound to the namespace name "http://www.w3.org/XML/1998/namespace".
ssax:resolve-name tests for the namespace constraints:
http://www.w3.org/TR/REC-xml-names/#nsc-NSDeclared
[Function]ssax:complete-start-tag tag port elems entities namespaces
Complete parsing of a start-tag markup. ssax:complete-start-tag must be called
after the start tag token has been read. tag is an UNRES-NAME. elems is an instance
of the ELEMS slot of XML-DECL; it can be #f to tell the function to do no validation
of elements and their attributes.
ssax:complete-start-tag returns several values:
ā€¢ ELEM-GI: a RES-NAME.
ā€¢ ATTRIBUTES: elementā€™s attributes, an ATTLIST of (RES-NAME . STRING)
pairs. The list does NOT include xmlns attributes.
ā€¢ NAMESPACES: the input list of namespaces amended with namespace (re-
)declarations contained within the start-tag under parsing
ā€¢ ELEM-CONTENT-MODEL
On exit, the current position in port will be the ļ¬rst character after ā€˜>ā€™ that terminates
the start-tag markup.
Faults detected:
VC: XML-Spec.html#enum
VC: XML-Spec.html#RequiredAttr
VC: XML-Spec.html#FixedAttr
VC: XML-Spec.html#ValueType
WFC: XML-Spec.html#uniqattspec (after namespaces preļ¬xes are resolved)
VC: XML-Spec.html#elementvalid
WFC: REC-xml-names/#dt-NSName
Chapter 4: Textual Conversion Packages 89
Note: although XML Recommendation does not explicitly say it, xmlns and xmlns:
attributes donā€™t have to be declared (although they can be declared, to specify their
default value).
[Function]ssax:read-external-id port
Parses an ExternalID production:
[75] ExternalID ::= ā€™SYSTEMā€™ S SystemLiteral
| ā€™PUBLICā€™ S PubidLiteral S SystemLiteral
[11] SystemLiteral ::= (ā€™"ā€™ [^"]* ā€™"ā€™) | ("ā€™" [^ā€™]* "ā€™")
[12] PubidLiteral ::= ā€™"ā€™ PubidChar* ā€™"ā€™
| "ā€™" (PubidChar - "ā€™")* "ā€™"
[13] PubidChar ::= #x20 | #x0D | #x0A | [a-zA-Z0-9]
| [-ā€™()+,./:=?;!*#@$_%]
Call ssax:read-external-id when an ExternalID is expected; that is, the current
character must be either #\S or #\P that starts correspondingly a SYSTEM or
PUBLIC token. ssax:read-external-id returns the SystemLiteral as a string. A
PubidLiteral is disregarded if present.
4.11.5 Mid-Level Parsers and Scanners
These procedures parse productions corresponding to the whole (document) entity or its
higher-level pieces (prolog, root element, etc).
[Function]ssax:scan-misc port
Scan the Misc production in the context:
[1] document ::= prolog element Misc*
[22] prolog ::= XMLDecl? Misc* (doctypedec l Misc*)?
[27] Misc ::= Comment | PI | S
Call ssax:scan-misc in the prolog or epilog contexts. In these contexts, whitespaces
are completely ignored. The return value from ssax:scan-misc is either a PI-token,
a DECL-token, a START token, or *EOF*. Comments are ignored and not reported.
[Function]ssax:read-char-data port expect-eof? str-handler iseed
Read the character content of an XML document or an XML element.
[43] content ::=
(element | CharData | Reference | CDSect | PI | Comment)*
To be more precise, ssax:read-char-data reads CharData, expands CDSect and
character entities, and skips comments. ssax:read-char-data stops at a named
reference, EOF, at the beginning of a PI, or a start/end tag.
expect-eof? is a boolean indicating if EOF is normal; i.e., the character data may be
terminated by the EOF. EOF is normal while processing a parsed entity.
iseed is an argument passed to the ļ¬rst invocation of str-handler.
ssax:read-char-data returns two results: seed and token. The seed is the result of
the last invocation of str-handler, or the original iseed if str-handler was never called.
token can be either an eof-object (this can happen only if expect-eof? was #t), or:
Chapter 4: Textual Conversion Packages 90
ā€¢ an xml-token describing a START tag or an END-tag; For a start token, the
caller has to ļ¬nish reading it.
ā€¢ an xml-token describing the beginning of a PI. Itā€™s up to an application to read
or skip through the rest of this PI;
ā€¢ an xml-token describing a named entity reference.
CDATA sections and character references are expanded inline and never returned.
Comments are silently disregarded.
As the XML Recommendation requires, all whitespace in character data must be
preserved. However, a CR character (#x0D) must be disregarded if it appears before a
LF character (#x0A), or replaced by a #x0A character otherwise. See Secs. 2.10 and
2.11 of the XML Recommendation. See also the canonical XML Recommendation.
[Function]ssax:assert-token token kind gi error-cont
Make sure that token is of anticipated kind and has anticipated gi. Note that the
gi argument may actually be a pair of two symbols, Namespace-URI or the preļ¬x,
and of the localname. If the assertion fails, error-cont is evaluated by passing it three
arguments: token kind gi. The result of error-cont is returned.
4.11.6 High-level Parsers
These procedures are to instantiate a SSAX parser. A user can instantiate the parser to do
the full validation, or no validation, or any particular validation. The user speciļ¬es which
PI he wants to be notiļ¬ed about. The user tells what to do with the parsed character and
element data. The latter handlers determine if the parsing follows a SAX or a DOM model.
[Function]ssax:make-pi-parser my-pi-handlers
Create a parser to parse and process one Processing Element (PI).
my-pi-handlers is an association list of pairs (pi-tag . pi-handler) where pi-tag is
an NCName symbol, the PI target; and pi-handler is a procedure taking arguments
port, pi-tag, and seed.
pi-handler should read the rest of the PI up to and including the combination ā€˜?>ā€™
that terminates the PI. The handler should return a new seed. One of the pi-tags
may be the symbol *DEFAULT*. The corresponding handler will handle PIs that no
other handler will. If the *DEFAULT* pi-tag is not speciļ¬ed, ssax:make-pi-parser
will assume the default handler that skips the body of the PI.
ssax:make-pi-parser returns a procedure of arguments port, pi-tag, and seed; that
will parse the current PI according to my-pi-handlers.
[Function]ssax:make-elem-parser my-new-level-seed my-ļ¬nish-element
my-char-data-handler my-pi-handlers
Create a parser to parse and process one element, including its character content or
children elements. The parser is typically applied to the root element of a document.
my-new-level-seed
is a procedure taking arguments:
elem-gi attributes namespaces expected-content seed
Chapter 4: Textual Conversion Packages 91
where elem-gi is a RES-NAME of the element about to be processed.
my-new-level-seed is to generate the seed to be passed to handlers that
process the content of the element.
my-ļ¬nish-element
is a procedure taking arguments:
elem-gi attributes namespaces parent-seed seed
my-ļ¬nish-element is called when parsing of elem-gi is ļ¬nished. The seed
is the result from the last content parser (or from my-new-level-seed if
the element has the empty content). parent-seed is the same seed as was
passed to my-new-level-seed. my-ļ¬nish-element is to generate a seed that
will be the result of the element parser.
my-char-data-handler
is a STR-HANDLER as described in Data Types above.
my-pi-handlers
is as described for ssax:make-pi-handler above.
The generated parser is a procedure taking arguments:
start-tag-head port elems entities namespaces preserve-ws? seed
The procedure must be called after the start tag token has been read. start-tag-head
is an UNRES-NAME from the start-element tag. ELEMS is an instance of ELEMS
slot of XML-DECL.
Faults detected:
VC: XML-Spec.html#elementvalid
WFC: XML-Spec.html#GIMatch
[Function]ssax:make-parser user-handler-tag user-handler . . .
Create an XML parser, an instance of the XML parsing framework. This will be a
SAX, a DOM, or a specialized parser depending on the supplied user-handlers.
ssax:make-parser takes an even number of arguments; user-handler-tag is a symbol
that identiļ¬es a procedure (or association list for PROCESSING-INSTRUCTIONS) (user-
handler) that follows the tag. Given below are tags and signatures of the correspond-
ing procedures. Not all tags have to be speciļ¬ed. If some are omitted, reasonable
defaults will apply.
ā€˜DOCTYPEā€™ handler-procedure: port docname systemid internal-subset? seed
If internal-subset? is #t, the current position in the port is right after
we have read ā€˜[ā€™ that begins the internal DTD subset. We must ļ¬nish
reading of this subset before we return (or must call skip-internal-dtd
if we arenā€™t interested in reading it). port at exit must be at the ļ¬rst
symbol after the whole DOCTYPE declaration.
The handler-procedure must generate four values:
elems entities namespaces seed
elems is as deļ¬ned for the ELEMS slot of XML-DECL. It may be #f
to switch oļ¬€ validation. namespaces will typically contain user-preļ¬xes
Chapter 4: Textual Conversion Packages 92
for selected uri-symbs. The default handler-procedure skips the internal
subset, if any, and returns (values #f ā€™() ā€™() seed).
ā€˜UNDECL-ROOTā€™
procedure: elem-gi seed
where elem-gi is an UNRES-NAME of the root element. This procedure
is called when an XML document under parsing contains no DOCTYPE
declaration.
The handler-procedure, as a DOCTYPE handler procedure above, must
generate four values:
elems entities namespaces seed
The default handler-procedure returns (values #f ā€™() ā€™() seed)
ā€˜DECL-ROOTā€™
procedure: elem-gi seed
where elem-gi is an UNRES-NAME of the root element. This procedure
is called when an XML document under parsing does contains the DOC-
TYPE declaration. The handler-procedure must generate a new seed
(and verify that the name of the root element matches the doctype, if
the handler so wishes). The default handler-procedure is the identity
function.
ā€˜NEW-LEVEL-SEEDā€™
procedure: see ssax:make-elem-parser, my-new-level-seed
ā€˜FINISH-ELEMENTā€™
procedure: see ssax:make-elem-parser, my-ļ¬nish-element
ā€˜CHAR-DATA-HANDLERā€™
procedure: see ssax:make-elem-parser, my-char-data-handler
ā€˜PROCESSING-INSTRUCTIONSā€™
association list as is passed to ssax:make-pi-parser. The default value
is ā€™()
The generated parser is a procedure of arguments port and seed.
This procedure parses the document prolog and then exits to an element parser (cre-
ated by ssax:make-elem-parser) to handle the rest.
[1] document ::= prolog element Misc*
[22] prolog ::= XMLDecl? Misc* (doctypedec | Misc*)?
[27] Misc ::= Comment | PI | S
[28] doctypedecl ::= ā€™<!DOCTYPEā€™ S Name (S ExternalID)? S?
(ā€™[ā€™ (markupdecl | PEReference | S)* ā€™]ā€™ S?)? ā€™>ā€™
[29] markupdecl ::= elementdecl | AttlistDecl
| EntityDecl
| NotationDecl | PI
| Comment
Chapter 4: Textual Conversion Packages 93
4.11.7 Parsing XML to SXML
[Function]ssax:xml->sxml port namespace-preļ¬x-assig
This is an instance of the SSAX parser that returns an SXML representation of the
XML document to be read from port. namespace-preļ¬x-assig is a list of (user-
prefix . uri-string) that assigns user-preļ¬xes to certain namespaces identiļ¬ed by
particular uri-strings. It may be an empty list. ssax:xml->sxml returns an SXML
tree. The port points out to the ļ¬rst character after the root element.
4.12 Printing Scheme
4.12.1 Generic-Write
(require ā€™generic-write)
generic-write is a procedure that transforms a Scheme data value (or Scheme pro-
gram expression) into its textual representation and prints it. The interface to the procedure
is suļ¬ƒciently general to easily implement other useful formatting procedures such as pretty
printing, output to a string and truncated output.
[Procedure]generic-write obj display? width output
obj Scheme data value to transform.
display? Boolean, controls whether characters and strings are quoted.
width Extended boolean, selects format:
#f single line format
integer > 0
pretty-print (value = max nb of chars per line)
output Procedure of 1 argument of string type, called repeatedly with successive
substrings of the textual representation. This procedure can return #f to
stop the transformation.
The value returned by generic-write is undeļ¬ned.
Examples:
(write obj) ā‰” (generic-write obj #f #f display-string)
(display obj) ā‰” (generic-write obj #t #f display-string)
where
display-string ā‰”
(lambda (s) (for-each write-char (string->list s)) #t)
4.12.2 Object-To-String
(require ā€™object->string)
[Function]object->string obj
Returns the textual representation of obj as a string.
[Function]object->limited-string obj limit
Returns the textual representation of obj as a string of length at most limit.
Chapter 4: Textual Conversion Packages 94
4.12.3 Pretty-Print
(require ā€™pretty-print)
[Procedure]pretty-print obj
[Procedure]pretty-print obj port
pretty-prints obj on port. If port is not speciļ¬ed, current-output-port is used.
Example:
(pretty-print ā€™((1 2 3 4 5) (6 7 8 9 10) (11 12 13 14 15)
(16 17 18 19 20) (21 22 23 24 25)))
a
((1 2 3 4 5)
a
(6 7 8 9 10)
a
(11 12 13 14 15)
a
(16 17 18 19 20)
a
(21 22 23 24 25))
[Procedure]pretty-print->string obj
[Procedure]pretty-print->string obj width
Returns the string of obj pretty-printed in width columns. If width is not speciļ¬ed,
(output-port-width) is used.
Example:
(pretty-print->string ā€™((1 2 3 4 5) (6 7 8 9 10) (11 12 13 14 15)
(16 17 18 19 20) (21 22 23 24 25)))
ā‡’
"((1 2 3 4 5)
(6 7 8 9 10)
(11 12 13 14 15)
(16 17 18 19 20)
(21 22 23 24 25))
"
Chapter 4: Textual Conversion Packages 95
(pretty-print->string ā€™((1 2 3 4 5) (6 7 8 9 10) (11 12 13 14 15)
(16 17 18 19 20) (21 22 23 24 25))
16)
ā‡’
"((1 2 3 4 5)
(6 7 8 9 10)
(11
12
13
14
15)
(16
17
18
19
20)
(21
22
23
24
25))
"
(require ā€™pprint-file)
[Procedure]pprint-file inļ¬le
[Procedure]pprint-file inļ¬le outļ¬le
Pretty-prints all the code in inļ¬le. If outļ¬le is speciļ¬ed, the output goes to outļ¬le,
otherwise it goes to (current-output-port).
[Function]pprint-filter-file inļ¬le proc outļ¬le
[Function]pprint-filter-file inļ¬le proc
inļ¬le is a port or a string naming an existing ļ¬le. Scheme source code expressions and
deļ¬nitions are read from the port (or ļ¬le) and proc is applied to them sequentially.
outļ¬le is a port or a string. If no outļ¬le is speciļ¬ed then current-output-port is
assumed. These expanded expressions are then pretty-printed to this port.
Whitepsace and comments (introduced by ;) which are not part of scheme expressions
are reproduced in the output. This procedure does not aļ¬€ect the values returned by
current-input-port, current-error-port, and current-output-port.
pprint-filter-file can be used to pre-compile macro-expansion and thus can re-
duce loading time. The following will write into exp-code.scm the result of expanding all
defmacros in code.scm.
(require ā€™pprint-file)
(require ā€™defmacroexpand)
(defmacro:load "my-macros.scm")
(pprint-filter-file "code.scm" defmacro:expand* "exp-code.scm")
Chapter 4: Textual Conversion Packages 96
4.13 Time and Date
If (provided? ā€™current-time):
The procedures current-time, difftime, and offset-time deal with a calendar time
datatype which may or may not be disjoint from other Scheme datatypes.
[Function]current-time
Returns the time since 00:00:00 GMT, January 1, 1970, measured in seconds. Note
that the reference time is diļ¬€erent from the reference time for get-universal-time
in Section 4.13.3 [Common-Lisp Time], page 99.
[Function]difftime caltime1 caltime0
Returns the diļ¬€erence (number of seconds) between twe calendar times: caltime1 -
caltime0. caltime0 may also be a number.
[Function]offset-time caltime oļ¬€set
Returns the calendar time of caltime oļ¬€set by oļ¬€set number of seconds (+ caltime
offset).
4.13.1 Time Zone
(require ā€™time-zone)
[Data Format]TZ-string
POSIX standards specify several formats for encoding time-zone rules.
:<pathname>
If the ļ¬rst character of <pathname> is ā€˜/ā€™, then <pathname> speciļ¬es
the absolute pathname of a tzļ¬le(5) format time-zone ļ¬le. Otherwise,
<pathname> is interpreted as a pathname within tzļ¬le:vicinity
(/usr/lib/zoneinfo/) naming a tzļ¬le(5) format time-zone ļ¬le.
<std><offset>
The string <std> consists of 3 or more alphabetic characters. <oļ¬€set>
speciļ¬es the time diļ¬€erence from GMT. The <oļ¬€set> is positive if the
local time zone is west of the Prime Meridian and negative if it is east.
<oļ¬€set> can be the number of hours or hours and minutes (and optionally
seconds) separated by ā€˜:ā€™. For example, -4:30.
<std><offset><dst>
<dst> is the at least 3 alphabetic characters naming the local daylight-
savings-time.
<std><offset><dst><doffset>
<doļ¬€set> speciļ¬es the oļ¬€set from the Prime Meridian when daylight-
savings-time is in eļ¬€ect.
The non-tzļ¬le formats can optionally be followed by transition times specifying the
day and time when a zone changes from standard to daylight-savings and back again.
,<date>/<time>,<date>/<time>
The <time>s are speciļ¬ed like the <oļ¬€set>s above, except that leading ā€˜+ā€™
and ā€˜-ā€™ are not allowed.
Chapter 4: Textual Conversion Packages 97
Each <date> has one of the formats:
J<day> speciļ¬es the Julian day with <day> between 1 and 365. Febru-
ary 29 is never counted and cannot be referenced.
<day> This speciļ¬es the Julian day with n between 0 and 365.
February 29 is counted in leap years and can be speciļ¬ed.
M<month>.<week>.<day>
This speciļ¬es day <day> (0 <= <day> <= 6) of week <week>
(1 <= <week> <= 5) of month <month> (1 <= <month> <=
12). Week 1 is the ļ¬rst week in which day d occurs and week
5 is the last week in which day <day> occurs. Day 0 is a
Sunday.
[Data Type]time-zone
is a datatype encoding how many hours from Greenwich Mean Time the local time
is, and the Daylight Savings Time rules for changing it.
[Function]time-zone TZ-string
Creates and returns a time-zone object speciļ¬ed by the string TZ-string. If time-zone
cannot interpret TZ-string, #f is returned.
[Function]tz:params caltime tz
tz is a time-zone object. tz:params returns a list of three items:
0. An integer. 0 if standard time is in eļ¬€ect for timezone tz at caltime; 1 if daylight
savings time is in eļ¬€ect for timezone tz at caltime.
1. The number of seconds west of the Prime Meridian timezone tz is at caltime.
2. The name for timezone tz at caltime.
tz:params is unaļ¬€ected by the default timezone; inquiries can be made of any time-
zone at any calendar time.
[Function]tz:std-offset tz
tz is a time-zone object. tz:std-offset returns the number of seconds west of the
Prime Meridian timezone tz is.
The rest of these procedures and variables are provided for POSIX compatability. Because
of shared state they are not thread-safe.
[Function]tzset
Returns the default time-zone.
[Function]tzset tz
Sets (and returns) the default time-zone to tz.
[Function]tzset TZ-string
Sets (and returns) the default time-zone to that speciļ¬ed by TZ-string.
tzset also sets the variables *timezone*, daylight?, and tzname. This function is
automatically called by the time conversion procedures which depend on the time
zone (see Section 4.13 [Time and Date], page 96).
Chapter 4: Textual Conversion Packages 98
[Variable]*timezone*
Contains the diļ¬€erence, in seconds, between Greenwich Mean Time and local stan-
dard time (for example, in the U.S. Eastern time zone (EST), timezone is 5*60*60).
*timezone* is initialized by tzset.
[Variable]daylight?
is #t if the default timezone has rules for Daylight Savings Time. Note: daylight?
does not tell you when Daylight Savings Time is in eļ¬€ect, just that the default zone
sometimes has Daylight Savings Time.
[Variable]tzname
is a vector of strings. Index 0 has the abbreviation for the standard timezone; If
daylight?, then index 1 has the abbreviation for the Daylight Savings timezone.
4.13.2 Posix Time
(require ā€™posix-time)
[Data Type]Calendar-Time
is a datatype encapsulating time.
[Data Type]Coordinated Universal Time
(abbreviated UTC) is a vector of integers representing time:
0. seconds (0 - 61)
1. minutes (0 - 59)
2. hours since midnight (0 - 23)
3. day of month (1 - 31)
4. month (0 - 11). Note diļ¬€erence from decode-universal-time.
5. the number of years since 1900. Note diļ¬€erence from decode-universal-time.
6. day of week (0 - 6)
7. day of year (0 - 365)
8. 1 for daylight savings, 0 for regular time
[Function]gmtime caltime
Converts the calendar time caltime to UTC and returns it.
[Function]localtime caltime tz
Returns caltime converted to UTC relative to timezone tz.
[Function]localtime caltime
converts the calendar time caltime to a vector of integers expressed relative to the
userā€™s time zone. localtime sets the variable *timezone* with the diļ¬€erence be-
tween Coordinated Universal Time (UTC) and local standard time in seconds (see
Section 4.13.1 [Time Zone], page 96).
[Function]gmktime univtime
Converts a vector of integers in GMT Coordinated Universal Time (UTC) format to
a calendar time.
Chapter 4: Textual Conversion Packages 99
[Function]mktime univtime
Converts a vector of integers in local Coordinated Universal Time (UTC) format to
a calendar time.
[Function]mktime univtime tz
Converts a vector of integers in Coordinated Universal Time (UTC) format (relative
to time-zone tz) to calendar time.
[Function]asctime univtime
Converts the vector of integers caltime in Coordinated Universal Time (UTC) format
into a string of the form "Wed Jun 30 21:49:08 1993".
[Function]gtime caltime
[Function]ctime caltime
[Function]ctime caltime tz
Equivalent to (asctime (gmtime caltime)), (asctime (localtime caltime)), and
(asctime (localtime caltime tz)), respectively.
4.13.3 Common-Lisp Time
(require ā€™common-lisp-time)
[Function]get-decoded-time
Equivalent to (decode-universal-time (get-universal-time)).
[Function]get-universal-time
Returns the current time as Universal Time, number of seconds since 00:00:00 Jan 1,
1900 GMT. Note that the reference time is diļ¬€erent from current-time.
[Function]decode-universal-time univtime
Converts univtime to Decoded Time format. Nine values are returned:
0. seconds (0 - 61)
1. minutes (0 - 59)
2. hours since midnight
3. day of month
4. month (1 - 12). Note diļ¬€erence from gmtime and localtime.
5. year (A.D.). Note diļ¬€erence from gmtime and localtime.
6. day of week (0 - 6)
7. #t for daylight savings, #f otherwise
8. hours west of GMT (-24 - +24)
Notice that the values returned by decode-universal-time do not match the argu-
ments to encode-universal-time.
Chapter 4: Textual Conversion Packages 100
[Function]encode-universal-time second minute hour date month year
[Function]encode-universal-time second minute hour date month year
time-zone
Converts the arguments in Decoded Time format to Universal Time format. If time-
zone is not speciļ¬ed, the returned time is adjusted for daylight saving time. Other-
wise, no adjustment is performed.
Notice that the values returned by decode-universal-time do not match the argu-
ments to encode-universal-time.
4.13.4 ISO 8601
(require ā€™iso-8601)
[Function]time->iso-8601 time
time is the time in seconds since 00:00:00 GMT, January 1, 1970. time->iso-8601
returns an expanded ISO 8601 format string for the date and time.
[Function]time->iso8601 time
time is a time in seconds since 00:00:00 GMT, January 1, 1970. time->iso8601
returns a compact ISO 8601 format string for the date and time.
[Function]iso-8601->time str
str is a string in ISO 8601 format, either compact or expanded. iso-8601->time
returns that time in seconds since 00:00:00 GMT, January 1, 1970.
4.13.5 Time Infrastructure
(require ā€™time-core)
[Function]time:gmtime tm
[Function]time:invert decoder target
[Function]time:split t tm isdst tm gmtoļ¬€ tm zone
(require ā€™tzfile)
[Function]tzfile:read path
4.14 NCBI-DNA
(require ā€™ncbi-dma)
[Function]ncbi:read-dna-sequence port
Reads the NCBI-format DNA sequence following the word ā€˜ORIGINā€™ from port.
[Function]ncbi:read-file ļ¬le
Reads the NCBI-format DNA sequence following the word ā€˜ORIGINā€™ from ļ¬le.
[Function]mrna<-cdna str
Replaces ā€˜Tā€™ with ā€˜Uā€™ in str
[Function]codons<-cdna cdna
Returns a list of three-letter symbol codons comprising the protein sequence encoded
by cdna starting with its ļ¬rst occurence of ā€˜atgā€™.
Chapter 4: Textual Conversion Packages 101
[Function]protein<-cdna cdna
Returns a list of three-letter symbols for the protein sequence encoded by cdna starting
with its ļ¬rst occurence of ā€˜atgā€™.
[Function]p<-cdna cdna
Returns a string of one-letter amino acid codes for the protein sequence encoded by
cdna starting with its ļ¬rst occurence of ā€˜atgā€™.
These cDNA count routines provide a means to check the nucleotide sequence with the
ā€˜BASE COUNTā€™ line preceding the sequence from NCBI.
[Function]cdna:base-count cdna
Returns a list of counts of ā€˜aā€™, ā€˜cā€™, ā€˜gā€™, and ā€˜tā€™ occurrencing in cdna.
[Function]cdna:report-base-count cdna
Prints the counts of ā€˜aā€™, ā€˜cā€™, ā€˜gā€™, and ā€˜tā€™ occurrencing in cdna.
4.15 Schmooz
Schmooz is a simple, lightweight markup language for interspersing Texinfo documentation
with Scheme source code. Schmooz does not create the top level Texinfo ļ¬le; it creates ā€˜txiā€™
ļ¬les which can be imported into the documentation using the Texinfo command ā€˜@includeā€™.
(require ā€™schmooz) deļ¬nes the function schmooz, which is used to process ļ¬les. Files
containing schmooz documentation should not contain (require ā€™schmooz).
[Procedure]schmooz ļ¬lename.scm . . .
Filename.scm should be a string ending with ā€˜.scmā€™ naming an existing ļ¬le contain-
ing Scheme source code. schmooz extracts top-level comments containing schmooz
commands from ļ¬lename.scm and writes the converted Texinfo source to a ļ¬le named
ļ¬lename.txi.
[Procedure]schmooz ļ¬lename.texi . . .
[Procedure]schmooz ļ¬lename.tex . . .
[Procedure]schmooz ļ¬lename.txi . . .
Filename should be a string naming an existing ļ¬le containing Texinfo source code.
For every occurrence of the string ā€˜@include filename.txiā€™ within that ļ¬le, schmooz
calls itself with the argument ā€˜filename.scmā€™.
Schmooz comments are distinguished (from non-schmooz comments) by their ļ¬rst line,
which must start with an at-sign (@) preceded by one or more semicolons (;). A schmooz
comment ends at the ļ¬rst subsequent line which does not start with a semicolon. Currently
schmooz comments are recognized only at top level.
Schmooz comments are copied to the Texinfo output ļ¬le with the leading contiguous
semicolons removed. Certain character sequences starting with at-sign are treated specially.
Others are copied unchanged.
A schmooz comment starting with ā€˜@bodyā€™ must be followed by a Scheme deļ¬nition.
All comments between the ā€˜@bodyā€™ line and the deļ¬nition will be included in a Texinfo
102
deļ¬nition, either a ā€˜@defunā€™ or a ā€˜@defvarā€™, depending on whether a procedure or a variable
is being deļ¬ned.
Within the text of that schmooz comment, at-sign followed by ā€˜0ā€™ will be replaced by
@code{procedure-name} if the following deļ¬nition is of a procedure; or @var{variable}
if deļ¬ning a variable.
An at-sign followed by a non-zero digit will expand to the variable citation of that
numbered argument: ā€˜@var{argument-name}ā€™.
If more than one deļ¬nition follows a ā€˜@bodyā€™ comment line without an intervening blank
or comment line, then those deļ¬nitions will be included in the same Texinfo deļ¬nition using
ā€˜@defvarxā€™ or ā€˜@defunxā€™, depending on whether the ļ¬rst deļ¬nition is of a variable or of a
procedure.
Schmooz can ļ¬gure out whether a deļ¬nition is of a procedure if it is of the form:
ā€˜(define (<identifier> <arg> ...) <expression>)ā€™
or if the left hand side of the deļ¬nition is some form ending in a lambda expression. Ob-
viously, it can be fooled. In order to force recognition of a procedure deļ¬nition, start the
documentation with ā€˜@argsā€™ instead of ā€˜@bodyā€™. ā€˜@argsā€™ should be followed by the argument
list of the function being deļ¬ned, which may be enclosed in parentheses and delimited by
whitespace, (as in Scheme), enclosed in braces and separated by commas, (as in Texinfo),
or consist of the remainder of the line, separated by whitespace.
For example:
;;@args arg1 args ...
;;@0 takes argument @1 and any number of @2
(define myfun (some-function-returning-magic))
Will result in:
@defun myfun arg1 args @dots{}
@code{myfun} takes argument @var{arg1} and any number of @var{args}
@end defun
ā€˜@argsā€™ may also be useful for indicating optional arguments by name. If ā€˜@argsā€™ occurs
inside a schmooz comment section, rather than at the beginning, then it will generate a
ā€˜@defunxā€™ line with the arguments supplied.
If the ļ¬rst at-sign in a schmooz comment is immediately followed by whitespace, then
the comment will be expanded to whatever follows that whitespace. If the at-sign is followed
by a non-whitespace character then the at-sign will be included as the ļ¬rst character of the
expansion. This feature is intended to make it easy to include Texinfo directives in schmooz
comments.
103
5 Mathematical Packages
5.1 Bit-Twiddling
(require ā€™logical) or (require ā€™srfi-60)
The bit-twiddling functions are made available through the use of the logical package.
logical is loaded by inserting (require ā€™logical) before the code that uses these func-
tions. These functions behave as though operating on integers in twoā€™s-complement repre-
sentation.
5.1.1 Bitwise Operations
[Function]logand n1 . . .
[Function]bitwise-and n1 . . .
Returns the integer which is the bit-wise AND of the integer arguments.
Example:
(number->string (logand #b1100 #b1010) 2)
ā‡’
"1000"
[Function]logior n1 . . .
[Function]bitwise-ior n1 . . .
Returns the integer which is the bit-wise OR of the integer arguments.
Example:
(number->string (logior #b1100 #b1010) 2)
ā‡’
"1110"
[Function]logxor n1 . . .
[Function]bitwise-xor n1 . . .
Returns the integer which is the bit-wise XOR of the integer arguments.
Example:
(number->string (logxor #b1100 #b1010) 2)
ā‡’
"110"
[Function]lognot n
[Function]bitwise-not n
Returns the integer which is the oneā€™s-complement of the integer argument.
Example:
(number->string (lognot #b10000000) 2)
ā‡’
"-10000001"
(number->string (lognot #b0) 2)
ā‡’
"-1"
Chapter 5: Mathematical Packages 104
[Function]bitwise-if mask n0 n1
[Function]bitwise-merge mask n0 n1
Returns an integer composed of some bits from integer n0 and some from integer n1.
A bit of the result is taken from n0 if the corresponding bit of integer mask is 1 and
from n1 if that bit of mask is 0.
[Function]logtest j k
[Function]any-bits-set? j k
(logtest j k) ā‰” (not (zero? (logand j k)))
(logtest #b0100 #b1011)
ā‡’
#f
(logtest #b0100 #b0111)
ā‡’
#t
5.1.2 Integer Properties
[Function]logcount n
Returns the number of bits in integer n. If integer is positive, the 1-bits in its binary
representation are counted. If negative, the 0-bits in its twoā€™s-complement binary
representation are counted. If 0, 0 is returned.
Example:
(logcount #b10101010)
ā‡’
4
(logcount 0)
ā‡’
0
(logcount -2)
ā‡’
1
On [email protected] Ben Harris credits Simon Tatham with the idea to have
bitwise-bit-count return a negative count for negative inputs. Alan Bawden came up
with the succinct invariant.
[Function]bitwise-bit-count n
If n is non-negative, this procedure returns the number of 1 bits in the twoā€™s-
complement representation of n. Otherwise it returns the result of the following
computation:
(bitwise-not (bitwise-bit-count (bitwise-not n)))
[Function]integer-length n
Returns the number of bits neccessary to represent n.
Example:
(integer-length #b10101010)
ā‡’
8
(integer-length 0)
ā‡’
0
(integer-length #b1111)
ā‡’
4
Chapter 5: Mathematical Packages 105
[Function]log2-binary-factors n
[Function]first-set-bit n
Returns the number of factors of two of integer n. This value is also the bit-index of
the least-signiļ¬cant ā€˜1ā€™ bit in n.
(require ā€™printf)
(do ((idx 0 (+ 1 idx)))
((> idx 16))
(printf "%s(%3d) ==> %-5d %s(%2d) ==> %-5d\n"
ā€™log2-binary-factors
(- idx) (log2-binary-factors (- idx))
ā€™log2-binary-factors
idx (log2-binary-factors idx)))
a
log2-binary-factors( 0) ==> -1 log2-binary-factors( 0) ==> -1
log2-binary-factors( -1) ==> 0 log2-binary-factors( 1) ==> 0
log2-binary-factors( -2) ==> 1 log2-binary-factors( 2) ==> 1
log2-binary-factors( -3) ==> 0 log2-binary-factors( 3) ==> 0
log2-binary-factors( -4) ==> 2 log2-binary-factors( 4) ==> 2
log2-binary-factors( -5) ==> 0 log2-binary-factors( 5) ==> 0
log2-binary-factors( -6) ==> 1 log2-binary-factors( 6) ==> 1
log2-binary-factors( -7) ==> 0 log2-binary-factors( 7) ==> 0
log2-binary-factors( -8) ==> 3 log2-binary-factors( 8) ==> 3
log2-binary-factors( -9) ==> 0 log2-binary-factors( 9) ==> 0
log2-binary-factors(-10) ==> 1 log2-binary-factors(10) ==> 1
log2-binary-factors(-11) ==> 0 log2-binary-factors(11) ==> 0
log2-binary-factors(-12) ==> 2 log2-binary-factors(12) ==> 2
log2-binary-factors(-13) ==> 0 log2-binary-factors(13) ==> 0
log2-binary-factors(-14) ==> 1 log2-binary-factors(14) ==> 1
log2-binary-factors(-15) ==> 0 log2-binary-factors(15) ==> 0
log2-binary-factors(-16) ==> 4 log2-binary-factors(16) ==> 4
5.1.3 Bit Within Word
[Function]logbit? index n
[Function]bit-set? index n
(logbit? index n) ā‰” (logtest (expt 2 index) n)
(logbit? 0 #b1101)
ā‡’
#t
(logbit? 1 #b1101)
ā‡’
#f
(logbit? 2 #b1101)
ā‡’
#t
(logbit? 3 #b1101)
ā‡’
#t
(logbit? 4 #b1101)
ā‡’
#f
[Function]copy-bit index from bit
Returns an integer the same as from except in the indexth bit, which is 1 if bit is #t
and 0 if bit is #f.
Example:
Chapter 5: Mathematical Packages 106
(number->string (copy-bit 0 0 #t) 2)
ā‡’
"1"
(number->string (copy-bit 2 0 #t) 2)
ā‡’
"100"
(number->string (copy-bit 2 #b1111 #f) 2)
ā‡’
"1011"
5.1.4 Field of Bits
[Function]bit-field n start end
Returns the integer composed of the start (inclusive) through end (exclusive) bits of
n. The startth bit becomes the 0-th bit in the result.
Example:
(number->string (bit-field #b1101101010 0 4) 2)
ā‡’
"1010"
(number->string (bit-field #b1101101010 4 9) 2)
ā‡’
"10110"
[Function]copy-bit-field to from start end
Returns an integer the same as to except possibly in the start (inclusive) through end
(exclusive) bits, which are the same as those of from. The 0-th bit of from becomes
the startth bit of the result.
Example:
(number->string (copy-bit-field #b1101101010 0 0 4) 2)
ā‡’
"1101100000"
(number->string (copy-bit-field #b1101101010 -1 0 4) 2)
ā‡’
"1101101111"
(number->string (copy-bit-field #b110100100010000 -1 5 9) 2)
ā‡’
"110100111110000"
[Function]ash n count
[Function]arithmetic-shift n count
Returns an integer equivalent to (inexact->exact (floor (* n (expt 2 count)))).
Example:
(number->string (ash #b1 3) 2)
ā‡’
"1000"
(number->string (ash #b1010 -1) 2)
ā‡’
"101"
[Function]rotate-bit-field n count start end
Returns n with the bit-ļ¬eld from start to end cyclically permuted by count bits
towards high-order.
Example:
(number->string (rotate-bit-field #b0100 3 0 4) 2)
ā‡’
"10"
(number->string (rotate-bit-field #b0100 -1 0 4) 2)
ā‡’
"10"
(number->string (rotate-bit-field #b110100100010000 -1 5 9) 2)
ā‡’
"110100010010000"
Chapter 5: Mathematical Packages 107
(number->string (rotate-bit-field #b110100100010000 1 5 9) 2)
ā‡’
"110100000110000"
[Function]reverse-bit-field n start end
Returns n with the order of bits start to end reversed.
(number->string (reverse-bit-field #xa7 0 8) 16)
ā‡’
"e5"
5.1.5 Bits as Booleans
[Function]integer->list k len
[Function]integer->list k
integer->list returns a list of len booleans corresponding to each bit of the non-
negative integer k. #t is coded for each 1; #f for 0. The len argument defaults to
(integer-length k).
[Function]list->integer list
list->integer returns an integer formed from the booleans in the list list, which
must be a list of booleans. A 1 bit is coded for each #t; a 0 bit for #f.
(list->integer (integer->list k))
ā‡’
k
[Function]booleans->integer bool1 . . .
Returns the integer coded by the bool1 . . . arguments.
5.2 Modular Arithmetic
(require ā€™modular)
[Function]extended-euclid n1 n2
Returns a list of 3 integers (d x y) such that d = gcd(n1, n2) = n1 * x + n2 * y.
[Function]symmetric:modulus m
For odd positive integer m, returns an object suitable for passing as the ļ¬rst argument
to modular: procedures, directing them to return a symmetric modular number, ie.
an n such that
(<= (quotient m -2) n (quotient m 2)
[Function]modular:characteristic modulus
Returns the non-negative integer characteristic of the ring formed when modulus is
used with modular: procedures.
[Function]modular:normalize modulus n
Returns the integer (modulo n (modular:characteristic modulus)) in the repre-
sentation speciļ¬ed by modulus.
The rest of these functions assume normalized arguments; That is, the arguments are con-
strained by the following table:
Chapter 5: Mathematical Packages 108
For all of these functions, if the ļ¬rst argument (modulus) is:
positive?
Integers mod modulus. The result is between 0 and modulus.
zero? The arguments are treated as integers. An integer is returned.
Otherwise, if modulus is a value returned by (symmetric:modulus radix), then the argu-
ments and result are treated as members of the integers modulo radix, but with symmetric
representation; i.e.
(<= (quotient radix 2) n (quotient (- -1 radix) 2)
If all the arguments are ļ¬xnums the computation will use only ļ¬xnums.
[Function]modular:invertable? modulus k
Returns #t if there exists an integer n such that k * n ā‰” 1 mod modulus, and #f
otherwise.
[Function]modular:invert modulus n2
Returns an integer n such that 1 = (n * n2) mod modulus. If n2 has no inverse mod
modulus an error is signaled.
[Function]modular:negate modulus n2
Returns (āˆ’n2) mod modulus.
[Function]modular:+ modulus n2 n3
Returns (n2 + n3) mod modulus.
[Function]modular:- modulus n2 n3
Returns (n2 āˆ’ n3) mod modulus.
[Function]modular:* modulus n2 n3
Returns (n2 * n3) mod modulus.
The Scheme code for modular:* with negative modulus is not completed for ļ¬xnum-
only implementations.
[Function]modular:expt modulus n2 n3
Returns (n2 ^ n3) mod modulus.
5.3 Irrational Integer Functions
(require ā€™math-integer)
[Function]integer-expt n1 n2
Returns n1 raised to the power n2 if that result is an exact integer; otherwise signals
an error.
(integer-expt 0 n2)
returns 1 for n2 equal to 0; returns 0 for positive integer n2; signals an error otherwise.
Chapter 5: Mathematical Packages 109
[Function]integer-log base k
Returns the largest exact integer whose power of base is less than or equal to k. If
base or k is not a positive exact integer, then integer-log signals an error.
[Function]integer-sqrt k
For non-negative integer k returns the largest integer whose square is less than or
equal to k; otherwise signals an error.
[Function]quotient n1 n2
[Function]remainder n1 n2
[Function]modulo n1 n2
are redeļ¬ned so that they accept only exact-integer arguments.
[Function]round-quotient n1 n2
Returns the quotient of n1 and n2 rounded toward even.
(quotient 3 2)
ā‡’
1
(round-quotient 3 2)
ā‡’
2
5.4 Irrational Real Functions
(require ā€™math-real)
Although this package deļ¬nes real and complex functions, it is safe to load into an
integer-only implementation; those functions will be deļ¬ned to #f.
[Function]real-exp x
[Function]real-ln x
[Function]real-log y x
[Function]real-sin x
[Function]real-cos x
[Function]real-tan x
[Function]real-asin x
[Function]real-acos x
[Function]real-atan x
[Function]atan y x
These procedures are part of every implementation that supports general real num-
bers; they compute the usual transcendental functions. ā€˜real-lnā€™ computes the nat-
ural logarithm of x; ā€˜real-logā€™ computes the logarithm of x base y, which is (/
(real-ln x) (real-ln y)). If arguments x and y are not both real; or if the correct
result would not be real, then these procedures signal an error.
[Function]real-sqrt x
For non-negative real x the result will be its positive square root; otherwise an error
will be signaled.
[Function]real-expt x1 x2
Returns x1 raised to the power x2 if that result is a real number; otherwise signals
an error.
Chapter 5: Mathematical Packages 110
(real-expt 0.0 x2)
ā€¢ returns 1.0 for x2 equal to 0.0;
ā€¢ returns 0.0 for positive real x2;
ā€¢ signals an error otherwise.
[Function]quo x1 x2
[Function]rem x1 x2
[Function]mod x1 x2
x2 should be non-zero.
(quo x1 x2) ==> n_q
(rem x1 x2) ==> x_r
(mod x1 x2) ==> x_m
where n q is x1/x2 rounded towards zero, 0 < |x r| < |x2|, 0 < |x m| < |x2|, x r
and x m diļ¬€er from x1 by a multiple of x2, x r has the same sign as x1, and x m has
the same sign as x2.
From this we can conclude that for x2 not equal to 0,
(= x1 (+ (* x2 (quo x1 x2))
(rem x1 x2)))
==> #t
provided all numbers involved in that computation are exact.
(quo 2/3 1/5) ==> 3
(mod 2/3 1/5) ==> 1/15
(quo .666 1/5) ==> 3.0
(mod .666 1/5) ==> 65.99999999999995e-3
[Function]ln z
These procedures are part of every implementation that supports general real num-
bers. ā€˜Lnā€™ computes the natural logarithm of z
In general, the mathematical function ln is multiply deļ¬ned. The value of ln z is
deļ¬ned to be the one whose imaginary part lies in the range from -pi (exclusive) to
pi (inclusive).
[Function]abs x
For real argument x, ā€˜Absā€™ returns the absolute value of xā€™ otherwise it signals an
error.
(abs -7) ==> 7
[Function]make-rectangular x1 x2
[Function]make-polar x3 x4
These procedures are part of every implementation that supports general complex
numbers. Suppose x1, x2, x3, and x4 are real numbers and z is a complex number
such that
Chapter 5: Mathematical Packages 111
z = x1 + x2i = x3 . e^i x4
Then
(make-rectangular x1 x2) ==> z
(make-polar x3 x4) ==> z
where -pi < x angle <= pi with x angle = x4 + 2pi n for some integer n.
If an argument is not real, then these procedures signal an error.
5.5 Prime Numbers
(require ā€™factor)
[Variable]prime:prngs
prime:prngs is the random-state (see Section 5.6 [Random Numbers], page 112) used
by these procedures. If you call these procedures from more than one thread (or from
interrupt), random may complain about reentrant calls.
Note: The prime test and generation procedures implement (or use) the Solovay-
Strassen primality test. See
ā€¢ Robert Solovay and Volker Strassen, A Fast Monte-Carlo Test for Primality, SIAM
Journal on Computing, 1977, pp 84-85.
[Function]jacobi-symbol p q
Returns the value (+1, āˆ’1, or 0) of the Jacobi-Symbol of exact non-negative integer
p and exact positive odd integer q.
[Variable]prime:trials
prime:trials the maxinum number of iterations of Solovay-Strassen that will be done
to test a number for primality.
[Function]prime? n
Returns #f if n is composite; #t if n is prime. There is a slight chance (expt 2 (-
prime:trials)) that a composite will return #t.
[Function]primes< start count
Returns a list of the ļ¬rst count prime numbers less than start. If there are fewer than
count prime numbers less than start, then the returned list will have fewer than start
elements.
[Function]primes> start count
Returns a list of the ļ¬rst count prime numbers greater than start.
[Function]factor k
Returns a list of the prime factors of k. The order of the factors is unspeciļ¬ed. In
order to obtain a sorted list do (sort! (factor k) <).
Chapter 5: Mathematical Packages 112
5.6 Random Numbers
A pseudo-random number generator is only as good as the tests it passes. George Marsaglia
of Florida State University developed a battery of tests named DIEHARD (http://stat.
fsu.edu/~geo/diehard.html). diehard.c has a bug which the patch http://groups.
csail.mit.edu/mac/ftpdir/users/jaffer/diehard.c.pat corrects.
SLIBā€™s PRNG generates 8 bits at a time. With the degenerate seed ā€˜0ā€™, the numbers
generated pass DIEHARD; but when bits are combined from sequential bytes, tests fail.
With the seed ā€˜http://swissnet.ai.mit.edu/~jaffer/SLIB.htmlā€™, all of those tests pass.
5.6.1 Exact Random Numbers
(require ā€™random)
[Function]random n state
[Function]random n
n must be an exact positive integer. random returns an exact integer between zero
(inclusive) and n (exclusive). The values returned by random are uniformly distributed
from 0 to n.
The optional argument state must be of the type returned by (seed->random-state)
or (make-random-state). It defaults to the value of the variable *random-state*.
This object is used to maintain the state of the pseudo-random-number generator and
is altered as a side eļ¬€ect of calls to random.
[Variable]*random-state*
Holds a data structure that encodes the internal state of the random-number generator
that random uses by default. The nature of this data structure is implementation-
dependent. It may be printed out and successfully read back in, but may or may not
function correctly as a random-number state object in another implementation.
[Function]copy-random-state state
Returns a new copy of argument state.
[Function]copy-random-state
Returns a new copy of *random-state*.
[Function]seed->random-state seed
Returns a new object of type suitable for use as the value of the variable
*random-state* or as a second argument to random. The number or string seed is
used to initialize the state. If seed->random-state is called twice with arguments
which are equal?, then the returned data structures will be equal?. Calling
seed->random-state with unequal arguments will nearly always return unequal
states.
[Function]make-random-state
[Function]make-random-state obj
Returns a new object of type suitable for use as the value of the variable
*random-state* or as a second argument to random. If the optional argument obj
is given, it should be a printable Scheme object; the ļ¬rst 50 characters of its printed
Chapter 5: Mathematical Packages 113
representation will be used as the seed. Otherwise the value of *random-state* is
used as the seed.
5.6.2 Inexact Random Numbers
(require ā€™random-inexact)
[Function]random:uniform
[Function]random:uniform state
Returns an uniformly distributed inexact real random number in the range between
0 and 1.
[Function]random:exp
[Function]random:exp state
Returns an inexact real in an exponential distribution with mean 1. For an exponen-
tial distribution with mean u use (* u (random:exp)).
[Function]random:normal
[Function]random:normal state
Returns an inexact real in a normal distribution with mean 0 and standard de-
viation 1. For a normal distribution with mean m and standard deviation d use
(+ m (* d (random:normal))).
[Procedure]random:normal-vector! vect
[Procedure]random:normal-vector! vect state
Fills vect with inexact real random numbers which are independent and standard
normally distributed (i.e., with mean 0 and variance 1).
[Procedure]random:hollow-sphere! vect
[Procedure]random:hollow-sphere! vect state
Fills vect with inexact real random numbers the sum of whose squares is equal to 1.0.
Thinking of vect as coordinates in space of dimension n = (vector-length vect),
the coordinates are uniformly distributed over the surface of the unit n-shere.
[Procedure]random:solid-sphere! vect
[Procedure]random:solid-sphere! vect state
Fills vect with inexact real random numbers the sum of whose squares is less than 1.0.
Thinking of vect as coordinates in space of dimension n = (vector-length vect),
the coordinates are uniformly distributed within the unit n-shere. The sum of the
squares of the numbers is returned.
5.7 Discrete Fourier Transform
(require ā€™dft) or (require ā€™Fourier-transform)
fft and fft-1 compute the Fast-Fourier-Transforms (O(n*log(n))) of arrays whose
dimensions are all powers of 2.
sft and sft-1 compute the Discrete-Fourier-Transforms for all combinations of dimen-
sions (O(n^2)).
Chapter 5: Mathematical Packages 114
[Function]sft array prot
[Function]sft array
array is an array of positive rank. sft returns an array of type prot (defaulting to
array) of complex numbers comprising the Discrete Fourier Transform of array.
[Function]sft-1 array prot
[Function]sft-1 array
array is an array of positive rank. sft-1 returns an array of type prot (defaulting
to array) of complex numbers comprising the inverse Discrete Fourier Transform of
array.
[Function]fft array prot
[Function]fft array
array is an array of positive rank whose dimensions are all powers of 2. fft returns an
array of type prot (defaulting to array) of complex numbers comprising the Discrete
Fourier Transform of array.
[Function]fft-1 array prot
[Function]fft-1 array
array is an array of positive rank whose dimensions are all powers of 2. fft-1 returns
an array of type prot (defaulting to array) of complex numbers comprising the inverse
Discrete Fourier Transform of array.
dft and dft-1 compute the discrete Fourier transforms using the best method for
decimating each dimension.
[Function]dft array prot
[Function]dft array
dft returns an array of type prot (defaulting to array) of complex numbers comprising
the Discrete Fourier Transform of array.
[Function]dft-1 array prot
[Function]dft-1 array
dft-1 returns an array of type prot (defaulting to array) of complex numbers com-
prising the inverse Discrete Fourier Transform of array.
(fft-1 (fft array)) will return an array of values close to array.
(fft ā€™#(1 0+i -1 0-i 1 0+i -1 0-i))
ā‡’
#(0.0 0.0 0.0+628.0783185208527e-18i 0.0
0.0 0.0 8.0-628.0783185208527e-18i 0.0)
(fft-1 ā€™#(0 0 0 0 0 0 8 0))
ā‡’
#(1.0 -61.23031769111886e-18+1.0i -1.0 61.23031769111886e-18-1.0i
1.0 -61.23031769111886e-18+1.0i -1.0 61.23031769111886e-18-1.0i)
Chapter 5: Mathematical Packages 115
5.8 Cyclic Checksum
(require ā€™crc) Cyclic Redundancy Checks using Galois ļ¬eld GF(2) polynomial arithmetic
are used for error detection in many data transmission and storage applications.
The generator polynomials for various CRC protocols are availble from many sources. But
the polynomial is just one of many parameters which must match in order for a CRC
implementation to interoperate with existing systems:
ā€¢ the byte-order and bit-order of the data stream;
ā€¢ whether the CRC or its inverse is being calculated;
ā€¢ the initial CRC value; and
ā€¢ whether and where the CRC value is appended (inverted or non-inverted) to the data
stream.
The performance of a particular CRC polynomial over packets of given sizes varies widely.
In terms of the probability of undetected errors, some uses of extant CRC polynomials are
suboptimal by several orders of magnitude.
If you are considering CRC for a new application, consult the following article to ļ¬nd the
optimum CRC polynomial for your range of data lengths:
ā€¢ Philip Koopman and Tridib Chakravarty,
ā€œCyclic Redundancy Code (CRC) Polynomial Selection For Embedded Networksā€,
The International Conference on Dependable Systems and Networks, DSN-2004.
http://www.ece.cmu.edu/~koopman/roses/dsn04/koopman04_crc_poly_embedded.pdf
There is even some controversy over the polynomials themselves.
[Constant]crc-32-polynomial
For CRC-32, http://www2.sis.pitt.edu/~jkabara/tele-2100/lect08.html gives
x^32+x^26+x^23+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x^1+1.
But http://www.cs.ncl.ac.uk/people/harry.whitļ¬eld/home.formal/CRCs.html,
http://duchon.umuc.edu/Web Pages/duchon/99 f cm435/ShiftRegister.htm,
http://spinroot.com/spin/Doc/Book91 PDF/ch3.pdf, http://www.erg.abdn.ac.uk/users/gorry/course/dl-
pages/crc.html, http://www.rad.com/networks/1994/err con/crc most.htm, and
http://www.gpfn.sk.ca/~rhg/csc8550s02/crc.html, http://www.nobugconsulting.ro/crc.php
give x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
SLIB crc-32-polynomial uses the latter deļ¬nition.
[Constant]crc-ccitt-polynomial
http://www.math.grin.edu/~rebelsky/Courses/CS364/2000S/Outlines/outline.12.html,
http://duchon.umuc.edu/Web Pages/duchon/99 f cm435/ShiftRegister.htm,
http://www.cs.ncl.ac.uk/people/harry.whitļ¬eld/home.formal/CRCs.html,
http://www2.sis.pitt.edu/~jkabara/tele-2100/lect08.html, and http://www.gpfn.sk.ca/~rhg/csc8550s02/crc.html
give CRC-CCITT: x^16+x^12+x^5+1.
Chapter 5: Mathematical Packages 116
[Constant]crc-16-polynomial
http://www.math.grin.edu/~rebelsky/Courses/CS364/2000S/Outlines/outline.12.html,
http://duchon.umuc.edu/Web Pages/duchon/99 f cm435/ShiftRegister.htm,
http://www.cs.ncl.ac.uk/people/harry.whitļ¬eld/home.formal/CRCs.html,
http://www.gpfn.sk.ca/~rhg/csc8550s02/crc.html, and http://www.usb.org/developers/data/crcdes.pdf
give CRC-16: x^16+x^15+x^2+1.
[Constant]crc-12-polynomial
http://www.math.grin.edu/~rebelsky/Courses/CS364/2000S/Outlines/outline.12.html,
http://www.cs.ncl.ac.uk/people/harry.whitļ¬eld/home.formal/CRCs.html,
http://www.it.iitb.ac.in/it605/lectures/link/node4.html, and http://spinroot.com/spin/Doc/Book91 PDF/ch3.pdf
give CRC-12: x^12+x^11+x^3+x^2+1.
But http://www.ļ¬„dusoe.edu/Faculty/Denenberg/Topics/Networks/Error Detection Correction/crc.html,
http://duchon.umuc.edu/Web Pages/duchon/99 f cm435/ShiftRegister.htm,
http://www.eng.uwi.tt/depts/elec/staļ¬€/kimal/errorcc.html, http://www.ee.uwa.edu.au/~roberto/teach/itc314/java/CRC/,
http://www.gpfn.sk.ca/~rhg/csc8550s02/crc.html, and http://www.efg2.com/Lab/Mathematics/CRC.htm
give CRC-12: x^12+x^11+x^3+x^2+x+1.
These diļ¬€er in bit 1 and calculations using them return diļ¬€erent values. With citations
near evenly split, it is hard to know which is correct. Thanks to Philip Koopman for
breaking the tie in favor of the latter (#xC07).
[Constant]crc-10-polynomial
http://www.math.grin.edu/~rebelsky/Courses/CS364/2000S/Outlines/outline.12.html
gives CRC-10: x^10+x^9+x^5+x^4+1; but http://cell-relay.indiana.edu/cell-
relay/publications/software/CRC/crc10.html, http://www.it.iitb.ac.in/it605/lectures/link/node4.html,
http://www.gpfn.sk.ca/~rhg/csc8550s02/crc.html, http://www.techfest.com/networking/atm/atm.htm,
http://www.protocols.com/pbook/atmcell2.htm, and http://www.nobugconsulting.ro/crc.php
give CRC-10: x^10+x^9+x^5+x^4+x+1.
[Constant]crc-08-polynomial
http://www.math.grin.edu/~rebelsky/Courses/CS364/2000S/Outlines/outline.12.html,
http://www.cs.ncl.ac.uk/people/harry.whitļ¬eld/home.formal/CRCs.html,
http://www.it.iitb.ac.in/it605/lectures/link/node4.html, and http://www.nobugconsulting.ro/crc.php
give CRC-8: x^8+x^2+x^1+1
[Constant]atm-hec-polynomial
http://cell-relay.indiana.edu/cell-relay/publications/software/CRC/32bitCRC.tutorial.html
and http://www.gpfn.sk.ca/~rhg/csc8550s02/crc.html give ATM HEC: x^8+x^2+x+1.
[Constant]dowcrc-polynomial
http://www.cs.ncl.ac.uk/people/harry.whitļ¬eld/home.formal/CRCs.html gives
DOWCRC: x^8+x^5+x^4+1.
[Constant]usb-token-polynomial
http://www.usb.org/developers/data/crcdes.pdf and http://www.nobugconsulting.ro/crc.php
give USB-token: x^5+x^2+1.
Each of these polynomial constants is a string of ā€˜1ā€™s and ā€˜0ā€™s, the exponent of each power
of x in descending order.
Chapter 5: Mathematical Packages 117
[Function]crc:make-table poly
poly must be string of ā€˜1ā€™s and ā€˜0ā€™s beginning with ā€˜1ā€™ and having length greater than
8. crc:make-table returns a vector of 256 integers, such that:
(set! crc
(logxor (ash (logand (+ -1 (ash 1 (- deg 8))) crc) 8)
(vector-ref crc-table
(logxor (ash crc (- 8 deg)) byte))))
will compute the crc with the 8 additional bits in byte; where crc is the previous
accumulated CRC value, deg is the degree of poly, and crc-table is the vector returned
by crc:make-table.
If the implementation does not support deg-bit integers, then crc:make-table re-
turns #f.
[Function]cksum ļ¬le
Computes the P1003.2/D11.2 (POSIX.2) 32-bit checksum of ļ¬le.
(require ā€™crc)
(cksum (in-vicinity (library-vicinity) "ratize.scm"))
ā‡’
157103930
[Function]cksum port
Computes the checksum of the bytes read from port until the end-of-ļ¬le.
cksum-string, which returns the P1003.2/D11.2 (POSIX.2) 32-bit checksum of the bytes
in str, can be deļ¬ned as follows:
(require ā€™string-port)
(define (cksum-string str) (call-with-input-string str cksum))
[Function]crc16 ļ¬le
Computes the USB data-packet (16-bit) CRC of ļ¬le.
[Function]crc16 port
Computes the USB data-packet (16-bit) CRC of the bytes read from port until the
end-of-ļ¬le.
crc16 calculates the same values as the crc16.pl program given in
http://www.usb.org/developers/data/crcdes.pdf.
[Function]crc5 ļ¬le
Computes the USB token (5-bit) CRC of ļ¬le.
[Function]crc5 port
Computes the USB token (5-bit) CRC of the bytes read from port until the end-of-ļ¬le.
crc5 calculates the same values as the crc5.pl program given in
http://www.usb.org/developers/data/crcdes.pdf.
Chapter 5: Mathematical Packages 118
5.9 Graphing
5.9.1 Character Plotting
(require ā€™charplot)
[Variable]charplot:dimensions
A list of the maximum height (number of lines) and maximum width (number of
columns) for the graph, its scales, and labels.
The default value for charplot:dimensions is the output-port-height and
output-port-width of current-output-port.
[Procedure]plot coords x-label y-label
coords is a list or vector of coordinates, lists of x and y coordinates. x-label and
y-label are strings with which to label the x and y axes.
Example:
(require ā€™charplot)
(set! charplot:dimensions ā€™(20 55))
(define (make-points n)
(if (zero? n)
ā€™()
(cons (list (/ n 6) (sin (/ n 6))) (make-points (1- n)))))
(plot (make-points 40) "x" "Sin(x)")
a
Sin(x) _________________________________________
1|- **** |
| ** ** |
0.75|- * * |
| * * |
0.5|- * * |
| * *|
0.25|- * * |
| * * |
0|-------------------*------------------*--|
| * |
-0.25|- * * |
| * * |
-0.5|- * |
| * * |
-0.75|- * * |
| ** ** |
-1|- **** |
|:_____._____:_____._____:_____._____:____|
x 2 4 6
Chapter 5: Mathematical Packages 119
[Procedure]plot func x1 x2
[Procedure]plot func x1 x2 npts
Plots the function of one argument func over the range x1 to x2. If the optional
integer argument npts is supplied, it speciļ¬es the number of points to evaluate func
at.
(plot sin 0 (* 2 pi))
a
_________________________________________
1|-: **** |
| : ** ** |
0.75|-: * * |
| : * * |
0.5|-: ** ** |
| : * * |
0.25|-:** ** |
| :* * |
0|-*------------------*--------------------|
| : * * |
-0.25|-: ** ** |
| : * * |
-0.5|-: * ** |
| : * * |
-0.75|-: * ** |
| : ** ** |
-1|-: **** |
|_:_____._____:_____._____:_____._____:___|
0 2 4 6
[Procedure]histograph data label
Creates and displays a histogram of the numerical values contained in vector or list
data
(require ā€™random-inexact)
(histograph (do ((idx 99 (+ -1 idx))
(lst ā€™() (cons (* .02 (random:normal)) lst)))
((negative? idx) lst))
"normal")
a
Chapter 5: Mathematical Packages 120
_________________________________________
8|- : I |
| : I |
7|- I I : I |
| I I : I |
6|- III I :I I |
| III I :I I |
5|- IIIIIIIIII I |
| IIIIIIIIII I |
4|- IIIIIIIIIIII |
| IIIIIIIIIIII |
3|-I I I IIIIIIIIIIII II I |
| I I I IIIIIIIIIIII II I |
2|-I I I IIIIIIIIIIIIIIIII I |
| I I I IIIIIIIIIIIIIIIII I |
1|-II I I IIIIIIIIIIIIIIIIIIIII I I I |
| II I I IIIIIIIIIIIIIIIIIIIII I I I |
0|-IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII----|
|__.____:____.____:____.____:____.____:___|
normal -0.025 0 0.025 0.05
5.9.2 PostScript Graphing
(require ā€™eps-graph)
This is a graphing package creating encapsulated-PostScript ļ¬les. Its motivations and design
choice are described in http://people.csail.mit.edu/jaffer/Docupage/grapheps
A dataset to be plotted is taken from a 2-dimensional array. Corresponding coordinates are
in rows. Coordinates from any pair of columns can be plotted.
[Function]create-postscript-graph ļ¬lename.eps size elt1 . . .
ļ¬lename.eps should be a string naming an output ļ¬le to be created. size should be
an exact integer, a list of two exact integers, or #f. elt1, ... are values returned by
graphing primitives described here.
create-postscript-graph creates an Encapsulated-PostScript ļ¬le named
ļ¬lename.eps containing graphs as directed by the elt1, ... arguments.
The size of the graph is determined by the size argument. If a list of two integers,
they specify the width and height. If one integer, then that integer is the width and
the height is 3/4 of the width. If #f, the graph will be 800 by 600.
These graphing procedures should be called as arguments to create-postscript-graph.
The order of these arguments is signiļ¬cant; PostScript graphics state is aļ¬€ected serially
from the ļ¬rst elt argument to the last.
[Function]whole-page
Pushes a rectangle for the whole encapsulated page onto the PostScript stack. This
pushed rectangle is an implicit argument to partition-page or setup-plot.
Chapter 5: Mathematical Packages 121
5.9.2.1 Column Ranges
A range is a list of two numbers, the minimum and the maximum. Ranges can be given
explicity or computed in PostScript by column-range.
[Function]column-range array k
Returns the range of values in 2-dimensional array column k.
[Function]pad-range range p
Expands range by p/100 on each end.
[Function]snap-range range
Expands range to round number of ticks.
[Function]combine-ranges range1 range2 . . .
Returns the minimal range covering all range1, range2, ...
[Function]setup-plot x-range y-range pagerect
[Function]setup-plot x-range y-range
x-range and y-range should each be a list of two numbers or the value returned by
pad-range, snap-range, or combine-range. pagerect is the rectangle bounding the
graph to be drawn; if missing, the rectangle from the top of the PostScript stack is
popped and used.
Based on the given ranges, setup-plot sets up scaling and margins for making a
graph. The margins are sized proportional to the fontheight value at the time of the
call to setup-plot. setup-plot sets two variables:
plotrect The region where data points will be plotted.
graphrect The pagerect argument to setup-plot. Includes plotrect, legends, etc.
5.9.2.2 Drawing the Graph
[Function]plot-column array x-column y-column proc3s
Plots points with x coordinate in x-column of array and y coordinate y-column of
array. The symbol proc3s speciļ¬es the type of glyph or drawing style for presenting
these coordinates.
The glyphs and drawing styles available are:
line Draws line connecting points in order.
mountain Fill area below line connecting points.
cloud Fill area above line connecting points.
impulse Draw line from x-axis to each point.
bargraph Draw rectangle from x-axis to each point.
disc Solid round dot.
point Minimal point ā€“ invisible if linewidth is 0.
square Square box.
Chapter 5: Mathematical Packages 122
diamond Square box at 45.o
plus Plus sign.
cross X sign.
triup Triangle pointing upward
tridown Triangle pointing downward
pentagon Five sided polygon
circle Hollow circle
[Function]plot-text-column array x-column y-column t-column proc3s
Plots text in t-column of array at x coordinate in x-column of array and y coordinate
y-column of array. The symbol proc3s speciļ¬es the oļ¬€set of the text from the speciļ¬ed
coordinates.
The oļ¬€sets available are:
above Draws the text centered above at the point.
center Draws the text centered at the point.
below Draws the text centered below the point.
left Draws the text to the left of the point.
right Draws the text to the right of the point.
All the oļ¬€sets other than center are calculated to keep the text clear of a glyph drawn
at the same coordinates. If you need more or less clearance, use set-glyphsize.
5.9.2.3 Graphics Context
[Function]in-graphic-context arg . . .
Saves the current graphics state, executes args, then restores to saved graphics state.
[Function]set-color color
color should be a string naming a Resene color, a saturate color, or a number between
0 and 100.
set-color sets the PostScript color to the color of the given string, or a grey value
between black (0) and white (100).
[Function]set-font font height
[Function]set-font font encoding height
font should be a (case-sensitive) string naming a PostScript font. height should
be a positive real number. encoding should name a PostScript encoding such as
ā€˜ISOLatin1Encodingā€™.
set-font Changes the current PostScript font to font with the encoding encoding,
and height equal to height. The default font is ā€˜Helveticaā€™ (12pt). The default
encoding is ā€˜StandardEncodingā€™.
Chapter 5: Mathematical Packages 123
The base set of PostScript fonts is:
Times Times-Italic Times-Bold Times-BoldItalic
Helvetica Helvetica-Oblique Helvetica-Bold Helvetica-BoldOblique
Courier Courier-Oblique Courier-Bold Courier-BoldOblique
Symbol
The base set of PostScript encodings is:
StandardEncoding ISOLatin1Encoding ExpertEncoding
ExpertSubsetEncoding SymbolEncoding
Line parameters do no aļ¬€ect fonts; they do eļ¬€ect glyphs.
[Function]set-linewidth w
The default linewidth is 1. Setting it to 0 makes the lines drawn as skinny as possible.
Linewidth must be much smaller than glyphsize for readable glyphs.
[Function]set-linedash j k
Lines are drawn j-on k-oļ¬€.
[Function]set-linedash j
Lines are drawn j-on j-oļ¬€.
[Function]set-linedash
Turns oļ¬€ dashing.
[Function]set-glyphsize w
Sets the (PostScript) variable glyphsize to w. The default glyphsize is 6.
The eļ¬€ects of clip-to-rect are also part of the graphic context.
5.9.2.4 Rectangles
A rectangle is a list of 4 numbers; the ļ¬rst two elements are the x and y coordinates of
lower left corner of the rectangle. The other two elements are the width and height of the
rectangle.
[Function]whole-page
Pushes a rectangle for the whole encapsulated page onto the PostScript stack. This
pushed rectangle is an implicit argument to partition-page or setup-plot.
[Function]partition-page xparts yparts
Pops the rectangle currently on top of the stack and pushes xparts * yparts sub-
rectangles onto the stack in decreasing y and increasing x order. If you are drawing
just one graph, then you donā€™t need partition-page.
[Variable]plotrect
The rectangle where data points should be plotted. plotrect is set by setup-plot.
[Variable]graphrect
The pagerect argument of the most recent call to setup-plot. Includes plotrect,
legends, etc.
Chapter 5: Mathematical Packages 124
[Function]fill-rect rect
ļ¬lls rect with the current color.
[Function]outline-rect rect
Draws the perimiter of rect in the current color.
[Function]clip-to-rect rect
Modiļ¬es the current graphics-state so that nothing will be drawn outside of the rect-
angle rect. Use in-graphic-context to limit the extent of clip-to-rect.
5.9.2.5 Legending
[Function]title-top title subtitle
[Function]title-top title
Puts a title line and an optional subtitle line above the graphrect.
[Function]title-bottom title subtitle
[Function]title-bottom title
Puts a title line and an optional subtitle line below the graphrect.
[Variable]topedge
[Variable]bottomedge
These edge coordinates of graphrect are suitable for passing as the ļ¬rst argument
to rule-horizontal.
[Variable]leftedge
[Variable]rightedge
These edge coordinates of graphrect are suitable for passing as the ļ¬rst argument
to rule-vertical.
[Function]set-margin-templates left right
The margin-templates are strings whose displayed width is used to reserve space for
the left and right side numerical legends. The default values are "-.0123456789".
[Function]rule-vertical x-coord text tick-width
Draws a vertical ruler with X coordinate x-coord and labeled with string text. If
tick-width is positive, then the ticks are tick-width long on the right side of x-coord;
and text and numeric legends are on the left. If tick-width is negative, then the ticks
are -tick-width long on the left side of x-coord; and text and numeric legends are on
the right.
[Function]rule-horizontal y-coord text tick-height
Draws a horizontal ruler with Y coordinate y-coord and labeled with string text. If
tick-height is positive, then the ticks are tick-height long on the top side of y-coord;
and text and numeric legends are on the bottom. If tick-height is negative, then
the ticks are -tick-height long on the bottom side of y-coord; and text and numeric
legends are on the top.
[Function]y-axis
Draws the y-axis.
Chapter 5: Mathematical Packages 125
[Function]x-axis
Draws the x-axis.
[Function]grid-verticals
Draws vertical lines through graphrect at each tick on the vertical ruler.
[Function]grid-horizontals
Draws horizontal lines through graphrect at each tick on the horizontal ruler.
5.9.2.6 Legacy Plotting
[Variable]graph:dimensions
A list of the width and height of the graph to be plotted using plot.
[Function]plot func x1 x2 npts
[Function]plot func x1 x2
Creates and displays using (system "gv tmp.eps") an encapsulated PostScript graph
of the function of one argument func over the range x1 to x2. If the optional integer
argument npts is supplied, it speciļ¬es the number of points to evaluate func at.
[Function]plot x1 x2 npts func1 func2 . . .
Creates and displays an encapsulated PostScript graph of the one-argument functions
func1, func2, ... over the range x1 to x2 at npts points.
[Function]plot coords x-label y-label
coords is a list or vector of coordinates, lists of x and y coordinates. x-label and
y-label are strings with which to label the x and y axes.
5.9.2.7 Example Graph
The ļ¬le am1.5.html, a table of solar irradiance, is fetched with ā€˜wgetā€™ if it isnā€™t already in
the working directory. The ļ¬le is read and stored into an array, irradiance.
create-postscript-graph is then called to create an encapsulated-PostScript ļ¬le,
solarad.eps. The size of the page is set to 600 by 300. whole-page is called and leaves
the rectangle on the PostScript stack. setup-plot is called with a literal range for x and
computes the range for column 1.
Two calls to top-title are made so a diļ¬€erent font can be used for the lower half.
in-graphic-context is used to limit the scope of the font change. The graphing area is
outlined and a rule drawn on the left side.
Because the X range was intentionally reduced, in-graphic-context is called and
clip-to-rect limits drawing to the plotting area. A black line is drawn from data column
1. That line is then overlayed with a mountain plot of the same column colored "Bright
Sun".
After returning from the in-graphic-context, the bottom ruler is drawn. Had it been
drawn earlier, all its ticks would have been painted over by the mountain plot.
The color is then changed to ā€˜seagreenā€™ and the same graphrect is setup again, this
time with a diļ¬€erent Y scale, 0 to 1000. The graphic context is again clipped to plotrect,
Chapter 5: Mathematical Packages 126
linedash is set, and column 2 is plotted as a dashed line. Finally the rightedge is ruled.
Having the line and its scale both in green helps disambiguate the scales.
(require ā€™eps-graph)
(require ā€™line-i/o)
(require ā€™string-port)
(define irradiance
(let ((url "http://www.pv.unsw.edu.au/am1.5.html")
(file "am1.5.html"))
(define (read->list line)
(define elts ā€™())
(call-with-input-string line
(lambda (iprt) (do ((elt (read iprt) (read iprt)))
((eof-object? elt) elts)
(set! elts (cons elt elts))))))
(if (not (file-exists? file))
(system (string-append "wget -c -O" file " " url)))
(call-with-input-file file
(lambda (iprt)
(define lines ā€™())
(do ((line (read-line iprt) (read-line iprt)))
((eof-object? line)
(let ((nra (make-array (A:floR64b)
(length lines)
(length (car lines)))))
(do ((lns lines (cdr lns))
(idx (+ -1 (length lines)) (+ -1 idx)))
((null? lns) nra)
(do ((kdx (+ -1 (length (car lines))) (+ -1 kdx))
(lst (car lns) (cdr lst)))
((null? lst))
(array-set! nra (car lst) idx kdx)))))
(if (and (positive? (string-length line))
(char-numeric? (string-ref line 0)))
(set! lines (cons (read->list line) lines))))))))
(let ((xrange ā€™(.25 2.5)))
(create-postscript-graph
"solarad.eps" ā€™(600 300)
(whole-page)
(setup-plot xrange (column-range irradiance 1))
(title-top
"Solar Irradiance http://www.pv.unsw.edu.au/am1.5.html")
(in-graphic-context
(set-font "Helvetica-Oblique" 12)
(title-top
Chapter 5: Mathematical Packages 127
""
"Key Centre for Photovoltaic Engineering UNSW - Air Mass 1.5 Global Spectrum"))
(outline-rect plotrect)
(rule-vertical leftedge "W/(m^2.um)" 10)
(in-graphic-context (clip-to-rect plotrect)
(plot-column irradiance 0 1 ā€™line)
(set-color "Bright Sun")
(plot-column irradiance 0 1 ā€™mountain)
)
(rule-horizontal bottomedge "Wavelength in .um" 5)
(set-color ā€™seagreen)
(setup-plot xrange ā€™(0 1000) graphrect)
(in-graphic-context (clip-to-rect plotrect)
(set-linedash 5 2)
(plot-column irradiance 0 2 ā€™line))
(rule-vertical rightedge "Integrated .W/(m^2)" -10)
))
(system "gv solarad.eps")
5.10 Solid Modeling
(require ā€™solid)
http://people.csail.mit.edu/jaffer/Solid/#Example gives an example use of this
package.
[Function]vrml node . . .
Returns the VRML97 string (including header) of the concatenation of strings nodes,
. . ..
[Function]vrml-append node1 node2 . . .
Returns the concatenation with interdigitated newlines of strings node1, node2, . . ..
[Function]vrml-to-file ļ¬le node . . .
Writes to ļ¬le named ļ¬le the VRML97 string (including header) of the concatenation
of strings nodes, . . . .
[Function]world:info title info . . .
Returns a VRML97 string setting the title of the ļ¬le in which it appears to title.
Additional strings info, . . . are comments.
VRML97 strings passed to vrml and vrml-to-file as arguments will appear in the
resulting VRML code. This string turns oļ¬€ the headlight at the viewpoint:
" NavigationInfo {headlight FALSE}"
[Function]scene:panorama front right back left top bottom
Speciļ¬es the distant images on the inside faces of the cube enclosing the virtual world.
Chapter 5: Mathematical Packages 128
[Function]scene:sphere colors angles
colors is a list of color objects. Each may be of type Section 5.11.1 [Color Data-Type],
page 134, a 24-bit sRGB integer, or a list of 3 numbers between 0.0 and 1.0.
angles is a list of non-increasing angles the same length as colors. Each angle is
between 90 and -90 degrees. If 90 or -90 are not elements of angles, then the color at
the zenith and nadir are taken from the colors paired with the angles nearest them.
scene:sphere ļ¬lls horizontal bands with interpolated colors on the background
sphere encasing the world.
[Function]scene:sky-and-dirt
Returns a blue and brown background sphere encasing the world.
[Function]scene:sky-and-grass
Returns a blue and green background sphere encasing the world.
[Function]scene:sun latitude julian-day hour turbidity strength
[Function]scene:sun latitude julian-day hour turbidity
latitude is the virtual placeā€™s latitude in degrees. julian-day is an integer from 0 to
366, the day of the year. hour is a real number from 0 to 24 for the time of day; 12 is
noon. turbidity is the degree of fogginess described in See Section 5.11.7 [Daylight],
page 149.
scene:sun returns a bright yellow, distant sphere where the sun would be at hour
on julian-day at latitude. If strength is positive, included is a light source of strength
(default 1).
[Function]scene:overcast latitude julian-day hour turbidity strength
[Function]scene:overcast latitude julian-day hour turbidity
latitude is the virtual placeā€™s latitude in degrees. julian-day is an integer from 0 to
366, the day of the year. hour is a real number from 0 to 24 for the time of day; 12 is
noon. turbidity is the degree of cloudiness described in See Section 5.11.7 [Daylight],
page 149.
scene:overcast returns an overcast sky as it might look at hour on julian-day at
latitude. If strength is positive, included is an ambient light source of strength (default
1).
Viewpoints are objects in the virtual world, and can be transformed individually or with
solid objects.
[Function]scene:viewpoint name distance compass pitch
[Function]scene:viewpoint name distance compass
Returns a viewpoint named name facing the origin and placed distance from it. com-
pass is a number from 0 to 360 giving the compass heading. pitch is a number from
-90 to 90, defaulting to 0, specifying the angle from the horizontal.
[Function]scene:viewpoints proximity
Returns 6 viewpoints, one at the center of each face of a cube with sides 2 * proximity,
centered on the origin.
Chapter 5: Mathematical Packages 129
Light Sources
In VRML97, lights shine only on objects within the same children node and descendants
of that node. Although it would have been convenient to let light direction be rotated by
solid:rotation, this restricts a rotated lightā€™s visibility to objects rotated with it.
To workaround this limitation, these directional light source procedures accept either Carte-
sian or spherical coordinates for direction. A spherical coordinate is a list (theta azimuth);
where theta is the angle in degrees from the zenith, and azimuth is the angle in degrees due
west of south.
It is sometimes useful for light sources to be brighter than ā€˜1ā€™. When intensity arguments
are greater than 1, these functions gang multiple sources to reach the desired strength.
[Function]light:ambient color intensity
[Function]light:ambient color
Ambient light shines on all surfaces with which it is grouped.
color is a an object of type Section 5.11.1 [Color Data-Type], page 134, a 24-bit sRGB
integer, or a list of 3 numbers between 0.0 and 1.0. If color is #f, then the default
color will be used. intensity is a real non-negative number defaulting to ā€˜1ā€™.
light:ambient returns a light source or sources of color with total strength of inten-
sity (or 1 if omitted).
[Function]light:directional color direction intensity
[Function]light:directional color direction
[Function]light:directional color
Directional light shines parallel rays with uniform intensity on all objects with which
it is grouped.
color is a an object of type Section 5.11.1 [Color Data-Type], page 134, a 24-bit sRGB
integer, or a list of 3 numbers between 0.0 and 1.0. If color is #f, then the default
color will be used.
direction must be a list or vector of 2 or 3 numbers specifying the direction to this
light. If direction has 2 numbers, then these numbers are the angle from zenith and
the azimuth in degrees; if direction has 3 numbers, then these are taken as a Cartesian
vector specifying the direction to the light source. The default direction is upwards;
thus its light will shine down.
intensity is a real non-negative number defaulting to ā€˜1ā€™.
light:directional returns a light source or sources of color with total strength of
intensity, shining from direction.
[Function]light:beam attenuation radius aperture peak
[Function]light:beam attenuation radius aperture
[Function]light:beam attenuation radius
[Function]light:beam attenuation
attenuation is a list or vector of three nonnegative real numbers specifying the re-
duction of intensity, the reduction of intensity with distance, and the reduction of
intensity as the square of distance. radius is the distance beyond which the light does
not shine. radius defaults to ā€˜100ā€™.
Chapter 5: Mathematical Packages 130
aperture is a real number between 0 and 180, the angle centered on the lightā€™s axis
through which it sheds some light. peak is a real number between 0 and 90, the angle
of greatest illumination.
[Function]light:point location color intensity beam
[Function]light:point location color intensity
[Function]light:point location color
[Function]light:point location
Point light radiates from location, intensity decreasing with distance, towards all
objects with which it is grouped.
color is a an object of type Section 5.11.1 [Color Data-Type], page 134, a 24-bit sRGB
integer, or a list of 3 numbers between 0.0 and 1.0. If color is #f, then the default
color will be used. intensity is a real non-negative number defaulting to ā€˜1ā€™. beam is
a structure returned by light:beam or #f.
light:point returns a light source or sources at location of color with total strength
intensity and beam properties. Note that the pointlight itself is not visible. To make
it so, place an object with emissive appearance at location.
[Function]light:spot location direction color intensity beam
[Function]light:spot location direction color intensity
[Function]light:spot location direction color
[Function]light:spot location direction
[Function]light:spot location
Spot light radiates from location towards direction, intensity decreasing with distance,
illuminating objects with which it is grouped.
direction must be a list or vector of 2 or 3 numbers specifying the direction to this
light. If direction has 2 numbers, then these numbers are the angle from zenith and
the azimuth in degrees; if direction has 3 numbers, then these are taken as a Cartesian
vector specifying the direction to the light source. The default direction is upwards;
thus its light will shine down.
color is a an object of type Section 5.11.1 [Color Data-Type], page 134, a 24-bit sRGB
integer, or a list of 3 numbers between 0.0 and 1.0. If color is #f, then the default
color will be used.
intensity is a real non-negative number defaulting to ā€˜1ā€™.
light:spot returns a light source or sources at location of direction with total
strength color. Note that the spotlight itself is not visible. To make it so, place
an object with emissive appearance at location.
Object Primitives
[Function]solid:box geometry appearance
[Function]solid:box geometry
geometry must be a number or a list or vector of three numbers. If geometry is a
number, the solid:box returns a cube with sides of length geometry centered on the
origin. Otherwise, solid:box returns a rectangular box with dimensions geometry
Chapter 5: Mathematical Packages 131
centered on the origin. appearance determines the surface properties of the returned
object.
[Function]solid:lumber geometry appearance
Returns a box of the speciļ¬ed geometry, but with the y-axis of a texture speciļ¬ed in
appearance being applied along the longest dimension in geometry.
[Function]solid:cylinder radius height appearance
[Function]solid:cylinder radius height
Returns a right cylinder with dimensions (abs radius) and (abs height) centered
on the origin. If height is positive, then the cylinder ends will be capped. If ra-
dius is negative, then only the ends will appear. appearance determines the surface
properties of the returned object.
[Function]solid:disk radius thickness appearance
[Function]solid:disk radius thickness
thickness must be a positive real number. solid:disk returns a circular disk with
dimensions radius and thickness centered on the origin. appearance determines the
surface properties of the returned object.
[Function]solid:cone radius height appearance
[Function]solid:cone radius height
Returns an isosceles cone with dimensions radius and height centered on the origin.
appearance determines the surface properties of the returned object.
[Function]solid:pyramid side height appearance
[Function]solid:pyramid side height
Returns an isosceles pyramid with dimensions side and height centered on the origin.
appearance determines the surface properties of the returned object.
[Function]solid:sphere radius appearance
[Function]solid:sphere radius
Returns a sphere of radius radius centered on the origin. appearance determines the
surface properties of the returned object.
[Function]solid:ellipsoid geometry appearance
[Function]solid:ellipsoid geometry
geometry must be a number or a list or vector of three numbers. If geometry is a
number, the solid:ellipsoid returns a sphere of diameter geometry centered on the
origin. Otherwise, solid:ellipsoid returns an ellipsoid with diameters geometry
centered on the origin. appearance determines the surface properties of the returned
object.
[Function]solid:polyline coordinates appearance
[Function]solid:polyline coordinates
coordinates must be a list or vector of coordinate lists or vectors specifying the x, y,
and z coordinates of points. solid:polyline returns lines connecting successive pairs
of points. If called with one argument, then the polyline will be white. If appearance
Chapter 5: Mathematical Packages 132
is given, then the polyline will have its emissive color only; being black if appearance
does not have an emissive color.
The following code will return a red line between points at (1 2 3) and (4 5 6):
(solid:polyline ā€™((1 2 3) (4 5 6)) (solid:color #f 0 #f 0 ā€™(1 0 0)))
[Function]solid:prism xz-array y appearance
[Function]solid:prism xz-array y
xz-array must be an n-by-2 array holding a sequence of coordinates tracing a non-
intersecting clockwise loop in the x-z plane. solid:prism will close the sequence if
the ļ¬rst and last coordinates are not the same.
solid:prism returns a capped prism y long.
[Function]solid:basrelief width height depth colorray appearance
[Function]solid:basrelief width height depth appearance
[Function]solid:basrelief width height depth
One of width, height, or depth must be a 2-dimensional array; the others must be
real numbers giving the length of the basrelief in those dimensions. The rest of this
description assumes that height is an array of heights.
solid:basrelief returns a width by depth basrelief solid with heights per array
height with the buttom surface centered on the origin.
If present, appearance determines the surface properties of the returned object. If
present, colorray must be an array of objects of type Section 5.11.1 [Color Data-Type],
page 134, 24-bit sRGB integers or lists of 3 numbers between 0.0 and 1.0.
If colorrayā€™s dimensions match height, then each element of colorray paints its corre-
sponding vertex of height. If colorray has all dimensions one smaller than height, then
each element of colorray paints the corresponding face of height. Other dimensions
for colorray are in error.
[Function]solid:text fontstyle str len appearance
[Function]solid:text fontstyle str len
fontstyle must be a value returned by solid:font.
str must be a string or list of strings.
len must be #f, a nonnegative integer, or list of nonnegative integers.
appearance, if given, determines the surface properties of the returned object.
solid:text returns a two-sided, ļ¬‚at text object positioned in the Z=0 plane of the
local coordinate system
Surface Attributes
[Function]solid:color diļ¬€useColor ambientIntensity specularColor shininess
emissiveColor transparency
[Function]solid:color diļ¬€useColor ambientIntensity specularColor shininess
emissiveColor
[Function]solid:color diļ¬€useColor ambientIntensity specularColor shininess
[Function]solid:color diļ¬€useColor ambientIntensity specularColor
Chapter 5: Mathematical Packages 133
[Function]solid:color diļ¬€useColor ambientIntensity
[Function]solid:color diļ¬€useColor
Returns an appearance, the optical properties of the objects with which it is associ-
ated. ambientIntensity, shininess, and transparency must be numbers between 0 and
1. diļ¬€useColor, specularColor, and emissiveColor are objects of type Section 5.11.1
[Color Data-Type], page 134, 24-bit sRGB integers or lists of 3 numbers between 0.0
and 1.0. If a color argument is omitted or #f, then the default color will be used.
[Function]solid:texture image color scale rotation center translation
[Function]solid:texture image color scale rotation center
[Function]solid:texture image color scale rotation
[Function]solid:texture image color scale
[Function]solid:texture image color
[Function]solid:texture image
Returns an appearance, the optical properties of the objects with which it is associ-
ated. image is a string naming a JPEG or PNG image resource. color is #f, a color,
or the string returned by solid:color. The rest of the optional arguments specify
2-dimensional transforms applying to the image.
scale must be #f, a number, or list or vector of 2 numbers specifying the scale to apply
to image. rotation must be #f or the number of degrees to rotate image. center must
be #f or a list or vector of 2 numbers specifying the center of image relative to the
image dimensions. translation must be #f or a list or vector of 2 numbers specifying
the translation to apply to image.
[Function]solid:font family style justify size spacing language direction
Returns a fontstyle object suitable for passing as an argument to solid:text. Any
of the arguments may be #f, in which case its default value, which is ļ¬rst in each list
of allowed values, is used.
family is a case-sensitive string naming a font; ā€˜SERIFā€™, ā€˜SANSā€™, and ā€˜TYPEWRITERā€™ are
supported at the minimum.
style is a case-sensitive string ā€˜PLAINā€™, ā€˜BOLDā€™, ā€˜ITALICā€™, or ā€˜BOLDITALICā€™.
justify is a case-sensitive string ā€˜FIRSTā€™, ā€˜BEGINā€™, ā€˜MIDDLEā€™, or ā€˜ENDā€™; or a list of one or
two case-sensitive strings (same choices). The mechanics of justify get complicated;
it is explained by tables 6.2 to 6.7 of http://www.web3d.org/x3d/specifications/
vrml/ISO-IEC-14772-IS-VRML97WithAmendment1/part1/nodesRef.html#Table6.
2
size is the extent, in the non-advancing direction, of the text. size defaults to 1.
spacing is the ratio of the line (or column) oļ¬€set to size. spacing defaults to 1.
language is the RFC-1766 language name.
direction is a list of two numbers: (x y). If (> (abs x) (abs y)), then the text will
be arrayed horizontally; otherwise vertically. The direction in which characters are
arrayed is determined by the sign of the major axis: positive x being left-to-right;
positive y being top-to-bottom.
Chapter 5: Mathematical Packages 134
Aggregating Objects
[Function]solid:center-row-of number solid spacing
Returns a row of number solid objects spaced evenly spacing apart.
[Function]solid:center-array-of number-a number-b solid spacing-a
spacing-b
Returns number-b rows, spacing-b apart, of number-a solid objects spacing-a apart.
[Function]solid:center-pile-of number-a number-b number-c solid
spacing-a spacing-b spacing-c
Returns number-c planes, spacing-c apart, of number-b rows, spacing-b apart, of
number-a solid objects spacing-a apart.
[Function]solid:arrow center
center must be a list or vector of three numbers. Returns an upward pointing metallic
arrow centered at center.
[Function]solid:arrow
Returns an upward pointing metallic arrow centered at the origin.
Spatial Transformations
[Function]solid:translation center solid . . .
center must be a list or vector of three numbers. solid:translation Returns an
aggregate of solids, . . . with their origin moved to center.
[Function]solid:scale scale solid . . .
scale must be a number or a list or vector of three numbers. solid:scale Returns
an aggregate of solids, . . . scaled per scale.
[Function]solid:rotation axis angle solid . . .
axis must be a list or vector of three numbers. solid:rotation Returns an aggregate
of solids, . . . rotated angle degrees around the axis axis.
5.11 Color
http://people.csail.mit.edu/jaffer/Color
The goals of this package are to provide methods to specify, compute, and transform colors
in a core set of additive color spaces. The color spaces supported should be suļ¬ƒcient for
working with the color data encountered in practice and the literature.
5.11.1 Color Data-Type
(require ā€™color)
[Function]color? obj
Returns #t if obj is a color.
Chapter 5: Mathematical Packages 135
[Function]color? obj typ
Returns #t if obj is a color of color-space typ. The symbol typ must be one of:
ā€¢ CIEXYZ
ā€¢ RGB709
ā€¢ L*a*b*
ā€¢ L*u*v*
ā€¢ sRGB
ā€¢ e-sRGB
ā€¢ L*C*h
[Function]make-color space arg . . .
Returns a color of type space.
ā€¢ For space arguments CIEXYZ, RGB709, and sRGB, the sole arg is a list of three
numbers.
ā€¢ For space arguments L*a*b*, L*u*v*, and L*C*h, arg is a list of three numbers
optionally followed by a whitepoint.
ā€¢ For xRGB, arg is an integer.
ā€¢ For e-sRGB, the arguments are as for e-sRGB->color.
[Function]color-space color
Returns the symbol for the color-space in which color is embedded.
[Function]color-precision color
For colors in digital color-spaces, color-precision returns the number of bits used
for each of the R, G, and B channels of the encoding. Otherwise, color-precision
returns #f
[Function]color-white-point color
Returns the white-point of color in all color-spaces except CIEXYZ.
[Function]convert-color color space white-point
[Function]convert-color color space
[Function]convert-color color e-sRGB precision
Converts color into space at optional white-point.
5.11.1.1 External Representation
Each color encoding has an external, case-insensitive representation. To ensure portability,
the white-point for all color strings is D65.
1
Color Space External Representation
CIEXYZ CIEXYZ:<X>/<Y>/<Z>
1
Readers may recognize these color string formats from Xlib. X11ā€™s color management system was
doomed by its ļ¬ction that CRT monitorsā€™ (and X11 default) color-spaces were linear RGBi. Unable to
shed this legacy, the only practical way to view pictures on X is to ignore its color management system
and use an sRGB monitor. In this implementation the device-independent RGB709 and sRGB spaces
replace the device-dependent RGBi and RGB spaces of Xlib.
Chapter 5: Mathematical Packages 136
RGB709 RGBi:<R>/<G>/<B>
L*a*b* CIELAB:<L>/<a>/<b>
L*u*v* CIELuv:<L>/<u>/<v>
L*C*h CIELCh:<L>/<C>/<h>
The X, Y, Z, L, a, b, u, v, C, h, R, G, and B ļ¬elds are (Scheme) real numbers within the
appropriate ranges.
Color Space External Representation
sRGB sRGB:<R>/<G>/<B>
e-sRGB10 e-sRGB10:<R>/<G>/<B>
e-sRGB12 e-sRGB12:<R>/<G>/<B>
e-sRGB16 e-sRGB16:<R>/<G>/<B>
The R, G, and B, ļ¬elds are non-negative exact decimal integers within the appropriate
ranges.
Several additional syntaxes are supported by string->color:
Color Space External Representation
sRGB sRGB:<RRGGBB>
sRGB #<RRGGBB>
sRGB 0x<RRGGBB>
sRGB #x<RRGGBB>
Where RRGGBB is a non-negative six-digit hexadecimal number.
[Function]color->string color
Returns a string representation of color.
[Function]string->color string
Returns the color represented by string. If string is not a syntactically valid notation
for a color, then string->color returns #f.
5.11.1.2 White
We experience color relative to the illumination around us. CIEXYZ coordinates, although
subject to uniform scaling, are objective. Thus other color spaces are speciļ¬ed relative to
a white point in CIEXYZ coordinates.
The white point for digital color spaces is set to D65. For the other spaces a white-point
argument can be speciļ¬ed. The default if none is speciļ¬ed is the white-point with which
the color was created or last converted; and D65 if none has been speciļ¬ed.
[Constant]D65
Is the color of 6500.K (blackbody) illumination. D65 is close to the average color of
daylight.
[Constant]D50
Is the color of 5000.K (blackbody) illumination. D50 is the color of indoor lighting
by incandescent bulbs, whose ļ¬laments have temperatures around 5000.K.
5.11.2 Color Spaces
Chapter 5: Mathematical Packages 137
Measurement-based Color Spaces
The tristimulus color spaces are those whose component values are proportional measure-
ments of light intensity. The CIEXYZ(1931) system provides 3 sets of spectra to dot-product
with a spectrum of interest. The result of those dot-products is coordinates in CIEXYZ
space. All tristimuls color spaces are related to CIEXYZ by linear transforms, namely ma-
trix multiplication. Of the color spaces listed here, CIEXYZ and RGB709 are tristimulus
spaces.
[Color Space]CIEXYZ
The CIEXYZ color space covers the full gamut. It is the basis for color-space conver-
sions.
CIEXYZ is a list of three inexact numbers between 0.0 and 1.1. ā€™(0. 0. 0.) is black;
ā€™(1. 1. 1.) is white.
[Function]ciexyz->color xyz
xyz must be a list of 3 numbers. If xyz is valid CIEXYZ coordinates, then
ciexyz->color returns the color speciļ¬ed by xyz; otherwise returns #f.
[Function]color:ciexyz x y z
Returns the CIEXYZ color composed of x, y, z. If the coordinates do not encode a
valid CIEXYZ color, then an error is signaled.
[Function]color->ciexyz color
Returns the list of 3 numbers encoding color in CIEXYZ.
[Color Space]RGB709
BT.709-4 (03/00) Parameter values for the HDTV standards for production and inter-
national programme exchange speciļ¬es parameter values for chromaticity, sampling,
signal format, frame rates, etc., of high deļ¬nition television signals.
An RGB709 color is represented by a list of three inexact numbers between 0.0 and
1.0. ā€™(0. 0. 0.) is black ā€™(1. 1. 1.) is white.
[Function]rgb709->color rgb
rgb must be a list of 3 numbers. If rgb is valid RGB709 coordinates, then
rgb709->color returns the color speciļ¬ed by rgb; otherwise returns #f.
[Function]color:rgb709 r g b
Returns the RGB709 color composed of r, g, b. If the coordinates do not encode a
valid RGB709 color, then an error is signaled.
[Function]color->rgb709 color
Returns the list of 3 numbers encoding color in RGB709.
Perceptual Uniformity
Although properly encoding the chromaticity, tristimulus spaces do not match the logarith-
mic response of human visual systems to intensity. Minimum detectable diļ¬€erences between
colors correspond to a smaller range of distances (6:1) in the L*a*b* and L*u*v* spaces
than in tristimulus spaces (80:1). For this reason, color distances are computed in L*a*b*
(or L*C*h).
Chapter 5: Mathematical Packages 138
[Color Space]L*a*b*
Is a CIE color space which better matches the human visual systemā€™s perception of
color. It is a list of three numbers:
ā€¢ 0 <= L* <= 100 (CIE Lightness)
ā€¢ -500 <= a* <= 500
ā€¢ -200 <= b* <= 200
[Function]l*a*b*->color L*a*b* white-point
L*a*b* must be a list of 3 numbers. If L*a*b* is valid L*a*b* coordinates, then
l*a*b*->color returns the color speciļ¬ed by L*a*b*; otherwise returns #f.
[Function]color:l*a*b* L* a* b* white-point
Returns the L*a*b* color composed of L*, a*, b* with white-point.
[Function]color:l*a*b* L* a* b*
Returns the L*a*b* color composed of L*, a*, b*. If the coordinates do not encode
a valid L*a*b* color, then an error is signaled.
[Function]color->l*a*b* color white-point
Returns the list of 3 numbers encoding color in L*a*b* with white-point.
[Function]color->l*a*b* color
Returns the list of 3 numbers encoding color in L*a*b*.
[Color Space]L*u*v*
Is another CIE encoding designed to better match the human visual systemā€™s percep-
tion of color.
[Function]l*u*v*->color L*u*v* white-point
L*u*v* must be a list of 3 numbers. If L*u*v* is valid L*u*v* coordinates, then
l*u*v*->color returns the color speciļ¬ed by L*u*v*; otherwise returns #f.
[Function]color:l*u*v* L* u* v* white-point
Returns the L*u*v* color composed of L*, u*, v* with white-point.
[Function]color:l*u*v* L* u* v*
Returns the L*u*v* color composed of L*, u*, v*. If the coordinates do not encode
a valid L*u*v* color, then an error is signaled.
[Function]color->l*u*v* color white-point
Returns the list of 3 numbers encoding color in L*u*v* with white-point.
[Function]color->l*u*v* color
Returns the list of 3 numbers encoding color in L*u*v*.
Cylindrical Coordinates
HSL (Hue Saturation Lightness), HSV (Hue Saturation Value), HSI (Hue Saturation Inten-
sity) and HCI (Hue Chroma Intensity) are cylindrical color spaces (with angle hue). But
these spaces are all deļ¬ned in terms device-dependent RGB spaces.
Chapter 5: Mathematical Packages 139
One might wonder if there is some fundamental reason why intuitive speciļ¬cation of color
must be device-dependent. But take heart! A cylindrical system can be based on L*a*b*
and is used for predicting how close colors seem to observers.
[Color Space]L*C*h
Expresses the *a and b* of L*a*b* in polar coordinates. It is a list of three numbers:
ā€¢ 0 <= L* <= 100 (CIE Lightness)
ā€¢ C* (CIE Chroma) is the distance from the neutral (gray) axis.
ā€¢ 0 <= h <= 360 (CIE Hue) is the angle.
The colors by quadrant of h are:
0 red, orange, yellow 90
90 yellow, yellow-green, green 180
180 green, cyan (blue-green), blue 270
270 blue, purple, magenta 360
[Function]l*c*h->color L*C*h white-point
L*C*h must be a list of 3 numbers. If L*C*h is valid L*C*h coordinates, then
l*c*h->color returns the color speciļ¬ed by L*C*h; otherwise returns #f.
[Function]color:l*c*h L* C* h white-point
Returns the L*C*h color composed of L*, C*, h with white-point.
[Function]color:l*c*h L* C* h
Returns the L*C*h color composed of L*, C*, h. If the coordinates do not encode a
valid L*C*h color, then an error is signaled.
[Function]color->l*c*h color white-point
Returns the list of 3 numbers encoding color in L*C*h with white-point.
[Function]color->l*c*h color
Returns the list of 3 numbers encoding color in L*C*h.
Digital Color Spaces
The color spaces discussed so far are impractical for image data because of numerical preci-
sion and computational requirements. In 1998 the IEC adopted A Standard Default Color
Space for the Internet - sRGB (http://www.w3.org/Graphics/Color/sRGB). sRGB was
cleverly designed to employ the 24-bit (256x256x256) color encoding already in widespread
use; and the 2.2 gamma intrinsic to CRT monitors.
Conversion from CIEXYZ to digital (sRGB) color spaces is accomplished by conversion ļ¬rst
to a RGB709 tristimulus space with D65 white-point; then each coordinate is individually
subjected to the same non-linear mapping. Inverse operations in the reverse order create
the inverse transform.
Chapter 5: Mathematical Packages 140
[Color Space]sRGB
Is "A Standard Default Color Space for the Internet". Most display monitors will
work fairly well with sRGB directly. Systems using ICC proļ¬les
2
should work very
well with sRGB.
[Function]srgb->color rgb
rgb must be a list of 3 numbers. If rgb is valid sRGB coordinates, then srgb->color
returns the color speciļ¬ed by rgb; otherwise returns #f.
[Function]color:srgb r g b
Returns the sRGB color composed of r, g, b. If the coordinates do not encode a valid
sRGB color, then an error is signaled.
[Color Space]xRGB
Represents the equivalent sRGB color with a single 24-bit integer. The most sig-
niļ¬cant 8 bits encode red, the middle 8 bits blue, and the least signiļ¬cant 8 bits
green.
[Function]color->srgb color
Returns the list of 3 integers encoding color in sRGB.
[Function]color->xrgb color
Returns the 24-bit integer encoding color in sRGB.
[Function]xrgb->color k
Returns the sRGB color composed of the 24-bit integer k.
[Color Space]e-sRGB
Is "Photography - Electronic still picture imaging - Extended sRGB color encoding"
(PIMA 7667:2001). It extends the gamut of sRGB; and its higher precision numbers
provide a larger dynamic range.
A triplet of integers represent e-sRGB colors. Three precisions are supported:
e-sRGB10 0 to 1023
e-sRGB12 0 to 4095
e-sRGB16 0 to 65535
[Function]e-srgb->color precision rgb
precision must be the integer 10, 12, or 16. rgb must be a list of 3 numbers. If rgb
is valid e-sRGB coordinates, then e-srgb->color returns the color speciļ¬ed by rgb;
otherwise returns #f.
2
A comprehensive encoding of transforms between CIEXYZ and device color spaces is the International
Color Consortium proļ¬le format, ICC.1:1998-09:
The intent of this format is to provide a cross-platform device proļ¬le format. Such device
proļ¬les can be used to translate color data created on one device into another deviceā€™s native
color space.
Chapter 5: Mathematical Packages 141
[Function]color:e-srgb 10 r g b
Returns the e-sRGB10 color composed of integers r, g, b.
[Function]color:e-srgb 12 r g b
Returns the e-sRGB12 color composed of integers r, g, b.
[Function]color:e-srgb 16 r g b
Returns the e-sRGB16 color composed of integers r, g, b. If the coordinates do not
encode a valid e-sRGB color, then an error is signaled.
[Function]color->e-srgb precision color
precision must be the integer 10, 12, or 16. color->e-srgb returns the list of 3
integers encoding color in sRGB10, sRGB12, or sRGB16.
5.11.3 Spectra
The following functions compute colors from spectra, scale color luminance, and extract
chromaticity. XYZ is used in the names of procedures for unnormalized colors; the coor-
dinates of CIEXYZ colors are constrained as described in Section 5.11.2 [Color Spaces],
page 136.
(require ā€™color-space)
A spectrum may be represented as:
ā€¢ A procedure of one argument accepting real numbers from 380e-9 to 780e-9, the wave-
length in meters; or
ā€¢ A vector of real numbers representing intensity samples evenly spaced over some range
of wavelengths overlapping the range 380e-9 to 780e-9.
CIEXYZ values are calculated as dot-product with the X, Y (Luminance), and Z Spectral
Tristimulus Values. The ļ¬les cie1931.xyz and cie1964.xyz in the distribution contain
these CIE-deļ¬ned values.
[Feature]cie1964
Loads the Spectral Tristimulus Values CIE 1964 Supplementary Standard Colorimet-
ric Observer, deļ¬ning cie:x-bar, cie:y-bar, and cie:z-bar.
[Feature]cie1931
Loads the Spectral Tristimulus Values CIE 1931 Supplementary Standard Colorimet-
ric Observer, deļ¬ning cie:x-bar, cie:y-bar, and cie:z-bar.
[Feature]ciexyz
Requires Spectral Tristimulus Values, defaulting to cie1931, deļ¬ning cie:x-bar, cie:y-
bar, and cie:z-bar.
(require ā€™cie1964) or (require ā€™cie1931) will load-ciexyz speciļ¬c values used by the
following spectrum conversion procedures. The spectrum conversion procedures (require
ā€™ciexyz) to assure that a set is loaded.
Chapter 5: Mathematical Packages 142
[Function]read-cie-illuminant path
path must be a string naming a ļ¬le consisting of 107 numbers for 5.nm intervals from
300.nm to 830.nm. read-cie-illuminant reads (using Scheme read) these numbers
and returns a length 107 vector ļ¬lled with them.
(define CIE:SI-D65
(read-CIE-illuminant (in-vicinity (library-vicinity) "ciesid65.dat")))
(spectrum->XYZ CIE:SI-D65 300e-9 830e-9)
ā‡’
(25.108569422374994 26.418013465625001 28.764075683374993)
[Function]read-normalized-illuminant path
path must be a string naming a ļ¬le consisting of 107 numbers for 5.nm intervals
from 300.nm to 830.nm. read-normalized-illuminant reads (using Scheme read)
these numbers and returns a length 107 vector ļ¬lled with them, normalized so that
spectrum->XYZ of the illuminant returns its whitepoint.
CIE Standard Illuminants A and D65 are included with SLIB:
(define CIE:SI-A
(read-normalized-illuminant (in-vicinity (library-vicinity) "ciesia.dat")))
(define CIE:SI-D65
(read-normalized-illuminant (in-vicinity (library-vicinity) "ciesid65.dat")))
(spectrum->XYZ CIE:SI-A 300e-9 830e-9)
ā‡’
(1.098499460820401 999.9999999999998e-3 355.8173930654951e-3)
(CIEXYZ->sRGB (spectrum->XYZ CIE:SI-A 300e-9 830e-9))
ā‡’
(255 234 133)
(spectrum->XYZ CIE:SI-D65 300e-9 830e-9)
ā‡’
(950.4336673552745e-3 1.0000000000000002 1.0888053986649182)
(CIEXYZ->sRGB (spectrum->XYZ CIE:SI-D65 300e-9 830e-9))
ā‡’
(255 255 255)
[Function]illuminant-map proc siv
siv must be a one-dimensional array or vector of 107 numbers. illuminant-map
returns a vector of length 107 containing the result of applying proc to each element
of siv.
[Function]illuminant-map->XYZ proc siv
(spectrum->XYZ (illuminant-map proc siv) 300e-9 830e-9)
[Function]spectrum->XYZ proc
proc must be a function of one argument. spectrum->XYZ computes the
CIEXYZ(1931) values for the spectrum returned by proc when called with
arguments from 380e-9 to 780e-9, the wavelength in meters.
[Function]spectrum->XYZ spectrum x1 x2
x1 and x2 must be positive real numbers specifying the wavelengths (in meters) cor-
responding to the zeroth and last elements of vector or list spectrum. spectrum->XYZ
returns the CIEXYZ(1931) values for a light source with spectral values proportional
to the elements of spectrum at evenly spaced wavelengths between x1 and x2.
Chapter 5: Mathematical Packages 143
Compute the colors of 6500.K and 5000.K blackbody radiation:
(require ā€™color-space)
(define xyz (spectrum->XYZ (blackbody-spectrum 6500)))
(define y_n (cadr xyz))
(map (lambda (x) (/ x y_n)) xyz)
ā‡’
(0.9687111145512467 1.0 1.1210875945303613)
(define xyz (spectrum->XYZ (blackbody-spectrum 5000)))
(map (lambda (x) (/ x y_n)) xyz)
ā‡’
(0.2933441826889158 0.2988931825387761 0.25783646831201573)
[Function]spectrum->chromaticity proc
[Function]spectrum->chromaticity spectrum x1 x2
Computes the chromaticity for the given spectrum.
[Function]wavelength->XYZ w
w must be a number between 380e-9 to 780e-9. wavelength->XYZ returns (unnor-
malized) XYZ values for a monochromatic light source with wavelength w.
[Function]wavelength->chromaticity w
w must be a number between 380e-9 to 780e-9. wavelength->chromaticity returns
the chromaticity for a monochromatic light source with wavelength w.
[Function]blackbody-spectrum temp
[Function]blackbody-spectrum temp span
Returns a procedure of one argument (wavelength in meters), which returns the ra-
diance of a black body at temp.
The optional argument span is the wavelength analog of bandwidth. With the default
span of 1.nm (1e-9.m), the values returned by the procedure correspond to the power
of the photons with wavelengths w to w+1e-9.
[Function]temperature->XYZ x
The positive number x is a temperature in degrees kelvin. temperature->XYZ com-
putes the unnormalized CIEXYZ(1931) values for the spectrum of a black body at
temperature x.
Compute the chromaticities of 6500.K and 5000.K blackbody radiation:
(require ā€™color-space)
(XYZ->chromaticity (temperature->XYZ 6500))
ā‡’
(0.3135191660557008 0.3236456786200268)
(XYZ->chromaticity (temperature->XYZ 5000))
ā‡’
(0.34508082841161052 0.3516084965163377)
[Function]temperature->chromaticity x
The positive number x is a temperature in degrees kelvin. temperature->cromaticity
computes the chromaticity for the spectrum of a black body at temperature x.
Chapter 5: Mathematical Packages 144
Compute the chromaticities of 6500.K and 5000.K blackbody radiation:
(require ā€™color-space)
(temperature->chromaticity 6500)
ā‡’
(0.3135191660557008 0.3236456786200268)
(temperature->chromaticity 5000)
ā‡’
(0.34508082841161052 0.3516084965163377)
[Function]XYZ->chromaticity xyz
Returns a two element list: the x and y components of xyz normalized to 1 (= x + y
+ z).
[Function]chromaticity->CIEXYZ x y
Returns the list of x, and y, 1 - y - x.
[Function]chromaticity->whitepoint x y
Returns the CIEXYZ(1931) values having luminosity 1 and chromaticity x and y.
Many color datasets are expressed in xyY format; chromaticity with CIE luminance (Y).
But xyY is not a CIE standard like CIEXYZ, CIELAB, and CIELUV. Although chromi-
nance is well deļ¬ned, the luminance component is sometimes scaled to 1, sometimes to 100,
but usually has no obvious range. With no given whitepoint, the only reasonable course is
to ascertain the luminance range of a dataset and normalize the values to lie from 0 to 1.
[Function]XYZ->xyY xyz
Returns a three element list: the x and y components of XYZ normalized to 1, and
CIE luminance Y.
[Function]xyY->XYZ xyY
[Function]xyY:normalize-colors colors
colors is a list of xyY triples. xyY:normalize-colors scales each chromaticity so it
sums to 1 or less; and divides the Y values by the maximum Y in the dataset, so all
lie between 0 and 1.
[Function]xyY:normalize-colors colors n
If n is positive real, then xyY:normalize-colors divides the Y values by n times the
maximum Y in the dataset.
If n is an exact non-positive integer, then xyY:normalize-colors divides the Y
values by the maximum of the Y s in the dataset excepting the -n largest Y values.
In all cases, returned Y values are limited to lie from 0 to 1.
Why would one want to normalize to other than 1? If the sun or its reļ¬‚ection is the
brightest object in a scene, then normalizing to its luminance will tend to make the rest
of the scene very dark. As with photographs, limiting the specular highlights looks better
than darkening everything else.
The results of measurements being what they are, xyY:normalize-colors is extremely
tolerant. Negative numbers are replaced with zero, and chromaticities with sums greater
than one are scaled to sum to one.
Chapter 5: Mathematical Packages 145
5.11.4 Color Diļ¬€erence Metrics
(require ā€™color-space)
The low-level metric functions operate on lists of 3 numbers, lab1, lab2, lch1, or lch2.
(require ā€™color)
The wrapped functions operate on objects of type color, color1 and color2 in the func-
tion entries.
[Function]L*a*b*:DE* lab1 lab2
Returns the Euclidean distance between lab1 and lab2.
[Function]CIE:DE* color1 color2 white-point
[Function]CIE:DE* color1 color2
Returns the Euclidean distance in L*a*b* space between color1 and color2.
[Function]L*a*b*:DE*94 lab1 lab2 parametric-factors
[Function]L*a*b*:DE*94 lab1 lab2
[Function]CIE:DE*94 color1 color2 parametric-factors
[Function]CIE:DE*94 color1 color2
Measures distance in the L*a*b* color-space. The three axes are individually scaled
in their contributions to the total distance.
DE*94 is not symmetrical in its arguments. lab1 is the ā€œreferenceā€ color and lab2 is
the ā€œsampleā€ color.
The CIE has deļ¬ned reference conditions under which the metric with default param-
eters can be expected to perform well. These are:
ā€¢ The specimens are homogeneous in colour.
ā€¢ The colour diļ¬€erence (CIELAB) is <= 5 units.
ā€¢ They are placed in direct edge contact.
ā€¢ Each specimen subtends an angle of >4 degrees to the assessor, whose colour
vision is normal.
ā€¢ They are illuminated at 1000 lux, and viewed against a background of uniform
grey, with L* of 50, under illumination simulating D65.
The parametric-factors argument is a list of 3 quantities kL, kC and kH. parametric-
factors independently adjust each colour-diļ¬€erence term to account for any devia-
tions from the reference viewing conditions. Under the reference conditions explained
above, the default is kL = kC = kH = 1.
The Color Measurement Committee of The Society of Dyers and Colorists in Great Britain
created a more sophisticated color-distance function for use in judging the consistency of
dye lots. With CMC:DE* it is possible to use a single value pass/fail tolerance for all shades.
[Function]CMC-DE lch1 lch2 parametric-factors
[Function]CMC-DE lch1 lch2 l c
[Function]CMC-DE lch1 lch2 l
[Function]CMC-DE lch1 lch2
[Function]CMC:DE* color1 color2 l c
Chapter 5: Mathematical Packages 146
[Function]CMC:DE* color1 color2
CMC:DE is a L*C*h metric. The parametric-factors argument is a list of 2 numbers l
and c. l and c parameterize this metric. 1 and 1 are recommended for perceptibility;
the default, 2 and 1, for acceptability.
5.11.5 Color Conversions
This package contains the low-level color conversion and color metric routines operating on
lists of 3 numbers. There is no type or range checking.
(require ā€™color-space)
[Constant]CIEXYZ:D65
Is the color of 6500.K (blackbody) illumination. D65 is close to the average color of
daylight.
[Constant]CIEXYZ:D50
Is the color of 5000.K (blackbody) illumination. D50 is the color of indoor lighting
by incandescent bulbs.
[Constant]CIEXYZ:A
[Constant]CIEXYZ:B
[Constant]CIEXYZ:C
[Constant]CIEXYZ:E
CIE 1931 illuminants normalized to 1 = y.
[Function]color:linear-transform matrix row
[Function]CIEXYZ->RGB709 xyz
[Function]RGB709->CIEXYZ srgb
[Function]CIEXYZ->L*u*v* xyz white-point
[Function]CIEXYZ->L*u*v* xyz
[Function]L*u*v*->CIEXYZ L*u*v* white-point
[Function]L*u*v*->CIEXYZ L*u*v*
The white-point defaults to CIEXYZ:D65.
[Function]CIEXYZ->L*a*b* xyz white-point
[Function]CIEXYZ->L*a*b* xyz
[Function]L*a*b*->CIEXYZ L*a*b* white-point
[Function]L*a*b*->CIEXYZ L*a*b*
The XYZ white-point defaults to CIEXYZ:D65.
[Function]L*a*b*->L*C*h L*a*b*
[Function]L*C*h->L*a*b* L*C*h
[Function]CIEXYZ->sRGB xyz
[Function]sRGB->CIEXYZ srgb
[Function]CIEXYZ->xRGB xyz
[Function]xRGB->CIEXYZ srgb
[Function]sRGB->xRGB xyz
Chapter 5: Mathematical Packages 147
[Function]xRGB->sRGB srgb
[Function]CIEXYZ->e-sRGB n xyz
[Function]e-sRGB->CIEXYZ n srgb
[Function]sRGB->e-sRGB n srgb
[Function]e-sRGB->sRGB n srgb
The integer n must be 10, 12, or 16. Because sRGB and e-sRGB use the same RGB709
chromaticities, conversion between them is simpler than conversion through CIEXYZ.
Do not convert e-sRGB precision through e-sRGB->sRGB then sRGB->e-sRGB ā€“ values would
be truncated to 8-bits!
[Function]e-sRGB->e-sRGB n1 srgb n2
The integers n1 and n2 must be 10, 12, or 16. e-sRGB->e-sRGB converts srgb to
e-sRGB of precision n2.
5.11.6 Color Names
(require ā€™color-names)
Rather than ballast the color dictionaries with numbered grays, file->color-dictionary
discards them. They are provided through the grey procedure:
[Function]grey k
Returns (inexact->exact (round (* k 2.55))), the X11 color grey<k>.
A color dictionary is a database table relating canonical color-names to color-strings (see
Section 5.11.1 [Color Data-Type], page 134).
The column names in a color dictionary are unimportant; the ļ¬rst ļ¬eld is the key, and the
second is the color-string.
[Function]color-name:canonicalize name
Returns a downcased copy of the string or symbol name with ā€˜_ā€™, ā€˜-ā€™, and whitespace
removed.
[Function]color-name->color name table1 table2 . . .
table1, table2, . . . must be color-dictionary tables. color-name->color searches for
the canonical form of name in table1, table2, . . . in order; returning the color-string
of the ļ¬rst matching record; #f otherwise.
[Function]color-dictionaries->lookup table1 table2 . . .
table1, table2, . . . must be color-dictionary tables. color-dictionaries->lookup
returns a procedure which searches for the canonical form of its string argument in
table1, table2, . . . ; returning the color-string of the ļ¬rst matching record; and #f
otherwise.
[Function]color-dictionary name rdb base-table-type
rdb must be a string naming a relational database ļ¬le; and the symbol name a table
therein. The database will be opened as base-table-type. color-dictionary returns
the read-only table name in database name if it exists; #f otherwise.
Chapter 5: Mathematical Packages 148
[Function]color-dictionary name rdb
rdb must be an open relational database or a string naming a relational database ļ¬le;
and the symbol name a table therein. color-dictionary returns the read-only table
name in database name if it exists; #f otherwise.
[Function]load-color-dictionary name rdb base-table-type
[Function]load-color-dictionary name rdb
rdb must be a string naming a relational database ļ¬le; and the symbol name a table
therein. If the symbol base-table-type is provided, the database will be opened as
base-table-type. load-color-dictionary creates a top-level deļ¬nition of the symbol
name to a lookup procedure for the color dictionary name in rdb.
The value returned by load-color-dictionary is unspeciļ¬ed.
Dictionary Creation
(require ā€™color-database)
[Function]file->color-dictionary ļ¬le table-name rdb base-table-type
[Function]file->color-dictionary ļ¬le table-name rdb
rdb must be an open relational database or a string naming a relational database
ļ¬le, table-name a symbol, and the string ļ¬le must name an existing ļ¬le with color-
names and their corresponding xRGB (6-digit hex) values. file->color-dictionary
creates a table table-name in rdb and enters the associations found in ļ¬le into it.
[Function]url->color-dictionary url table-name rdb base-table-type
[Function]url->color-dictionary url table-name rdb
rdb must be an open relational database or a string naming a relational database ļ¬le
and table-name a symbol. url->color-dictionary retrieves the resource named by
the string url using the wget program; then calls file->color-dictionary to enter
its associations in table-name in url.
This section has detailed the procedures for creating and loading color dictionaries. So
where are the dictionaries to load?
http://people.csail.mit.edu/jaffer/Color/Dictionaries.html
Describes and evaluates several color-name dictionaries on the web. The following procedure
creates a database containing two of these dictionaries.
[Function]make-slib-color-name-db
Creates an alist-table relational database in library-vicinity containing the Resene
and saturate color-name dictionaries.
If the ļ¬les resenecolours.txt, nbs-iscc.txt, and saturate.txt exist in the
library-vicinity, then they used as the source of color-name data. Otherwise,
make-slib-color-name-db calls url->color-dictionary with the URLs of appropriate
source ļ¬les.
The Short List
(require ā€™saturate)
Chapter 5: Mathematical Packages 149
[Function]saturate name
Looks for name among the 19 saturated colors from Approximate Colors on CIE
Chromaticity Diagram:
reddish orange orange yellowish orange yellow
greenish yellow yellow green yellowish green green
bluish green blue green greenish blue blue
purplish blue bluish purple purple reddish purple
red purple purplish red red
(http://people.csail.mit .edu/jaffer/Color/saturate.pdf). If name is found,
the corresponding color is returned. Otherwise #f is returned. Use saturate only for
light source colors.
Resene Paints Limited, New Zealandā€™s largest privately-owned and operated paint manu-
facturing company, has generously made their Resene RGB Values List available.
(require ā€™resene)
[Function]resene name
Looks for name among the 1300 entries in the Resene color-name dictionary (http://
people.csail.mit.edu/jaffer/Color/resene.pdf). If name is found, the corre-
sponding color is returned. Otherwise #f is returned. The Resene RGB Values List
is an excellent source for surface colors.
If you include the Resene RGB Values List in binary form in a program, then you must
include its license with your program:
Resene RGB Values List
For further information refer to http://www.resene.co.nz
Copyright Resene Paints Ltd 2001
Permission to copy this dictionary, to modify it, to redistribute it, to distribute
modiļ¬ed versions, and to use it for any purpose is granted, subject to the
following restrictions and understandings.
1. Any text copy made of this dictionary must include this copyright notice
in full.
2. Any redistribution in binary form must reproduce this copyright notice in
the documentation or other materials provided with the distribution.
3. Resene Paints Ltd makes no warranty or representation that this dictionary
is error-free, and is under no obligation to provide any services, by way of
maintenance, update, or otherwise.
4. There shall be no use of the name of Resene or Resene Paints Ltd in any
advertising, promotional, or sales literature without prior written consent
in each case.
5. These RGB colour formulations may not be used to the detriment of Resene
Paints Ltd.
5.11.7 Daylight
(require ā€™daylight)
Chapter 5: Mathematical Packages 150
This package calculates the colors of sky as detailed in:
http://www.cs.utah.edu/vissim/papers/sunsky/sunsky.pdf
A Practical Analytic Model for Daylight
A. J. Preetham, Peter Shirley, Brian Smits
[Function]solar-hour julian-day hour
Returns the solar-time in hours given the integer julian-day in the range 1 to 366,
and the local time in hours.
To be meticulous, subtract 4 minutes for each degree of longitude west of the standard
meridian of your time zone.
[Function]solar-declination julian-day
[Function]solar-polar declination latitude solar-hour
Returns a list of theta s, the solar angle from the zenith, and phi s, the solar azimuth.
0 <= theta s measured in degrees. phi s is measured in degrees from due south; west
of south being positive.
In the following procedures, the number 0 <= theta s <= 90 is the solar angle from the
zenith in degrees.
Turbidity is a measure of the fraction of scattering due to haze as opposed to molecules.
This is a convenient quantity because it can be estimated based on visibility of distant
objects. This model fails for turbidity values less than 1.3.
_______________________________________________________________
512|-: |
| * pure-air |
256|-:** |
| : ** exceptionally-clear |
128|-: * |
| : ** |
64|-: * |
| : ** very-clear |
32|-: ** |
| : ** |
16|-: *** clear |
| : **** |
8|-: **** |
| : **** light-haze |
4|-: **** |
| : ****** |
2|-: ******** haze thin-|
| : *********** fog |
1|-:----------------------------------------------------*******--|
|_:____.____:____.____:____.____:____.____:____.____:____.____:_|
1 2 4 8 16 32 64
Meterorological range (km) versus Turbidity
Chapter 5: Mathematical Packages 151
[Function]sunlight-spectrum turbidity theta s
Returns a vector of 41 values, the spectrum of sunlight from 380.nm to 790.nm for a
given turbidity and theta s.
[Function]sunlight-chromaticity turbidity theta s
Given turbidity and theta s, sunlight-chromaticity returns the CIEXYZ triple for
color of sunlight scaled to be just inside the RGB709 gamut.
[Function]zenith-xyy turbidity theta s
Returns the xyY (chromaticity and luminance) at the zenith. The Luminance has
units kcd/m^2.
[Function]overcast-sky-color-xyy turbidity theta s
turbidity is a positive real number expressing the amount of light scattering. The
real number theta s is the solar angle from the zenith in degrees.
overcast-sky-color-xyy returns a function of one angle theta, the angle from the
zenith of the viewing direction (in degrees); and returning the xyY value for light
coming from that elevation of the sky.
[Function]clear-sky-color-xyy turbidity theta s phi s
[Function]sky-color-xyy turbidity theta s phi s
turbidity is a positive real number expressing the amount of light scattering. The
real number theta s is the solar angle from the zenith in degrees. The real number
phi s is the solar angle from south.
clear-sky-color-xyy returns a function of two angles, theta and phi which specify
the angles from the zenith and south meridian of the viewing direction (in degrees);
returning the xyY value for light coming from that direction of the sky.
sky-color-xyY calls overcast-sky-color-xyY for turbidity <= 20; otherwise the
clear-sky-color-xyy function.
5.12 Root Finding
(require ā€™root)
In the Newton method, divide the df/dx argument by the multiplicity of the desired
root in order to preserve quadratic convergence.
[Function]newton:find-integer-root f df/dx x0
Given integer valued procedure f, its derivative (with respect to its argument) df/dx,
and initial integer value x0 for which df/dx(x0) is non-zero, returns an integer x for
which f (x) is closer to zero than either of the integers adjacent to x; or returns #f if
such an integer canā€™t be found.
To ļ¬nd the closest integer to a given integerā€™s square root:
(define (integer-sqrt y)
(newton:find-integer-root
(lambda (x) (- (* x x) y))
(lambda (x) (* 2 x))
(ash 1 (quotient (integer-length y) 2))))
Chapter 5: Mathematical Packages 152
(integer-sqrt 15)
ā‡’
4
[Function]newton:find-root f df/dx x0 prec
Given real valued procedures f, df/dx of one (real) argument, initial real value x0
for which df/dx(x0) is non-zero, and positive real number prec, returns a real x for
which abs(f (x)) is less than prec; or returns #f if such a real canā€™t be found.
If prec is instead a negative integer, newton:find-root returns the result of -prec
iterations.
H. J. Orchard, The Laguerre Method for Finding the Zeros of Polynomials, IEEE Transac-
tions on Circuits and Systems, Vol. 36, No. 11, November 1989, pp 1377-1381.
There are 2 errors in Orchardā€™s Table II. Line k=2 for starting value of 1000+j0
should have Z k of 1.0475 + j4.1036 and line k=2 for starting value of 0+j1000
should have Z k of 1.0988 + j4.0833.
[Function]laguerre:find-root f df/dz ddf/dz^2 z0 prec
Given complex valued procedure f of one (complex) argument, its derivative (with re-
spect to its argument) df/dx, its second derivative ddf/dz^2, initial complex value z0,
and positive real number prec, returns a complex number z for which magnitude(f (z))
is less than prec; or returns #f if such a number canā€™t be found.
If prec is instead a negative integer, laguerre:find-root returns the result of -prec
iterations.
[Function]laguerre:find-polynomial-root deg f df/dz ddf/dz^2 z0 prec
Given polynomial procedure f of integer degree deg of one argument, its derivative
(with respect to its argument) df/dx, its second derivative ddf/dz^2, initial com-
plex value z0, and positive real number prec, returns a complex number z for which
magnitude(f (z)) is less than prec; or returns #f if such a number canā€™t be found.
If prec is instead a negative integer, laguerre:find-polynomial-root returns the
result of -prec iterations.
[Function]secant:find-root f x0 x1 prec
[Function]secant:find-bracketed-root f x0 x1 prec
Given a real valued procedure f and two real valued starting points x0 and x1, returns
a real x for which (abs (f x)) is less than prec; or returns #f if such a real canā€™t be
found.
If x0 and x1 are chosen such that they bracket a root, that is
(or (< (f x0) 0 (f x1))
(< (f x1) 0 (f x0)))
then the root returned will be between x0 and x1, and f will not be passed an
argument outside of that interval.
secant:find-bracketed-root will return #f unless x0 and x1 bracket a root.
The secant method is used until a bracketing interval is found, at which point a
modiļ¬ed regula falsi method is used.
Chapter 5: Mathematical Packages 153
If prec is instead a negative integer, secant:find-root returns the result of -prec
iterations.
If prec is a procedure it should accept 5 arguments: x0 f0 x1 f1 and count, where f0
will be (f x0), f1 (f x1), and count the number of iterations performed so far. prec
should return non-false if the iteration should be stopped.
5.13 Minimizing
(require ā€™minimize)
The Golden Section Search
3
algorithm ļ¬nds minima of functions which are expensive
to compute or for which derivatives are not available. Although optimum for the general
case, convergence is slow, requiring nearly 100 iterations for the example (x^3-2x-5).
If the derivative is available, Newton-Raphson is probably a better choice. If the
function is inexpensive to compute, consider approximating the derivative.
[Function]golden-section-search f x0 x1 prec
x 0 are x 1 real numbers. The (single argument) procedure f is unimodal over the
open interval (x 0, x 1). That is, there is exactly one point in the interval for which
the derivative of f is zero.
golden-section-search returns a pair (x . f (x)) where f (x) is the minimum. The
prec parameter is the stop criterion. If prec is a positive number, then the iteration
continues until x is within prec from the true value. If prec is a negative integer, then
the procedure will iterate -prec times or until convergence. If prec is a procedure of
seven arguments, x0, x1, a, b, fa, fb, and count, then the iterations will stop when
the procedure returns #t.
Analytically, the minimum of x^3-2x-5 is 0.816497.
(define func (lambda (x) (+ (* x (+ (* x x) -2)) -5)))
(golden-section-search func 0 1 (/ 10000))
==> (816.4883855245578e-3 . -6.0886621077391165)
(golden-section-search func 0 1 -5)
==> (819.6601125010515e-3 . -6.088637561916407)
(golden-section-search func 0 1
(lambda (a b c d e f g ) (= g 500)))
==> (816.4965933140557e-3 . -6.088662107903635)
5.14 The Limit
[library procedure]limit proc x1 x2 k
[library procedure]limit proc x1 x2
Proc must be a procedure taking a single inexact real argument. K is the number of
points on which proc will be called; it defaults to 8.
If x1 is ļ¬nite, then Proc must be continuous on the half-open interval:
3
David Kahaner, Cleve Moler, and Stephen Nash Numerical Methods and Software Prentice-Hall, 1989,
ISBN 0-13-627258-4
Chapter 5: Mathematical Packages 154
( x1 .. x1+x2 ]
And x2 should be chosen small enough so that proc is expected to be monotonic or
constant on arguments between x1 and x1 + x2.
Limit computes the limit of proc as its argument approaches x1 from x1 + x2. Limit
returns a real number or real inļ¬nity or ā€˜#fā€™.
If x1 is not ļ¬nite, then x2 must be a ļ¬nite nonzero real with the same sign as x1; in
which case limit returns:
(limit (lambda (x) (proc (/ x))) 0.0 (/ x2) k)
Limit examines the magnitudes of the diļ¬€erences between successive values returned
by proc called with a succession of numbers from x1+x2/k to x1.
If the magnitudes of diļ¬€erences are monotonically decreasing, then then the limit is
extrapolated from the degree n polynomial passing through the samples returned by
proc.
If the magnitudes of diļ¬€erences are increasing as fast or faster than a hyperbola
matching at x1+x2, then a real inļ¬nity with sign the same as the diļ¬€erences is re-
turned.
If the magnitudes of diļ¬€erences are increasing more slowly than the hyperbola match-
ing at x1+x2, then the limit is extrapolated from the quadratic passing through the
three samples closest to x1.
If the magnitudes of diļ¬€erences are not monotonic or are not completely within one
of the above categories, then #f is returned.
;; constant
(limit (lambda (x) (/ x x)) 0 1.0e-9) ==> 1.0
(limit (lambda (x) (expt 0 x)) 0 1.0e-9) ==> 0.0
(limit (lambda (x) (expt 0 x)) 0 -1.0e-9) ==> +inf.0
;; linear
(limit + 0 976.5625e-6) ==> 0.0
(limit - 0 976.5625e-6) ==> 0.0
;; vertical point of inflection
(limit sqrt 0 1.0e-18) ==> 0.0
(limit (lambda (x) (* x (log x))) 0 1.0e-9) ==> -102.70578127633066e-12
(limit (lambda (x) (/ x (log x))) 0 1.0e-9) ==> 96.12123142321669e-15
;; limits tending to infinity
(limit + +inf.0 1.0e9) ==> +inf.0
(limit + -inf.0 -1.0e9) ==> -inf.0
(limit / 0 1.0e-9) ==> +inf.0
(limit / 0 -1.0e-9) ==> -inf.0
(limit (lambda (x) (/ (log x) x)) 0 1.0e-9) ==> -inf.0
(limit (lambda (x) (/ (magnitude (log x)) x)) 0 -1.0e-9)
==> -inf.0
;; limit doesnā€™t exist
(limit sin +inf.0 1.0e9) ==> #f
(limit (lambda (x) (sin (/ x))) 0 1.0e-9) ==> #f
Chapter 5: Mathematical Packages 155
(limit (lambda (x) (sin (/ x))) 0 -1.0e-9) ==> #f
(limit (lambda (x) (/ (log x) x)) 0 -1.0e-9) ==> #f
;; conditionally convergent - return #f
(limit (lambda (x) (/ (sin x) x)) +inf.0 1.0e222)
==> #f
;; asymptotes
(limit / -inf.0 -1.0e222) ==> 0.0
(limit / +inf.0 1.0e222) ==> 0.0
(limit (lambda (x) (expt x x)) 0 1.0e-18) ==> 1.0
(limit (lambda (x) (sin (/ x))) +inf.0 1.0e222) ==> 0.0
(limit (lambda (x) (/ (+ (exp (/ x)) 1))) 0 1.0e-9)
==> 0.0
(limit (lambda (x) (/ (+ (exp (/ x)) 1))) 0 -1.0e-9)
==> 1.0
(limit (lambda (x) (real-part (expt (tan x) (cos x)))) (/ pi 2) 1.0e-9)
==> 1.0
;; This example from the 1979 Macsyma manual grows so rapidly
;; that x2 must be less than 41. It correctly returns e^2.
(limit (lambda (x) (expt (+ x (exp x) (exp (* 2 x))) (/ x))) +inf.0 40)
==> 7.3890560989306504
;; LIMIT can calculate the proper answer when evaluation
;; of the function at the limit point does not:
(tan (atan +inf.0)) ==> 16.331778728383844e15
(limit tan (atan +inf.0) -1.0e-15) ==> +inf.0
(tan (atan +inf.0)) ==> 16.331778728383844e15
(limit tan (atan +inf.0) 1.0e-15) ==> -inf.0
((lambda (x) (expt (exp (/ -1 x)) x)) 0) ==> 1.0
(limit (lambda (x) (expt (exp (/ -1 x)) x)) 0 1.0e-9)
==> 0.0
5.15 Commutative Rings
Scheme provides a consistent and capable set of numeric functions. Inexacts implement a
ļ¬eld; integers a commutative ring (and Euclidean domain). This package allows one to use
basic Scheme numeric functions with symbols and non-numeric elements of commutative
rings.
(require ā€™commutative-ring)
The commutative-ring package makes the procedures +, -, *, /, and ^ careful in the
sense that any non-numeric arguments they do not reduce appear in the expression output.
In order to see what working with this package is like, self-set all the single letter identiļ¬ers
(to their corresponding symbols).
(define a ā€™a)
...
(define z ā€™z)
Or just (require ā€™self-set). Now try some sample expressions:
Chapter 5: Mathematical Packages 156
(+ (+ a b) (- a b))
ā‡’
(* a 2)
(* (+ a b) (+ a b))
ā‡’
(^ (+ a b) 2)
(* (+ a b) (- a b))
ā‡’
(* (+ a b) (- a b))
(* (- a b) (- a b))
ā‡’
(^ (- a b) 2)
(* (- a b) (+ a b))
ā‡’
(* (+ a b) (- a b))
(/ (+ a b) (+ c d))
ā‡’
(/ (+ a b) (+ c d))
(^ (+ a b) 3)
ā‡’
(^ (+ a b) 3)
(^ (+ a 2) 3)
ā‡’
(^ (+ 2 a) 3)
Associative rules have been applied and repeated addition and multiplication converted
to multiplication and exponentiation.
We can enable distributive rules, thus expanding to sum of products form:
(set! *ruleset* (combined-rulesets distribute* distribute/))
(* (+ a b) (+ a b))
ā‡’
(+ (* 2 a b) (^ a 2) (^ b 2))
(* (+ a b) (- a b))
ā‡’
(- (^ a 2) (^ b 2))
(* (- a b) (- a b))
ā‡’
(- (+ (^ a 2) (^ b 2)) (* 2 a b))
(* (- a b) (+ a b))
ā‡’
(- (^ a 2) (^ b 2))
(/ (+ a b) (+ c d))
ā‡’
(+ (/ a (+ c d)) (/ b (+ c d)))
(/ (+ a b) (- c d))
ā‡’
(+ (/ a (- c d)) (/ b (- c d)))
(/ (- a b) (- c d))
ā‡’
(- (/ a (- c d)) (/ b (- c d)))
(/ (- a b) (+ c d))
ā‡’
(- (/ a (+ c d)) (/ b (+ c d)))
(^ (+ a b) 3)
ā‡’
(+ (* 3 a (^ b 2)) (* 3 b (^ a 2)) (^ a 3) (^ b 3))
(^ (+ a 2) 3)
ā‡’
(+ 8 (* a 12) (* (^ a 2) 6) (^ a 3))
Use of this package is not restricted to simple arithmetic expressions:
(require ā€™determinant)
(determinant ā€™((a b c) (d e f) (g h i)))
ā‡’
(- (+ (* a e i) (* b f g) (* c d h)) (* a f h) (* b d i) (* c e g))
Currently, only +, -, *, /, and ^ support non-numeric elements. Expressions with - are
converted to equivalent expressions without -, so behavior for - is not deļ¬ned separately.
/ expressions are handled similarly.
This list might be extended to include quotient, modulo, remainder, lcm, and gcd;
but these work only for the more restrictive Euclidean (Unique Factorization) Domain.
5.16 Rules and Rulesets
The commutative-ring package allows control of ring properties through the use of rulesets.
[Variable]*ruleset*
Contains the set of rules currently in eļ¬€ect. Rules deļ¬ned by cring:define-rule
are stored within the value of *ruleset* at the time cring:define-rule is called. If
*ruleset* is #f, then no rules apply.
Chapter 5: Mathematical Packages 157
[Function]make-ruleset rule1 . . .
[Function]make-ruleset name rule1 . . .
Returns a new ruleset containing the rules formed by applying cring:define-rule
to each 4-element list argument rule. If the ļ¬rst argument to make-ruleset is a
symbol, then the database table created for the new ruleset will be named name.
Calling make-ruleset with no rule arguments creates an empty ruleset.
[Function]combined-rulesets ruleset1 . . .
[Function]combined-rulesets name ruleset1 . . .
Returns a new ruleset containing the rules contained in each ruleset argument ruleset.
If the ļ¬rst argument to combined-ruleset is a symbol, then the database table
created for the new ruleset will be named name. Calling combined-ruleset with no
ruleset arguments creates an empty ruleset.
Two rulesets are deļ¬ned by this package.
[Constant]distribute*
Contains the ruleset to distribute multiplication over addition and subtraction.
[Constant]distribute/
Contains the ruleset to distribute division over addition and subtraction.
Take care when using both distribute* and distribute/ simultaneously. It is possible
to put / into an inļ¬nite loop.
You can specify how sum and product expressions containing non-numeric elements
simplify by specifying the rules for + or * for cases where expressions involving objects
reduce to numbers or to expressions involving diļ¬€erent non-numeric elements.
[Function]cring:define-rule op sub-op1 sub-op2 reduction
Deļ¬nes a rule for the case when the operation represented by symbol op is applied
to lists whose cars are sub-op1 and sub-op2, respectively. The argument reduction
is a procedure accepting 2 arguments which will be lists whose cars are sub-op1 and
sub-op2.
[Function]cring:define-rule op sub-op1 ā€™identity reduction
Deļ¬nes a rule for the case when the operation represented by symbol op is applied to
a list whose car is sub-op1, and some other argument. Reduction will be called with
the list whose car is sub-op1 and some other argument.
If reduction returns #f, the reduction has failed and other reductions will be tried.
If reduction returns a non-false value, that value will replace the two arguments in
arithmetic (+, -, and *) calculations involving non-numeric elements.
The operations + and * are assumed commutative; hence both orders of arguments
to reduction will be tried if necessary.
The following rule is the deļ¬nition for distributing * over +.
(cring:define-rule
ā€™* ā€™+ ā€™identity
(lambda (exp1 exp2)
(apply + (map (lambda (trm) (* trm exp2)) (cdr exp1))))))
Chapter 5: Mathematical Packages 158
5.17 How to Create a Commutative Ring
The ļ¬rst step in creating your commutative ring is to write procedures to create elements of
the ring. A non-numeric element of the ring must be represented as a list whose ļ¬rst element
is a symbol or string. This ļ¬rst element identiļ¬es the type of the object. A convenient and
clear convention is to make the type-identifying element be the same symbol whose top-level
value is the procedure to create it.
(define (n . list1)
(cond ((and (= 2 (length list1))
(eq? (car list1) (cadr list1)))
0)
((not (term< (first list1) (last1 list1)))
(apply n (reverse list1)))
(else (cons ā€™n list1))))
(define (s x y) (n x y))
(define (m . list1)
(cond ((neq? (first list1) (term_min list1))
(apply m (cyclicrotate list1)))
((term< (last1 list1) (cadr list1))
(apply m (reverse (cyclicrotate list1))))
(else (cons ā€™m list1))))
Deļ¬ne a procedure to multiply 2 non-numeric elements of the ring. Other multipli-
catons are handled automatically. Objects for which rules have not been deļ¬ned are not
changed.
(define (n*n ni nj)
(let ((list1 (cdr ni)) (list2 (cdr nj)))
(cond ((null? (intersection list1 list2)) #f)
((and (eq? (last1 list1) (first list2))
(neq? (first list1) (last1 list2)))
(apply n (splice list1 list2)))
((and (eq? (first list1) (first list2))
(neq? (last1 list1) (last1 list2)))
(apply n (splice (reverse list1) list2)))
((and (eq? (last1 list1) (last1 list2))
(neq? (first list1) (first list2)))
(apply n (splice list1 (reverse list2))))
((and (eq? (last1 list1) (first list2))
(eq? (first list1) (last1 list2)))
(apply m (cyclicsplice list1 list2)))
((and (eq? (first list1) (first list2))
(eq? (last1 list1) (last1 list2)))
(apply m (cyclicsplice (reverse list1) list2)))
(else #f))))
Test the procedures to see if they work.
Chapter 5: Mathematical Packages 159
;;; where cyclicrotate(list) is cyclic rotation of the list one step
;;; by putting the first element at the end
(define (cyclicrotate list1)
(append (rest list1) (list (first list1))))
;;; and where term_min(list) is the element of the list which is
;;; first in the term ordering.
(define (term_min list1)
(car (sort list1 term<)))
(define (term< sym1 sym2)
(string<? (symbol->string sym1) (symbol->string sym2)))
(define first car)
(define rest cdr)
(define (last1 list1) (car (last-pair list1)))
(define (neq? obj1 obj2) (not (eq? obj1 obj2)))
;;; where splice is the concatenation of list1 and list2 except that their
;;; common element is not repeated.
(define (splice list1 list2)
(cond ((eq? (last1 list1) (first list2))
(append list1 (cdr list2)))
(else (slib:error ā€™splice list1 list2))))
;;; where cyclicsplice is the result of leaving off the last element of
;;; splice(list1,list2).
(define (cyclicsplice list1 list2)
(cond ((and (eq? (last1 list1) (first list2))
(eq? (first list1) (last1 list2)))
(butlast (splice list1 list2) 1))
(else (slib:error ā€™cyclicsplice list1 list2))))
(N*N (S a b) (S a b))
ā‡’
(m a b)
Then register the rule for multiplying type N objects by type N objects.
(cring:define-rule ā€™* ā€™N ā€™N N*N))
Now we are ready to compute!
(define (t)
(define detM
(+ (* (S g b)
(+ (* (S f d)
(- (* (S a f) (S d g)) (* (S a g) (S d f))))
(* (S f f)
(- (* (S a g) (S d d)) (* (S a d) (S d g))))
(* (S f g)
(- (* (S a d) (S d f)) (* (S a f) (S d d))))))
(* (S g d)
(+ (* (S f b)
(- (* (S a g) (S d f)) (* (S a f) (S d g))))
(* (S f f)
Chapter 5: Mathematical Packages 160
(- (* (S a b) (S d g)) (* (S a g) (S d b))))
(* (S f g)
(- (* (S a f) (S d b)) (* (S a b) (S d f))))))
(* (S g f)
(+ (* (S f b)
(- (* (S a d) (S d g)) (* (S a g) (S d d))))
(* (S f d)
(- (* (S a g) (S d b)) (* (S a b) (S d g))))
(* (S f g)
(- (* (S a b) (S d d)) (* (S a d) (S d b))))))
(* (S g g)
(+ (* (S f b)
(- (* (S a f) (S d d)) (* (S a d) (S d f))))
(* (S f d)
(- (* (S a b) (S d f)) (* (S a f) (S d b))))
(* (S f f)
(- (* (S a d) (S d b)) (* (S a b) (S d d))))))))
(* (S b e) (S c a) (S e c)
detM
))
(pretty-print (t))
a
(- (+ (m a c e b d f g)
(m a c e b d g f)
(m a c e b f d g)
(m a c e b f g d)
(m a c e b g d f)
(m a c e b g f d))
(* 2 (m a b e c) (m d f g))
(* (m a c e b d) (m f g))
(* (m a c e b f) (m d g))
(* (m a c e b g) (m d f)))
5.18 Matrix Algebra
(require ā€™determinant)
A Matrix can be either a list of lists (rows) or an array. Unlike linear-algebra texts, this
package uses 0-based coordinates.
[Function]matrix->lists matrix
Returns the list-of-lists form of matrix.
[Function]matrix->array matrix
Returns the array form of matrix.
[Function]determinant matrix
matrix must be a square matrix. determinant returns the determinant of matrix.
(require ā€™determinant)
161
(determinant ā€™((1 2) (3 4)))
ā‡’
-2
(determinant ā€™((1 2 3) (4 5 6) (7 8 9)))
ā‡’
0
[Function]transpose matrix
Returns a copy of matrix ļ¬‚ipped over the diagonal containing the 1,1 element.
[Function]matrix:sum m1 m2
Returns the element-wise sum of matricies m1 and m2.
[Function]matrix:difference m1 m2
Returns the element-wise diļ¬€erence of matricies m1 and m2.
[Function]matrix:product m1 m2
Returns the product of matrices m1 and m2.
[Function]matrix:product m1 z
Returns matrix m1 times scalar z.
[Function]matrix:product z m1
Returns matrix m1 times scalar z.
[Function]matrix:inverse matrix
matrix must be a square matrix. If matrix is singular, then matrix:inverse returns
#f; otherwise matrix:inverse returns the matrix:product inverse of matrix.
162
6 Database Packages
6.1 Relational Database
(require ā€™relational-database)
This package implements a database system inspired by the Relational Model (E. F.
Codd, A Relational Model of Data for Large Shared Data Banks). An SLIB relational
database implementation can be created from any Section 6.2.1 [Base Table], page 179,
implementation.
Why relational database? For motivations and design issues see
http://people.csail.mit.edu/jaffer/DBManifesto.html.
6.1.1 Using Databases
(require ā€™databases)
This enhancement wraps a utility layer on relational-database which provides:
ā€¢ Identiļ¬cation of open databases by ļ¬lename.
ā€¢ Automatic sharing of open (immutable) databases.
ā€¢ Automatic loading of base-table package when creating a database.
ā€¢ Detection and automatic loading of the appropriate base-table package when opening
a database.
ā€¢ Table and data deļ¬nition from Scheme lists.
Database Sharing
Auto-sharing refers to a call to the procedure open-database returning an already open
database (procedure), rather than opening the database ļ¬le a second time.
Note: Databases returned by open-database do not include wrappers applied
by packages like Section 6.1.4 [Embedded Commands], page 169. But wrapped
databases do work as arguments to these functions.
When a database is created, it is mutable by the creator and not auto-sharable. A database
opened mutably is also not auto-sharable. But any number of readers can (open) share a
non-mutable database ļ¬le.
This next set of procedures mirror the whole-database methods in Section 6.2.4 [Database
Operations], page 187. Except for create-database, each procedure will accept either a
ļ¬lename or database procedure for its ļ¬rst argument.
[Function]create-database ļ¬lename base-table-type
ļ¬lename should be a string naming a ļ¬le; or #f. base-table-type must be a sym-
bol naming a feature which can be passed to require. create-database returns a
new, open relational database (with base-table type base-table-type) associated with
ļ¬lename, or a new ephemeral database if ļ¬lename is #f.
create-database is the only run-time use of require in SLIB which crosses module
boundaries. When base-table-type is required by create-database; it adds an asso-
ciation of base-table-type with its relational-system procedure to mdbm:*databases*.
Chapter 6: Database Packages 163
alist-table is the default base-table type:
(require ā€™databases)
(define my-rdb (create-database "my.db" ā€™alist-table))
Only alist-table and base-table modules which have been required will dispatch
correctly from the open-database procedures. Therefore, either pass two arguments
to open-database, or require the base-table of your database ļ¬le uses before calling
open-database with one argument.
[Procedure]open-database! rdb base-table-type
Returns mutable open relational database or #f.
[Function]open-database rdb base-table-type
Returns an open relational database associated with rdb. The database will be opened
with base-table type base-table-type).
[Function]open-database rdb
Returns an open relational database associated with rdb. open-database will at-
tempt to deduce the correct base-table-type.
[Function]write-database rdb ļ¬lename
Writes the mutable relational-database rdb to ļ¬lename.
[Function]sync-database rdb
Writes the mutable relational-database rdb to the ļ¬lename it was opened with.
[Function]solidify-database rdb
Syncs rdb and makes it immutable.
[Function]close-database rdb
rdb will only be closed when the count of open-database - close-database calls
for rdb (and its ļ¬lename) is 0. close-database returns #t if successful; and #f
otherwise.
[Function]mdbm:report
Prints a table of open database ļ¬les. The columns are the base-table type, number
of opens, ā€˜!ā€™ for mutable, the ļ¬lename, and the lock certiļ¬cate (if locked).
(mdbm:report)
a
alist-table 003 /usr/local/lib/slib/clrnamdb.scm
alist-table 001 ! sdram.db [email protected]:1038628199
Opening Tables
[Function]open-table rdb table-name
rdb must be a relational database and table-name a symbol.
open-table returns a "methods" procedure for an existing relational table in rdb if
it exists and can be opened for reading, otherwise returns #f.
Chapter 6: Database Packages 164
[Procedure]open-table! rdb table-name
rdb must be a relational database and table-name a symbol.
open-table! returns a "methods" procedure for an existing relational table in rdb if
it exists and can be opened in mutable mode, otherwise returns #f.
Deļ¬ning Tables
[Function]define-domains rdb row5 . . .
Adds the domain rows row5 . . . to the ā€˜*domains-data*ā€™ table in rdb. The format
of the row is given in Section 6.2.2 [Catalog Representation], page 184.
(define-domains rdb ā€™(permittivity #f complex? c64 #f))
[Function]add-domain rdb row5
Use define-domains instead.
[Function]define-tables rdb spec-0 . . .
Adds tables as speciļ¬ed in spec-0 . . . to the open relational-database rdb. Each spec
has the form:
(<name> <descriptor-name> <descriptor-name> <rows>)
or
(<name> <primary-key-ļ¬elds> <other-ļ¬elds> <rows>)
where <name> is the table name, <descriptor-name> is the symbol name of a descriptor
table, <primary-key-ļ¬elds> and <other-ļ¬elds> describe the primary keys and other
ļ¬elds respectively, and <rows> is a list of data rows to be added to the table.
<primary-key-ļ¬elds> and <other-ļ¬elds> are lists of ļ¬eld descriptors of the form:
(<column-name> <domain>)
or
(<column-name> <domain> <column-integrity-rule>)
where <column-name> is the column name, <domain> is the domain of the column,
and <column-integrity-rule> is an expression whose value is a procedure of one argu-
ment (which returns #f to signal an error).
If <domain> is not a deļ¬ned domain name and it matches the name of this table or
an already deļ¬ned (in one of spec-0 . . .) single key ļ¬eld table, a foreign-key domain
will be created for it.
Listing Tables
[Function]list-table-definition rdb table-name
If symbol table-name exists in the open relational-database rdb, then returns a list of
the table-name, its primary key names and domains, its other key names and domains,
and the tableā€™s records (as lists). Otherwise, returns #f.
The list returned by list-table-definition, when passed as an argument to
define-tables, will recreate the table.
Chapter 6: Database Packages 165
6.1.2 Table Operations
These are the descriptions of the methods available from an open relational table. A method
is retrieved from a table by calling the table with the symbol name of the operation. For
example:
((plat ā€™get ā€™processor) ā€™djgpp)
ā‡’
i386
Some operations described below require primary key arguments. Primary keys arguments
are denoted key1 key2 . . .. It is an error to call an operation for a table which takes
primary key arguments with the wrong number of primary keys for that table.
[Operation on relational-table]get column-name
Returns a procedure of arguments key1 key2 . . . which returns the value for the
column-name column of the row associated with primary keys key1, key2 . . . if that
row exists in the table, or #f otherwise.
((plat ā€™get ā€™processor) ā€™djgpp)
ā‡’
i386
((plat ā€™get ā€™processor) ā€™be-os)
ā‡’
#f
6.1.2.1 Single Row Operations
The term row used below refers to a Scheme list of values (one for each column) in the order
speciļ¬ed in the descriptor (table) for this table. Missing values appear as #f. Primary keys
must not be missing.
[Operation on relational-table]row:insert
Adds the row row to this table. If a row for the primary key(s) speciļ¬ed by row
already exists in this table an error is signaled. The value returned is unspeciļ¬ed.
(define telephone-table-desc
((my-database ā€™create-table) ā€™telephone-table-desc))
(define ndrp (telephone-table-desc ā€™row:insert))
(ndrp ā€™(1 #t name #f string))
(ndrp ā€™(2 #f telephone
(lambda (d)
(and (string? d) (> (string-length d) 2)
(every
(lambda (c)
(memv c ā€™(#\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9
#\+ #\( #\space #\) #\-)))
(string->list d))))
string))
[Operation on relational-table]row:update
Returns a procedure of one argument, row, which adds the row, row, to this table. If
a row for the primary key(s) speciļ¬ed by row already exists in this table, it will be
overwritten. The value returned is unspeciļ¬ed.
[Operation on relational-table]row:retrieve
Returns a procedure of arguments key1 key2 . . . which returns the row associated
with primary keys key1, key2 . . . if it exists, or #f otherwise.
Chapter 6: Database Packages 166
((plat ā€™row:retrieve) ā€™linux)
ā‡’
(linux i386 linux gcc)
((plat ā€™row:retrieve) ā€™multics)
ā‡’
#f
[Operation on relational-table]row:remove
Returns a procedure of arguments key1 key2 . . . which removes and returns the row
associated with primary keys key1, key2 . . . if it exists, or #f otherwise.
[Operation on relational-table]row:delete
Returns a procedure of arguments key1 key2 . . . which deletes the row associated
with primary keys key1, key2 . . . if it exists. The value returned is unspeciļ¬ed.
6.1.2.2 Match-Keys
The (optional) match-key1 . . . arguments are used to restrict actions of a whole-table
operation to a subset of that table. Those procedures (returned by methods) which accept
match-key arguments will accept any number of match-key arguments between zero and
the number of primary keys in the table. Any unspeciļ¬ed match-key arguments default to
#f.
The match-key1 . . . restrict the actions of the table command to those records whose
primary keys each satisfy the corresponding match-key argument. The arguments and
their actions are:
#f The false value matches any key in the corresponding position.
an object of type procedure
This procedure must take a single argument, the key in the cor-
responding position. Any key for which the procedure returns a
non-false value is a match; Any key for which the procedure re-
turns a #f is not.
other values
Any other value matches only those keys equal? to it.
[Operation on relational-table]get* column-name
Returns a procedure of optional arguments match-key1 . . . which returns a list of the
values for the speciļ¬ed column for all rows in this table. The optional match-key1
. . . arguments restrict actions to a subset of the table.
((plat ā€™get* ā€™processor))
ā‡’
(i386 i8086 i386 i8086 i386 i386 i8086 m68000
m68000 m68000 m68000 m68000 powerpc)
((plat ā€™get* ā€™processor) #f)
ā‡’
(i386 i8086 i386 i8086 i386 i386 i8086 m68000
m68000 m68000 m68000 m68000 powerpc)
(define (a-key? key)
(char=? #\a (string-ref (symbol->string key) 0)))
((plat ā€™get* ā€™processor) a-key?)
ā‡’
Chapter 6: Database Packages 167
(m68000 m68000 m68000 m68000 m68000 powerpc)
((plat ā€™get* ā€™name) a-key?)
ā‡’
(atari-st-turbo-c atari-st-gcc amiga-sas/c-5.10
amiga-aztec amiga-dice-c aix)
6.1.2.3 Multi-Row Operations
[Operation on relational-table]row:retrieve*
Returns a procedure of optional arguments match-key1 . . . which returns a list of
all rows in this table. The optional match-key1 . . . arguments restrict actions to a
subset of the table. For details see See Section 6.1.2.2 [Match-Keys], page 166.
((plat ā€™row:retrieve*) a-key?)
ā‡’
((atari-st-turbo-c m68000 atari turbo-c)
(atari-st-gcc m68000 atari gcc)
(amiga-sas/c-5.10 m68000 amiga sas/c)
(amiga-aztec m68000 amiga aztec)
(amiga-dice-c m68000 amiga dice-c)
(aix powerpc aix -))
[Operation on relational-table]row:remove*
Returns a procedure of optional arguments match-key1 . . . which removes and returns
a list of all rows in this table. The optional match-key1 . . . arguments restrict actions
to a subset of the table.
[Operation on relational-table]row:delete*
Returns a procedure of optional arguments match-key1 . . . which Deletes all rows
from this table. The optional match-key1 . . . arguments restrict deletions to a subset
of the table. The value returned is unspeciļ¬ed. The descriptor table and catalog entry
for this table are not aļ¬€ected.
[Operation on relational-table]for-each-row
Returns a procedure of arguments proc match-key1 . . . which calls proc with each
row in this table. The optional match-key1 . . . arguments restrict actions to a subset
of the table. For details see See Section 6.1.2.2 [Match-Keys], page 166.
Note that row:insert* and row:update* do not use match-keys.
[Operation on relational-table]row:insert*
Returns a procedure of one argument, rows, which adds each row in the list of rows,
rows, to this table. If a row for the primary key speciļ¬ed by an element of rows
already exists in this table, an error is signaled. The value returned is unspeciļ¬ed.
[Operation on relational-table]row:update*
Returns a procedure of one argument, rows, which adds each row in the list of rows,
rows, to this table. If a row for the primary key speciļ¬ed by an element of rows
already exists in this table, it will be overwritten. The value returned is unspeciļ¬ed.
Chapter 6: Database Packages 168
6.1.2.4 Indexed Sequential Access Methods
Indexed Sequential Access Methods are a way of arranging database information so that
records can be accessed both by key and by key sequence (ordering). ISAM is not part of
Coddā€™s relational model.
Associative memory in B-Trees is an example of a database implementation which can
support a native key ordering. SLIBā€™s alist-table implementation uses sort to implement
for-each-row-in-order, but does not support isam-next and isam-prev.
The multi-primary-key ordering employed by these operations is the lexicographic collation
of those primary-key ļ¬elds in their given order. For example:
(12 a 34) < (12 a 36) < (12 b 1) < (13 a 0)
6.1.2.5 Sequential Index Operations
The following procedures are individually optional depending on the base-table implemem-
tation. If an operation is not supported, then calling the table with that operation symbol
will return false.
[Operation on relational-table]for-each-row-in-order
Returns a procedure of arguments proc match-key1 . . . which calls proc with each
row in this table in the (implementation-dependent) natural, repeatable ordering for
rows. The optional match-key1 . . . arguments restrict actions to a subset of the
table. For details see See Section 6.1.2.2 [Match-Keys], page 166.
[Operation on relational-table]isam-next
Returns a procedure of arguments key1 key2 . . . which returns the key-list identifying
the lowest record higher than key1 key2 . . . which is stored in the relational-table;
or false if no higher record is present.
[Operation on relational-table]isam-next column-name
The symbol column-name names a key ļ¬eld. In the list returned by isam-next, that
ļ¬eld, or a ļ¬eld to its left, will be changed. This allows one to skip over less signiļ¬cant
key ļ¬elds.
[Operation on relational-table]isam-prev
Returns a procedure of arguments key1 key2 . . . which returns the key-list identifying
the highest record less than key1 key2 . . . which is stored in the relational-table; or
false if no lower record is present.
[Operation on relational-table]isam-prev column-name
The symbol column-name names a key ļ¬eld. In the list returned by isam-next, that
ļ¬eld, or a ļ¬eld to its left, will be changed. This allows one to skip over less signiļ¬cant
key ļ¬elds.
For example, if a table has key ļ¬elds:
(col1 col2)
(9 5)
(9 6)
(9 7)
Chapter 6: Database Packages 169
(9 8)
(12 5)
(12 6)
(12 7)
Then:
((table ā€™isam-next) ā€™(9 5))
ā‡’
(9 6)
((table ā€™isam-next ā€™col2) ā€™(9 5))
ā‡’
(9 6)
((table ā€™isam-next ā€™col1) ā€™(9 5))
ā‡’
(12 5)
((table ā€™isam-prev) ā€™(12 7))
ā‡’
(12 6)
((table ā€™isam-prev ā€™col2) ā€™(12 7))
ā‡’
(12 6)
((table ā€™isam-prev ā€™col1) ā€™(12 7))
ā‡’
(9 8)
6.1.2.6 Table Administration
[Operation on relational-table]column-names
[Operation on relational-table]column-foreigns
[Operation on relational-table]column-domains
[Operation on relational-table]column-types
Return a list of the column names, foreign-key table names, domain names, or type
names respectively for this table. These 4 methods are diļ¬€erent from the others in
that the list is returned, rather than a procedure to obtain the list.
[Operation on relational-table]primary-limit
Returns the number of primary keys ļ¬elds in the relations in this table.
[Operation on relational-table]close-table
Subsequent operations to this table will signal an error.
6.1.3 Database Interpolation
(require ā€™database-interpolate)
Indexed sequential access methods allow ļ¬nding the keys (having associations) closest to a
given value. This facilitates the interpolation of associations between those in the table.
[Function]interpolate-from-table table column
Table should be a relational table with one numeric primary key ļ¬eld which supports
the isam-prev and isam-next operations. column should be a symbol or exact
positive integer designating a numerically valued column of table.
interpolate-from-table calculates and returns a value proportionally intermediate
between its values in the next and previous key records contained in table. For keys
larger than all the stored keys the value associated with the largest stored key is used.
For keys smaller than all the stored keys the value associated with the smallest stored
key is used.
6.1.4 Embedded Commands
(require ā€™database-commands)
This enhancement wraps a utility layer on relational-database which provides:
ā€¢ Automatic execution of initialization commands stored in database.
Chapter 6: Database Packages 170
ā€¢ Transparent execution of database commands stored in *commands* table in database.
When an enhanced relational-database is called with a symbol which matches a name
in the *commands* table, the associated procedure expression is evaluated and applied to
the enhanced relational-database. A procedure should then be returned which the user can
invoke on (optional) arguments.
The command *initialize* is special. If present in the *commands* table,
open-database or open-database! will return the value of the *initialize* command.
Notice that arbitrary code can be run when the *initialize* procedure is automatically
applied to the enhanced relational-database.
Note also that if you wish to shadow or hide from the user relational-database methods
described in Section 6.2.4 [Database Operations], page 187, this can be done by a dis-
patch in the closure returned by the *initialize* expression rather than by entries in the
*commands* table if it is desired that the underlying methods remain accessible to code in
the *commands* table.
6.1.4.1 Database Extension
[Function]wrap-command-interface rdb
Returns relational database rdb wrapped with additional commands deļ¬ned in its
*commands* table.
[Function]add-command-tables rdb
The relational database rdb must be mutable. add-command-tables adds a *com-
mand* table to rdb; then returns (wrap-command-interface rdb).
[Function]define-*commands* rdb spec-0 . . .
Adds commands to the *commands* table as speciļ¬ed in spec-0 . . . to the open
relational-database rdb. Each spec has the form:
((<name> <rdb>) "comment" <expression1> <expression2> ...)
or
((<name> <rdb>) <expression1> <expression2> ...)
where <name> is the command name, <rdb> is a formal passed the calling relational
database, "comment" describes the command, and <expression1>, <expression1>, . . .
are the body of the procedure.
define-*commands* adds to the *commands* table a command <name>:
(lambda (<name> <rdb>) <expression1> <expression2> ...)
[Function]open-command-database ļ¬lename
[Function]open-command-database ļ¬lename base-table-type
Returns an open enhanced relational database associated with ļ¬lename. The database
will be opened with base-table type base-table-type) if supplied. If base-table-type is
not supplied, open-command-database will attempt to deduce the correct base-table-
type. If the database can not be opened or if it lacks the *commands* table, #f is
returned.
Chapter 6: Database Packages 171
[Function]open-command-database! ļ¬lename
[Function]open-command-database! ļ¬lename base-table-type
Returns mutable open enhanced relational database . . .
[Function]open-command-database database
Returns database if it is an immutable relational database; #f otherwise.
[Function]open-command-database! database
Returns database if it is a mutable relational database; #f otherwise.
6.1.4.2 Command Intrinsics
Some commands are deļ¬ned in all extended relational-databases. The are called just like
Section 6.2.4 [Database Operations], page 187.
[Operation on relational-database]add-domain domain-row
Adds domain-row to the domains table if there is no row in the domains table asso-
ciated with key (car domain-row) and returns #t. Otherwise returns #f.
For the ļ¬elds and layout of the domain table, See Section 6.2.2 [Catalog Representa-
tion], page 184. Currently, these ļ¬elds are
ā€¢ domain-name
ā€¢ foreign-table
ā€¢ domain-integrity-rule
ā€¢ type-id
ā€¢ type-param
The following example adds 3 domains to the ā€˜buildā€™ database. ā€˜Optstringā€™ is either
a string or #f. filename is a string and build-whats is a symbol.
(for-each (build ā€™add-domain)
ā€™((optstring #f
(lambda (x) (or (not x) (string? x)))
string
#f)
(filename #f #f string #f)
(build-whats #f #f symbol #f)))
[Operation on relational-database]delete-domain domain-name
Removes and returns the domain-name row from the domains table.
[Operation on relational-database]domain-checker domain
Returns a procedure to check an argument for conformance to domain domain.
6.1.4.3 Deļ¬ne-tables Example
The following example shows a new database with the name of foo.db being created with
tables describing processor families and processor/os/compiler combinations. The database
is then solidiļ¬ed; saved and changed to immutable.
(require ā€™databases)
Chapter 6: Database Packages 172
(define my-rdb (create-database "foo.db" ā€™alist-table))
(define-tables my-rdb
ā€™(processor-family
((family atom))
((also-ran processor-family))
((m68000 #f)
(m68030 m68000)
(i386 i8086)
(i8086 #f)
(powerpc #f)))
ā€™(platform
((name symbol))
((processor processor-family)
(os symbol)
(compiler symbol))
((aix powerpc aix -)
(amiga-dice-c m68000 amiga dice-c)
(amiga-aztec m68000 amiga aztec)
(amiga-sas/c-5.10 m68000 amiga sas/c)
(atari-st-gcc m68000 atari gcc)
(atari-st-turbo-c m68000 atari turbo-c)
(borland-c-3.1 i8086 ms-dos borland-c)
(djgpp i386 ms-dos gcc)
(linux i386 linux gcc)
(microsoft-c i8086 ms-dos microsoft-c)
(os/2-emx i386 os/2 gcc)
(turbo-c-2 i8086 ms-dos turbo-c)
(watcom-9.0 i386 ms-dos watcom))))
(solidify-database my-rdb)
6.1.4.4 The *commands* Table
The table *commands* in an enhanced relational-database has the ļ¬elds (with domains):
PRI name symbol
parameters parameter-list
procedure expression
documentation string
The parameters ļ¬eld is a foreign key (domain parameter-list) of the
*catalog-data* table and should have the value of a table described by
*parameter-columns*. This parameter-list table describes the arguments suitable for
passing to the associated command. The intent of this table is to be of a form such that
diļ¬€erent user-interfaces (for instance, pull-down menus or plain-text queries) can operate
from the same table. A parameter-list table has the following ļ¬elds:
Chapter 6: Database Packages 173
PRI index ordinal
name symbol
arity parameter-arity
domain domain
defaulter expression
expander expression
documentation string
The arity ļ¬eld can take the values:
single Requires a single parameter of the speciļ¬ed domain.
optional A single parameter of the speciļ¬ed domain or zero parameters is acceptable.
boolean A single boolean parameter or zero parameters (in which case #f is substituted)
is acceptable.
nary Any number of parameters of the speciļ¬ed domain are acceptable. The argu-
ment passed to the command function is always a list of the parameters.
nary1 One or more of parameters of the speciļ¬ed domain are acceptable. The argu-
ment passed to the command function is always a list of the parameters.
The domain ļ¬eld speciļ¬es the domain which a parameter or parameters in the indexth
ļ¬eld must satisfy.
The defaulter ļ¬eld is an expression whose value is either #f or a procedure of one
argument (the parameter-list) which returns a list of the default value or values as appro-
priate. Note that since the defaulter procedure is called every time a default parameter
is needed for this column, sticky defaults can be implemented using shared state with the
domain-integrity-rule.
6.1.4.5 Command Service
[Function]make-command-server rdb table-name
Returns a procedure of 2 arguments, a (symbol) command and a call-back procedure.
When this returned procedure is called, it looks up command in table table-name
and calls the call-back procedure with arguments:
command The command
command-value
The result of evaluating the expression in the procedure ļ¬eld of table-
name and calling it with rdb.
parameter-name
A list of the oļ¬ƒcial name of each parameter. Corresponds to the name
ļ¬eld of the commandā€™s parameter-table.
positions A list of the positive integer index of each parameter. Corresponds to the
index ļ¬eld of the commandā€™s parameter-table.
arities A list of the arities of each parameter. Corresponds to the arity ļ¬eld
of the commandā€™s parameter-table. For a description of arity see table
above.
Chapter 6: Database Packages 174
types A list of the type name of each parameter. Correspnds to the type-id
ļ¬eld of the contents of the domain of the commandā€™s parameter-table.
defaulters A list of the defaulters for each parameter. Corresponds to the
defaulters ļ¬eld of the commandā€™s parameter-table.
domain-integrity-rules
A list of procedures (one for each parameter) which tests whether a value
for a parameter is acceptable for that parameter. The procedure should
be called with each datum in the list for nary arity parameters.
aliases A list of lists of (alias parameter-name). There can be more than one
alias per parameter-name.
For information about parameters, See Section 4.4.4 [Parameter lists], page 62.
6.1.4.6 Command Example
Here is an example of setting up a command with arguments and parsing those arguments
from a getopt style argument list (see Section 4.4.1 [Getopt], page 58).
(require ā€™database-commands)
(require ā€™databases)
(require ā€™getopt-parameters)
(require ā€™parameters)
(require ā€™getopt)
(require ā€™fluid-let)
(require ā€™printf)
(define my-rdb (add-command-tables (create-database #f ā€™alist-table)))
(define-tables my-rdb
ā€™(foo-params
*parameter-columns*
*parameter-columns*
((1 single-string single string
(lambda (pl) ā€™("str")) #f "single string")
(2 nary-symbols nary symbol
(lambda (pl) ā€™()) #f "zero or more symbols")
(3 nary1-symbols nary1 symbol
(lambda (pl) ā€™(symb)) #f "one or more symbols")
(4 optional-number optional ordinal
(lambda (pl) ā€™()) #f "zero or one number")
(5 flag boolean boolean
(lambda (pl) ā€™(#f)) #f "a boolean flag")))
ā€™(foo-pnames
((name string))
((parameter-index ordinal))
(("s" 1)
("single-string" 1)
Chapter 6: Database Packages 175
("n" 2)
("nary-symbols" 2)
("N" 3)
("nary1-symbols" 3)
("o" 4)
("optional-number" 4)
("f" 5)
("flag" 5)))
ā€™(my-commands
((name symbol))
((parameters parameter-list)
(parameter-names parameter-name-translation)
(procedure expression)
(documentation string))
((foo
foo-params
foo-pnames
(lambda (rdb) (lambda args (print args)))
"test command arguments"))))
(define (dbutil:serve-command-line rdb command-table command argv)
(set! *argv* (if (vector? argv) (vector->list argv) argv))
((make-command-server rdb command-table)
command
(lambda (comname comval options positions
arities types defaulters dirs aliases)
(apply comval (getopt->arglist options positions
arities types defaulters dirs aliases)))))
(define (cmd . opts)
(fluid-let ((*optind* 1))
(printf "%-34s
ā‡’
"
(call-with-output-string
(lambda (pt) (write (cons ā€™cmd opts) pt))))
(set! opts (cons "cmd" opts))
(force-output)
(dbutil:serve-command-line
my-rdb ā€™my-commands ā€™foo (length opts) opts)))
(cmd)
ā‡’
("str" () (symb) () #f)
(cmd "-f")
ā‡’
("str" () (symb) () #t)
(cmd "--flag")
ā‡’
("str" () (symb) () #t)
(cmd "-o177")
ā‡’
("str" () (symb) (177) #f)
(cmd "-o" "177")
ā‡’
("str" () (symb) (177) #f)
(cmd "--optional" "621")
ā‡’
("str" () (symb) (621) #f)
(cmd "--optional=621")
ā‡’
("str" () (symb) (621) #f)
(cmd "-s" "speciality")
ā‡’
("speciality" () (symb) () #f)
Chapter 6: Database Packages 176
(cmd "-sspeciality")
ā‡’
("speciality" () (symb) () #f)
(cmd "--single" "serendipity")
ā‡’
("serendipity" () (symb) () #f)
(cmd "--single=serendipity")
ā‡’
("serendipity" () (symb) () #f)
(cmd "-n" "gravity" "piety")
ā‡’
("str" () (piety gravity) () #f)
(cmd "-ngravity" "piety")
ā‡’
("str" () (piety gravity) () #f)
(cmd "--nary" "chastity")
ā‡’
("str" () (chastity) () #f)
(cmd "--nary=chastity" "")
ā‡’
("str" () ( chastity) () #f)
(cmd "-N" "calamity")
ā‡’
("str" () (calamity) () #f)
(cmd "-Ncalamity")
ā‡’
("str" () (calamity) () #f)
(cmd "--nary1" "surety")
ā‡’
("str" () (surety) () #f)
(cmd "--nary1=surety")
ā‡’
("str" () (surety) () #f)
(cmd "-N" "levity" "fealty")
ā‡’
("str" () (fealty levity) () #f)
(cmd "-Nlevity" "fealty")
ā‡’
("str" () (fealty levity) () #f)
(cmd "--nary1" "surety" "brevity")
ā‡’
("str" () (brevity surety) () #f)
(cmd "--nary1=surety" "brevity")
ā‡’
("str" () (brevity surety) () #f)
(cmd "-?")
a
Usage: cmd [OPTION ARGUMENT ...] ...
-f, --flag
-o, --optional[=]<number>
-n, --nary[=]<symbols> ...
-N, --nary1[=]<symbols> ...
-s, --single[=]<string>
ERROR: getopt->parameter-list "unrecognized option" "-?"
6.1.5 Database Macros
(require ā€™within-database)
The object-oriented programming interface to SLIB relational databases has failed to
support clear, understandable, and modular code-writing for database applications.
This seems to be a failure of the object-oriented paradigm where the type of an object
is not manifest (or even traceable) in source code.
within-database, along with the ā€˜databasesā€™ package, reorganizes high-level database
functions toward a more declarative style. Using this package, one can tag database table
and command declarations for emacs:
etags -lscheme -rā€™/ *(define-\(command\|table\) (\([^; \t]+\)/\2/ā€™ \
source1.scm ...
6.1.5.1 Within-database
[Function]within-database database statement-1 . . .
within-database creates a lexical scope in which the commands define-table and
define-command create tables and *commands*-table entries respectively in open re-
lational database database. The expressions in ā€˜within-databaseā€™ form are executed
in order.
Chapter 6: Database Packages 177
within-database Returns database.
[Syntax]define-command (<name> <rdb>) "comment" <expression1> <expression2>
. . .
[Syntax]define-command (<name> <rdb>) <expression1> <expression2> . . .
Adds to the *commands* table a command <name>:
(lambda (<name> <rdb>) <expression1> <expression2> ...)
[Syntax]define-table <name> <descriptor-name> <descriptor-name> <rows>
[Syntax]define-table <name> <primary-key-ļ¬elds> <other-ļ¬elds> <rows>
where <name> is the table name, <descriptor-name> is the symbol name of a descriptor
table, <primary-key-ļ¬elds> and <other-ļ¬elds> describe the primary keys and other
ļ¬elds respectively, and <rows> is a list of data rows to be added to the table.
<primary-key-ļ¬elds> and <other-ļ¬elds> are lists of ļ¬eld descriptors of the form:
(<column-name> <domain>)
or
(<column-name> <domain> <column-integrity-rule>)
where <column-name> is the column name, <domain> is the domain of the column,
and <column-integrity-rule> is an expression whose value is a procedure of one argu-
ment (which returns #f to signal an error).
If <domain> is not a deļ¬ned domain name and it matches the name of this table or
an already deļ¬ned (in one of spec-0 . . .) single key ļ¬eld table, a foreign-key domain
will be created for it.
[Function]add-macro-support database
The relational database database must be mutable. add-macro-support adds a
*macros* table and define-macro macro to database; then database is returned.
[Syntax]define-macro (<name> arg1 . . .) "comment" <expression1> <expression2>
. . .
[Syntax]define-macro (<name> arg1 . . .) <expression1> <expression2> . . .
Adds a macro <name> to the *macros*.
Note: within-database creates lexical scope where not only define-command and
define-table, but every command and macro are deļ¬ned, ie.:
(within-database my-rdb
(define-command (message rdb)
(lambda (msg)
(display "message: ")
(display msg)
(newline)))
(message "Defining FOO...")
;; ... defining FOO ...
(message "Defining BAR...")
;; ... defining BAR ...
)
Chapter 6: Database Packages 178
6.1.5.2 Within-database Example
Here is an example of within-database macros:
(require ā€™within-database)
(define my-rdb
(add-command-tables
(create-database "foo.db" ā€™alist-table)))
(within-database my-rdb
(define-command (*initialize* rdb)
"Print Welcome"
(display "Welcome")
(newline)
rdb)
(define-command (without-documentation rdb)
(display "without-documentation called")
(newline))
(define-table (processor-family
((family atom))
((also-ran processor-family)))
(m68000 #f)
(m68030 m68000)
(i386 i8086)
(i8086 #f)
(powerpc #f))
(define-table (platform
((name symbol))
((processor processor-family)
(os symbol)
(compiler symbol)))
(aix powerpc aix -)
;; ...
(amiga-aztec m68000 amiga aztec)
(amiga-sas/c-5.10 m68000 amiga sas/c)
(atari-st-gcc m68000 atari gcc)
;; ...
(watcom-9.0 i386 ms-dos watcom))
(define-command (get-processor rdb)
"Get processor for given platform."
(((rdb ā€™open-table) ā€™platform #f) ā€™get ā€™processor)))
(close-database my-rdb)
(set! my-rdb (open-command-database! "foo.db"))
a
Welcome
Chapter 6: Database Packages 179
(my-rdb ā€™without-documentation)
a
without-documentation called
((my-rdb ā€™get-processor) ā€™amiga-sas/c-5.10)
ā‡’
m68000
(close-database my-rdb)
6.1.6 Database Browser
(require ā€™database-browse)
[Procedure]browse database
Prints the names of all the tables in database and sets browseā€™s default to database.
[Procedure]browse
Prints the names of all the tables in the default database.
[Procedure]browse table-name
For each record of the table named by the symbol table-name, prints a line composed
of all the ļ¬eld values.
[Procedure]browse pathname
Opens the database named by the string pathname, prints the names of all its tables,
and sets browseā€™s default to the database.
[Procedure]browse database table-name
Sets browseā€™s default to database and prints the records of the table named by the
symbol table-name.
[Procedure]browse pathname table-name
Opens the database named by the string pathname and sets browseā€™s default to it;
browse prints the records of the table named by the symbol table-name.
6.2 Relational Infrastructure
6.2.1 Base Table
A base-table is the primitive database layer upon which SLIB relational databases are
built. At the minimum, it must support the types integer, symbol, string, and boolean.
The base-table may restrict the size of integers, symbols, and strings it supports.
A base table implementation is available as the value of the identiļ¬er naming it (eg.
alist-table) after requiring the symbol of that name.
[Feature]alist-table
(require ā€™alist-table)
Chapter 6: Database Packages 180
Association-list base tables support all Scheme types and are suitable for small data-
bases. In order to be retrieved after being written to a ļ¬le, the data stored should
include only objects which are readable and writeable in the Scheme implementation.
The alist-table base-table implementation is included in the SLIB distribution.
WB is a B-tree database package with SCM interfaces. Being disk-based, WB databases
readily store and access hundreds of megabytes of data. WB comes with two base-table
embeddings.
[Feature]wb-table
(require ā€™wb-table)
wb-table supports scheme expressions for keys and values whose text representations
are less than 255 characters in length. See Section ā€œwb-tableā€ in WB.
[Feature]rwb-isam
(require ā€™rwb-isam)
rwb-isam is a sophisticated base-table implementation built on WB and SCM which
uses binary numerical formats for key and non-key ļ¬elds. It supports IEEE ļ¬‚oating-
point and ļ¬xed-precision integer keys with the correct numerical collation order.
This rest of this section documents the interface for a base table implementation from
which the Section 6.1 [Relational Database], page 162, package constructs a Relational
system. It will be of interest primarily to those wishing to port or write new base-table
implementations.
[Variable]*base-table-implementations*
To support automatic dispatch for open-database, each base-table module adds an
association to *base-table-implementations* when loaded. This association is the
list of the base-table symbol and the value returned by (make-relational-system
base-table).
6.2.1.1 The Base
All of these functions are accessed through a single procedure by calling that procedure
with the symbol name of the operation. A procedure will be returned if that operation is
supported and #f otherwise. For example:
(require ā€™alist-table)
(define my-base (alist-table ā€™make-base))
my-base
ā‡’
*a procedure*
(define foo (alist-table ā€™foo))
foo
ā‡’
#f
[Operation on base-table]make-base ļ¬lename key-dimension column-types
Returns a new, open, low-level database (collection of tables) associated with ļ¬lename.
This returned database has an empty table associated with catalog-id. The positive
integer key-dimension is the number of keys composed to make a primary-key for the
catalog table. The list of symbols column-types describes the types of each column
for that table. If the database cannot be created as speciļ¬ed, #f is returned.
Chapter 6: Database Packages 181
Calling the close-base method on this database and possibly other operations will
cause ļ¬lename to be written to. If ļ¬lename is #f a temporary, non-disk based database
will be created if such can be supported by the base table implelentation.
[Operation on base-table]open-base ļ¬lename mutable
Returns an open low-level database associated with ļ¬lename. If mutable is #t, this
database will have methods capable of eļ¬€ecting change to the database. If mutable is
#f, only methods for inquiring the database will be available. If the database cannot
be opened as speciļ¬ed #f is returned.
Calling the close-base (and possibly other) method on a mutable database will
cause ļ¬lename to be written to.
[Operation on base-table]write-base lldb ļ¬lename
Causes the low-level database lldb to be written to ļ¬lename. If the write is suc-
cessful, also causes lldb to henceforth be associated with ļ¬lename. Calling the
close-database (and possibly other) method on lldb may cause ļ¬lename to be writ-
ten to. If ļ¬lename is #f this database will be changed to a temporary, non-disk based
database if such can be supported by the underlying base table implelentation. If the
operations completed successfully, #t is returned. Otherwise, #f is returned.
[Operation on base-table]sync-base lldb
Causes the ļ¬le associated with the low-level database lldb to be updated to reļ¬‚ect its
current state. If the associated ļ¬lename is #f, no action is taken and #f is returned.
If this operation completes successfully, #t is returned. Otherwise, #f is returned.
[Operation on base-table]close-base lldb
Causes the low-level database lldb to be written to its associated ļ¬le (if any). If the
write is successful, subsequent operations to lldb will signal an error. If the operations
complete successfully, #t is returned. Otherwise, #f is returned.
6.2.1.2 Base Tables
[Operation on base-table]make-table lldb key-dimension column-types
Returns the ordinal base-id for a new base table, otherwise returns #f. The base
table can then be opened using (open-table lldb base-id). The positive integer
key-dimension is the number of keys composed to make a primary-key for this table.
The list of symbols column-types describes the types of each column.
[Operation on base-table]open-table lldb base-id key-dimension column-types
Returns a handle for an existing base table in the low-level database lldb if that table
exists and can be opened in the mode indicated by mutable, otherwise returns #f.
As with make-table, the positive integer key-dimension is the number of keys com-
posed to make a primary-key for this table. The list of symbols column-types de-
scribes the types of each column.
[Operation on base-table]kill-table lldb base-id key-dimension column-types
Returns #t if the base table associated with base-id was removed from the low level
database lldb, and #f otherwise.
Chapter 6: Database Packages 182
[Operation on base-table]catalog-id
A constant base-id ordinal suitable for passing as a parameter to open-table. catalog-
id will be used as the base table for the system catalog.
6.2.1.3 Base Field Types
[Operation on base-table]supported-type? symbol
Returns #t if symbol names a type allowed as a column value by the implementa-
tion, and #f otherwise. At a minimum, an implementation must support the types
integer, ordinal, symbol, string, and boolean.
[Operation on base-table]supported-key-type? symbol
Returns #t if symbol names a type allowed as a key value by the implementation, and
#f otherwise. At a minimum, an implementation must support the types ordinal,
and symbol.
An ordinal is an exact positive integer. The other types are standard Scheme.
6.2.1.4 Composite Keys
[Operation on base-table]make-keyifier-1 type
Returns a procedure which accepts a single argument which must be of type type.
This returned procedure returns an object suitable for being a key argument in the
functions whose descriptions follow.
Any 2 arguments of the supported type passed to the returned function which are
not equal? must result in returned values which are not equal?.
[Operation on base-table]make-list-keyifier key-dimension types
The list of symbols types must have at least key-dimension elements. Returns a proce-
dure which accepts a list of length key-dimension and whose types must corresopond
to the types named by types. This returned procedure combines the elements of its
list argument into an object suitable for being a key argument in the functions whose
descriptions follow.
Any 2 lists of supported types (which must at least include symbols and non-negative
integers) passed to the returned function which are not equal? must result in returned
values which are not equal?.
[Operation on base-table]make-key-extractor key-dimension types
column-number
Returns a procedure which accepts objects produced by application of the result of
(make-list-keyifier key-dimension types). This procedure returns a key which
is equal? to the column-numberth element of the list which was passed to create
composite-key. The list types must have at least key-dimension elements.
[Operation on base-table]make-key->list key-dimension types
Returns a procedure which accepts objects produced by application of the result of
(make-list-keyifier key-dimension types). This procedure returns a list of keys
which are elementwise equal? to the list which was passed to create composite-key.
Chapter 6: Database Packages 183
6.2.1.5 Base Record Operations
In the following functions, the key argument can always be assumed to be the value returned
by a call to a keyify routine.
[Operation on base-table]present? handle key
Returns a non-#f value if there is a row associated with key in the table opened in
handle and #f otherwise.
[Operation on base-table]make-getter key-dimension types
Returns a procedure which takes arguments handle and key. This procedure returns
a list of the non-primary values of the relation (in the base table opened in handle)
whose primary key is key if it exists, and #f otherwise.
make-getter-1 is a new operation. The relational-database module works with older base-
table implementations by using make-getter.
[Operation on base-table]make-getter-1 key-dimension types index
Returns a procedure which takes arguments handle and key. This procedure returns
the value of the indexth ļ¬eld (in the base table opened in handle) whose primary key
is key if it exists, and #f otherwise.
index must be larger than key-dimension.
[Operation on base-table]make-putter key-dimension types
Returns a procedure which takes arguments handle and key and value-list. This
procedure associates the primary key key with the values in value-list (in the base
table opened in handle) and returns an unspeciļ¬ed value.
[Operation on base-table]delete handle key
Removes the row associated with key from the table opened in handle. An unspeciļ¬ed
value is returned.
6.2.1.6 Match Keys
A match-keys argument is a list of length equal to the number of primary keys. The match-
keys restrict the actions of the table command to those records whose primary keys all
satisfy the corresponding element of the match-keys list. The elements and their actions
are:
#f The false value matches any key in the corresponding position.
an object of type procedure
This procedure must take a single argument, the key in the cor-
responding position. Any key for which the procedure returns a
non-false value is a match; Any key for which the procedure re-
turns a #f is not.
other values
Any other value matches only those keys equal? to it.
Chapter 6: Database Packages 184
6.2.1.7 Aggregate Base Operations
The key-dimension and column-types arguments are needed to decode the composite-keys
for matching with match-keys.
[Operation on base-table]delete* handle key-dimension column-types
match-keys
Removes all rows which satisfy match-keys from the table opened in handle. An
unspeciļ¬ed value is returned.
[Operation on base-table]for-each-key handle procedure key-dimension
column-types match-keys
Calls procedure once with each key in the table opened in handle which satisfy match-
keys in an unspeciļ¬ed order. An unspeciļ¬ed value is returned.
[Operation on base-table]map-key handle procedure key-dimension
column-types match-keys
Returns a list of the values returned by calling procedure once with each key in the
table opened in handle which satisfy match-keys in an unspeciļ¬ed order.
6.2.1.8 Base ISAM Operations
These operations are optional for a Base-Table implementation.
[Operation on base-table]ordered-for-each-key handle procedure
key-dimension column-types match-keys
Calls procedure once with each key in the table opened in handle which satisfy match-
keys in the natural order for the types of the primary key ļ¬elds of that table. An
unspeciļ¬ed value is returned.
[Operation on base-table]make-nexter handle key-dimension column-types
index
Returns a procedure of arguments key1 key2 . . . which returns the key-list identifying
the lowest record higher than key1 key2 . . . which is stored in the base-table and
which diļ¬€ers in column index or a lower indexed key; or false if no higher record is
present.
[Operation on base-table]make-prever handle key-dimension column-types
index
Returns a procedure of arguments key1 key2 . . . which returns the key-list identifying
the highest record less than key1 key2 . . . which is stored in the base-table and which
diļ¬€ers in column index or a lower indexed key; or false if no higher record is present.
6.2.2 Catalog Representation
Each database (in an implementation) has a system catalog which describes all the user
accessible tables in that database (including itself).
The system catalog base table has the following ļ¬elds. PRI indicates a primary key for that
table.
Chapter 6: Database Packages 185
PRI table-name
column-limit the highest column number
coltab-name descriptor table name
bastab-id data base table identifier
user-integrity-rule
view-procedure A scheme thunk which, when called,
produces a handle for the view. coltab
and bastab are specified if and only if
view-procedure is not.
Descriptors for base tables (not views) are tables (pointed to by system catalog). Descriptor
(base) tables have the ļ¬elds:
PRI column-number sequential integers from 1
primary-key? boolean TRUE for primary key components
column-name
column-integrity-rule
domain-name
A primary key is any column marked as primary-key? in the corresponding descriptor
table. All the primary-key? columns must have lower column numbers than any non-
primary-key? columns. Every table must have at least one primary key. Primary keys
must be suļ¬ƒcient to distinguish all rows from each other in the table. All of the system
deļ¬ned tables have a single primary key.
A domain is a category describing the allowable values to occur in a column. It is described
by a (base) table with the ļ¬elds:
PRI domain-name
foreign-table
domain-integrity-rule
type-id
type-param
The type-id ļ¬eld value is a symbol. This symbol may be used by the underlying base table
implementation in storing that ļ¬eld.
If the foreign-table ļ¬eld is non-#f then that ļ¬eld names a table from the catalog. The
values for that domain must match a primary key of the table referenced by the type-param
(or #f, if allowed). This package currently does not support composite foreign-keys.
The types for which support is planned are:
Chapter 6: Database Packages 186
atom
symbol
string [<length>]
number [<base>]
money <currency>
date-time
boolean
foreign-key <table-name>
expression
virtual <expression>
6.2.3 Relational Database Objects
This object-oriented interface is deprecated for typical database applications;
Section 6.1.1
[Using Databases], page 162, provides an application programmer interface which is easier
to understand and use.
[Function]make-relational-system base-table-implementation
Returns a procedure implementing a relational database using the base-table-
implementation.
All of the operations of a base table implementation are accessed through a procedure
deļ¬ned by requireing that implementation. Similarly, all of the operations of the
relational database implementation are accessed through the procedure returned by
make-relational-system. For instance, a new relational database could be created
from the procedure returned by make-relational-system by:
(require ā€™alist-table)
(define relational-alist-system
(make-relational-system alist-table))
(define create-alist-database
(relational-alist-system ā€™create-database))
(define my-database
(create-alist-database "mydata.db"))
What follows are the descriptions of the methods available from relational system returned
by a call to make-relational-system.
[Operation on relational-system]create-database ļ¬lename
Returns an open, nearly empty relational database associated with ļ¬lename. The only
tables deļ¬ned are the system catalog and domain table. Calling the close-database
method on this database and possibly other operations will cause ļ¬lename to be
written to. If ļ¬lename is #f a temporary, non-disk based database will be created if
such can be supported by the underlying base table implelentation. If the database
cannot be created as speciļ¬ed #f is returned. For the ļ¬elds and layout of descriptor
tables, Section 6.2.2 [Catalog Representation], page 184,
Chapter 6: Database Packages 187
[Operation on relational-system]open-database ļ¬lename mutable?
Returns an open relational database associated with ļ¬lename. If mutable? is #t, this
database will have methods capable of eļ¬€ecting change to the database. If muta-
ble? is #f, only methods for inquiring the database will be available. Calling the
close-database (and possibly other) method on a mutable? database will cause ļ¬le-
name to be written to. If the database cannot be opened as speciļ¬ed #f is returned.
6.2.4 Database Operations
This object-oriented interface is deprecated for typical database applications; Section 6.1.1
[Using Databases], page 162, provides an application programmer interface which is easier
to understand and use.
These are the descriptions of the methods available from an open relational database. A
method is retrieved from a database by calling the database with the symbol name of the
operation. For example:
(define my-database
(create-alist-database "mydata.db"))
(define telephone-table-desc
((my-database ā€™create-table) ā€™telephone-table-desc))
[Operation on relational-database]close-database
Causes the relational database to be written to its associated ļ¬le (if any). If the
write is successful, subsequent operations to this database will signal an error. If the
operations completed successfully, #t is returned. Otherwise, #f is returned.
[Operation on relational-database]write-database ļ¬lename
Causes the relational database to be written to ļ¬lename. If the write is success-
ful, also causes the database to henceforth be associated with ļ¬lename. Calling the
close-database (and possibly other) method on this database will cause ļ¬lename to
be written to. If ļ¬lename is #f this database will be changed to a temporary, non-disk
based database if such can be supported by the underlying base table implelentation.
If the operations completed successfully, #t is returned. Otherwise, #f is returned.
[Operation on relational-database]sync-database
Causes any pending updates to the database ļ¬le to be written out. If the operations
completed successfully, #t is returned. Otherwise, #f is returned.
[Operation on relational-database]solidify-database
Causes any pending updates to the database ļ¬le to be written out. If the writes
completed successfully, then the database is changed to be immutable and #t is
returned. Otherwise, #f is returned.
[Operation on relational-database]table-exists? table-name
Returns #t if table-name exists in the system catalog, otherwise returns #f.
[Operation on relational-database]open-table table-name mutable?
Returns a methods procedure for an existing relational table in this database if it
exists and can be opened in the mode indicated by mutable?, otherwise returns #f.
Chapter 6: Database Packages 188
These methods will be present only in mutable databases.
[Operation on relational-database]delete-table table-name
Removes and returns the table-name row from the system catalog if the table or view
associated with table-name gets removed from the database, and #f otherwise.
[Operation on relational-database]create-table table-desc-name
Returns a methods procedure for a new (open) relational table for describing the
columns of a new base table in this database, otherwise returns #f. For the ļ¬elds and
layout of descriptor tables, See Section 6.2.2 [Catalog Representation], page 184.
[Operation on relational-database]create-table table-name table-desc-name
Returns a methods procedure for a new (open) relational table with columns as de-
scribed by table-desc-name, otherwise returns #f.
[Operation on relational-database]create-view ??
[Operation on relational-database]project-table ??
[Operation on relational-database]restrict-table ??
[Operation on relational-database]cart-prod-tables ??
Not yet implemented.
6.3 Weight-Balanced Trees
(require ā€™wt-tree)
Balanced binary trees are a useful data structure for maintaining large sets of ordered
objects or sets of associations whose keys are ordered. MIT Scheme has an comprehensive
implementation of weight-balanced binary trees which has several advantages over the other
data structures for large aggregates:
ā€¢ In addition to the usual element-level operations like insertion, deletion and lookup,
there is a full complement of collection-level operations, like set intersection, set union
and subset test, all of which are implemented with good orders of growth in time and
space. This makes weight balanced trees ideal for rapid prototyping of functionally
derived speciļ¬cations.
ā€¢ An element in a tree may be indexed by its position under the ordering of the keys, and
the ordinal position of an element may be determined, both with reasonable eļ¬ƒciency.
ā€¢ Operations to ļ¬nd and remove minimum element make weight balanced trees simple
to use for priority queues.
ā€¢ The implementation is functional rather than imperative. This means that operations
like ā€˜insertingā€™ an association in a tree do not destroy the old tree, in much the same way
that (+ 1 x) modiļ¬es neither the constant 1 nor the value bound to x. The trees are
referentially transparent thus the programmer need not worry about copying the trees.
Referential transparency allows space eļ¬ƒciency to be achieved by sharing subtrees.
These features make weight-balanced trees suitable for a wide range of applications,
especially those that require large numbers of sets or discrete maps. Applications that have
a few global databases and/or concentrate on element-level operations like insertion and
lookup are probably better oļ¬€ using hash-tables or red-black trees.
Chapter 6: Database Packages 189
The size of a tree is the number of associations that it contains. Weight balanced
binary trees are balanced to keep the sizes of the subtrees of each node within a constant
factor of each other. This ensures logarithmic times for single-path operations (like lookup
and insertion). A weight balanced tree takes space that is proportional to the number of
associations in the tree. For the current implementation, the constant of proportionality is
six words per association.
Weight balanced trees can be used as an implementation for either discrete sets or
discrete maps (associations). Sets are implemented by ignoring the datum that is associated
with the key. Under this scheme if an associations exists in the tree this indicates that the
key of the association is a member of the set. Typically a value such as (), #t or #f is
associated with the key.
Many operations can be viewed as computing a result that, depending on whether the
tree arguments are thought of as sets or maps, is known by two diļ¬€erent names. An example
is wt-tree/member?, which, when regarding the tree argument as a set, computes the set
membership operation, but, when regarding the tree as a discrete map, wt-tree/member?
is the predicate testing if the map is deļ¬ned at an element in its domain. Most names
in this package have been chosen based on interpreting the trees as sets, hence the name
wt-tree/member? rather than wt-tree/defined-at?.
The weight balanced tree implementation is a run-time-loadable option. To use weight
balanced trees, execute
(load-option ā€™wt-tree)
once before calling any of the procedures deļ¬ned here.
6.3.1 Construction of Weight-Balanced Trees
Binary trees require there to be a total order on the keys used to arrange the elements
in the tree. Weight balanced trees are organized by types, where the type is an object
encapsulating the ordering relation. Creating a tree is a two-stage process. First a tree type
must be created from the predicate which gives the ordering. The tree type is then used
for making trees, either empty or singleton trees or trees from other aggregate structures
like association lists. Once created, a tree ā€˜knowsā€™ its type and the type is used to test
compatibility between trees in operations taking two trees. Usually a small number of
tree types are created at the beginning of a program and used many times throughout the
programā€™s execution.
[procedure+]make-wt-tree-type key<?
This procedure creates and returns a new tree type based on the ordering predicate
key<?. Key<? must be a total ordering, having the property that for all key values a,
b and c:
(key<? a a)
ā‡’
#f
(and (key<? a b) (key<? b a))
ā‡’
#f
(if (and (key<? a b) (key<? b c))
(key<? a c)
#t)
ā‡’
#t
Two key values are assumed to be equal if neither is less than the other by key<?.
Chapter 6: Database Packages 190
Each call to make-wt-tree-type returns a distinct value, and trees are only compat-
ible if their tree types are eq?. A consequence is that trees that are intended to be
used in binary tree operations must all be created with a tree type originating from
the same call to make-wt-tree-type.
[variable+]number-wt-type
A standard tree type for trees with numeric keys. Number-wt-type could have been
deļ¬ned by
(define number-wt-type (make-wt-tree-type <))
[variable+]string-wt-type
A standard tree type for trees with string keys. String-wt-type could have been
deļ¬ned by
(define string-wt-type (make-wt-tree-type string<?))
[procedure+]make-wt-tree wt-tree-type
This procedure creates and returns a newly allocated weight balanced tree. The tree
is empty, i.e. it contains no associations. Wt-tree-type is a weight balanced tree type
obtained by calling make-wt-tree-type; the returned tree has this type.
[procedure+]singleton-wt-tree wt-tree-type key datum
This procedure creates and returns a newly allocated weight balanced tree. The
tree contains a single association, that of datum with key. Wt-tree-type is a weight
balanced tree type obtained by calling make-wt-tree-type; the returned tree has
this type.
[procedure+]alist->wt-tree tree-type alist
Returns a newly allocated weight-balanced tree that contains the same associations
as alist. This procedure is equivalent to:
(lambda (type alist)
(let ((tree (make-wt-tree type)))
(for-each (lambda (association)
(wt-tree/add! tree
(car association)
(cdr association)))
alist)
tree))
6.3.2 Basic Operations on Weight-Balanced Trees
This section describes the basic tree operations on weight balanced trees. These operations
are the usual tree operations for insertion, deletion and lookup, some predicates and a
procedure for determining the number of associations in a tree.
[procedure+]wt-tree/empty? wt-tree
Returns #t if wt-tree contains no associations, otherwise returns #f.
Chapter 6: Database Packages 191
[procedure+]wt-tree/size wt-tree
Returns the number of associations in wt-tree, an exact non-negative integer. This
operation takes constant time.
[procedure+]wt-tree/add wt-tree key datum
Returns a new tree containing all the associations in wt-tree and the association of
datum with key. If wt-tree already had an association for key, the new association
overrides the old. The average and worst-case times required by this operation are
proportional to the logarithm of the number of associations in wt-tree.
[procedure+]wt-tree/add! wt-tree key datum
Associates datum with key in wt-tree and returns an unspeciļ¬ed value. If wt-tree
already has an association for key, that association is replaced. The average and
worst-case times required by this operation are proportional to the logarithm of the
number of associations in wt-tree.
[procedure+]wt-tree/member? key wt-tree
Returns #t if wt-tree contains an association for key, otherwise returns #f. The aver-
age and worst-case times required by this operation are proportional to the logarithm
of the number of associations in wt-tree.
[procedure+]wt-tree/lookup wt-tree key default
Returns the datum associated with key in wt-tree. If wt-tree doesnā€™t contain an
association for key, default is returned. The average and worst-case times required
by this operation are proportional to the logarithm of the number of associations in
wt-tree.
[procedure+]wt-tree/delete wt-tree key
Returns a new tree containing all the associations in wt-tree, except that if wt-tree
contains an association for key, it is removed from the result. The average and worst-
case times required by this operation are proportional to the logarithm of the number
of associations in wt-tree.
[procedure+]wt-tree/delete! wt-tree key
If wt-tree contains an association for key the association is removed. Returns an
unspeciļ¬ed value. The average and worst-case times required by this operation are
proportional to the logarithm of the number of associations in wt-tree.
6.3.3 Advanced Operations on Weight-Balanced Trees
In the following the size of a tree is the number of associations that the tree contains, and
a smaller tree contains fewer associations.
[procedure+]wt-tree/split< wt-tree bound
Returns a new tree containing all and only the associations in wt-tree which have
a key that is less than bound in the ordering relation of the tree type of wt-tree.
The average and worst-case times required by this operation are proportional to the
logarithm of the size of wt-tree.
Chapter 6: Database Packages 192
[procedure+]wt-tree/split> wt-tree bound
Returns a new tree containing all and only the associations in wt-tree which have a
key that is greater than bound in the ordering relation of the tree type of wt-tree.
The average and worst-case times required by this operation are proportional to the
logarithm of size of wt-tree.
[procedure+]wt-tree/union wt-tree-1 wt-tree-2
Returns a new tree containing all the associations from both trees. This operation
is asymmetric: when both trees have an association for the same key, the returned
tree associates the datum from wt-tree-2 with the key. Thus if the trees are viewed
as discrete maps then wt-tree/union computes the map override of wt-tree-1 by
wt-tree-2. If the trees are viewed as sets the result is the set union of the arguments.
The worst-case time required by this operation is proportional to the sum of the sizes
of both trees. If the minimum key of one tree is greater than the maximum key of
the other tree then the time required is at worst proportional to the logarithm of the
size of the larger tree.
[procedure+]wt-tree/intersection wt-tree-1 wt-tree-2
Returns a new tree containing all and only those associations from wt-tree-1 which
have keys appearing as the key of an association in wt-tree-2. Thus the associ-
ated data in the result are those from wt-tree-1. If the trees are being used as sets
the result is the set intersection of the arguments. As a discrete map operation,
wt-tree/intersection computes the domain restriction of wt-tree-1 to (the domain
of) wt-tree-2. The time required by this operation is never worse that proportional
to the sum of the sizes of the trees.
[procedure+]wt-tree/difference wt-tree-1 wt-tree-2
Returns a new tree containing all and only those associations from wt-tree-1 which
have keys that do not appear as the key of an association in wt-tree-2. If the trees
are viewed as sets the result is the asymmetric set diļ¬€erence of the arguments. As
a discrete map operation, it computes the domain restriction of wt-tree-1 to the
complement of (the domain of) wt-tree-2. The time required by this operation is
never worse that proportional to the sum of the sizes of the trees.
[procedure+]wt-tree/subset? wt-tree-1 wt-tree-2
Returns #t iļ¬€ the key of each association in wt-tree-1 is the key of some association
in wt-tree-2, otherwise returns #f. Viewed as a set operation, wt-tree/subset? is
the improper subset predicate. A proper subset predicate can be constructed:
(define (proper-subset? s1 s2)
(and (wt-tree/subset? s1 s2)
(< (wt-tree/size s1) (wt-tree/size s2))))
As a discrete map operation, wt-tree/subset? is the subset test on the domain(s)
of the map(s). In the worst-case the time required by this operation is proportional
to the size of wt-tree-1.
[procedure+]wt-tree/set-equal? wt-tree-1 wt-tree-2
Returns #t iļ¬€ for every association in wt-tree-1 there is an association in wt-tree-2
that has the same key, and vice versa.
Chapter 6: Database Packages 193
Viewing the arguments as sets wt-tree/set-equal? is the set equality predicate. As
a map operation it determines if two maps are deļ¬ned on the same domain.
This procedure is equivalent to
(lambda (wt-tree-1 wt-tree-2)
(and (wt-tree/subset? wt-tree-1 wt-tree-2
(wt-tree/subset? wt-tree-2 wt-tree-1)))
In the worst-case the time required by this operation is proportional to the size of the
smaller tree.
[procedure+]wt-tree/fold combiner initial wt-tree
This procedure reduces wt-tree by combining all the associations, using an reverse
in-order traversal, so the associations are visited in reverse order. Combiner is a proce-
dure of three arguments: a key, a datum and the accumulated result so far. Provided
combiner takes time bounded by a constant, wt-tree/fold takes time proportional
to the size of wt-tree.
A sorted association list can be derived simply:
(wt-tree/fold (lambda (key datum list)
(cons (cons key datum) list))
ā€™()
wt-tree))
The data in the associations can be summed like this:
(wt-tree/fold (lambda (key datum sum) (+ sum datum))
0
wt-tree)
[procedure+]wt-tree/for-each action wt-tree
This procedure traverses the tree in-order, applying action to each association. The
associations are processed in increasing order of their keys. Action is a procedure of
two arguments which take the key and datum respectively of the association. Provided
action takes time bounded by a constant, wt-tree/for-each takes time proportional
to in the size of wt-tree. The example prints the tree:
(wt-tree/for-each (lambda (key value)
(display (list key value)))
wt-tree))
[procedure+]wt-tree/union-merge wt-tree-1 wt-tree-2 merge
Returns a new tree containing all the associations from both trees. If both trees have
an association for the same key, the datum associated with that key in the result tree
is computed by applying the procedure merge to the key, the value from wt-tree-1
and the value from wt-tree-2. Merge is of the form
(lambda (key datum-1 datum-2) ...)
If some key occurs only in one tree, that association will appear in the result tree
without being processed by merge, so for this operation to make sense, either merge
must have both a right and left identity that correspond to the association being
Chapter 6: Database Packages 194
absent in one of the trees, or some guarantee must be made, for example, all the keys
in one tree are known to occur in the other.
These are all reasonable procedures for merge
(lambda (key val1 val2) (+ val1 val2))
(lambda (key val1 val2) (append val1 val2))
(lambda (key val1 val2) (wt-tree/union val1 val2))
However, a procedure like
(lambda (key val1 val2) (- val1 val2))
would result in a subtraction of the data for all associations with keys occuring in both
trees but associations with keys occuring in only the second tree would be copied, not
negated, as is presumably be intent. The programmer might ensure that this never
happens.
This procedure has the same time behavior as wt-tree/union but with a slightly
worse constant factor. Indeed, wt-tree/union might have been deļ¬ned like this:
(define (wt-tree/union tree1 tree2)
(wt-tree/union-merge tree1 tree2
(lambda (key val1 val2) val2)))
The merge procedure takes the key as a parameter in case the data are not independent
of the key.
6.3.4 Indexing Operations on Weight-Balanced Trees
Weight balanced trees support operations that view the tree as sorted sequence of associa-
tions. Elements of the sequence can be accessed by position, and the position of an element
in the sequence can be determined, both in logarthmic time.
[procedure+]wt-tree/index wt-tree index
[procedure+]wt-tree/index-datum wt-tree index
[procedure+]wt-tree/index-pair wt-tree index
Returns the 0-based indexth association of wt-tree in the sorted sequence under
the treeā€™s ordering relation on the keys. wt-tree/index returns the indexth key,
wt-tree/index-datum returns the datum associated with the indexth key and
wt-tree/index-pair returns a new pair (key . datum) which is the cons of the
indexth key and its datum. The average and worst-case times required by this
operation are proportional to the logarithm of the number of associations in the tree.
These operations signal an error if the tree is empty, if index<0, or if index is greater
than or equal to the number of associations in the tree.
Indexing can be used to ļ¬nd the median and maximum keys in the tree as follows:
median: (wt-tree/index wt-tree (quotient (wt-tree/size wt-tree) 2))
maximum: (wt-tree/index wt-tree (-1+ (wt-tree/size wt-tree)))
[procedure+]wt-tree/rank wt-tree key
Determines the 0-based position of key in the sorted sequence of the keys under
the treeā€™s ordering relation, or #f if the tree has no association with for key. This
195
procedure returns either an exact non-negative integer or #f. The average and worst-
case times required by this operation are proportional to the logarithm of the number
of associations in the tree.
[procedure+]wt-tree/min wt-tree
[procedure+]wt-tree/min-datum wt-tree
[procedure+]wt-tree/min-pair wt-tree
Returns the association of wt-tree that has the least key under the treeā€™s ordering
relation. wt-tree/min returns the least key, wt-tree/min-datum returns the da-
tum associated with the least key and wt-tree/min-pair returns a new pair (key
. datum) which is the cons of the minimum key and its datum. The average and
worst-case times required by this operation are proportional to the logarithm of the
number of associations in the tree.
These operations signal an error if the tree is empty. They could be written
(define (wt-tree/min tree) (wt-tree/index tree 0))
(define (wt-tree/min-datum tree) (wt-tree/index-datum tree 0))
(define (wt-tree/min-pair tree) (wt-tree/index-pair tree 0))
[procedure+]wt-tree/delete-min wt-tree
Returns a new tree containing all of the associations in wt-tree except the association
with the least key under the wt-treeā€™s ordering relation. An error is signalled if
the tree is empty. The average and worst-case times required by this operation are
proportional to the logarithm of the number of associations in the tree. This operation
is equivalent to
(wt-tree/delete wt-tree (wt-tree/min wt-tree))
[procedure+]wt-tree/delete-min! wt-tree
Removes the association with the least key under the wt-treeā€™s ordering relation. An
error is signalled if the tree is empty. The average and worst-case times required by
this operation are proportional to the logarithm of the number of associations in the
tree. This operation is equivalent to
(wt-tree/delete! wt-tree (wt-tree/min wt-tree))
196
7 Other Packages
7.1 Data Structures
7.1.1 Arrays
(require ā€™array) or (require ā€™srfi-63)
[Function]array? obj
Returns #t if the obj is an array, and #f if not.
Note: Arrays are not disjoint from other Scheme types. Vectors and possibly strings also
satisfy array?. A disjoint array predicate can be written:
(define (strict-array? obj)
(and (array? obj) (not (string? obj)) (not (vector? obj))))
[Function]equal? obj1 obj2
Returns #t if obj1 and obj2 have the same rank and dimensions and the corresponding
elements of obj1 and obj2 are equal?.
equal? recursively compares the contents of pairs, vectors, strings, and arrays, ap-
plying eqv? on other objects such as numbers and symbols. A rule of thumb is that
objects are generally equal? if they print the same. equal? may fail to terminate if
its arguments are circular data structures.
(equal? ā€™a ā€™a)
ā‡’
#t
(equal? ā€™(a) ā€™(a))
ā‡’
#t
(equal? ā€™(a (b) c)
ā€™(a (b) c))
ā‡’
#t
(equal? "abc" "abc")
ā‡’
#t
(equal? 2 2)
ā‡’
#t
(equal? (make-vector 5 ā€™a)
(make-vector 5 ā€™a))
ā‡’
#t
(equal? (make-array (A:fixN32b 4) 5 3)
(make-array (A:fixN32b 4) 5 3))
ā‡’
#t
(equal? (make-array ā€™#(foo) 3 3)
(make-array ā€™#(foo) 3 3))
ā‡’
#t
(equal? (lambda (x) x)
(lambda (y) y))
ā‡’
unspecified
[Function]array-rank obj
Returns the number of dimensions of obj. If obj is not an array, 0 is returned.
[Function]array-dimensions array
Returns a list of dimensions.
(array-dimensions (make-array ā€™#() 3 5))
ā‡’
(3 5)
Chapter 7: Other Packages 197
[Function]make-array prototype k1 . . .
Creates and returns an array of type prototype with dimensions k1, . . . and ļ¬lled
with elements from prototype. prototype must be an array, vector, or string. The
implementation-dependent type of the returned array will be the same as the type of
prototype; except if that would be a vector or string with rank not equal to one, in
which case some variety of array will be returned.
If the prototype has no elements, then the initial contents of the returned array are
unspeciļ¬ed. Otherwise, the returned array will be ļ¬lled with the element at the origin
of prototype.
[Function]create-array prototype k1 . . .
create-array is an alias for make-array.
[Function]make-shared-array array mapper k1 . . .
make-shared-array can be used to create shared subarrays of other arrays. The
mapper is a function that translates coordinates in the new array into coordinates in
the old array. A mapper must be linear, and its range must stay within the bounds
of the old array, but it can be otherwise arbitrary. A simple example:
(define fred (make-array ā€™#(#f) 8 8))
(define freds-diagonal
(make-shared-array fred (lambda (i) (list i i)) 8))
(array-set! freds-diagonal ā€™foo 3)
(array-ref fred 3 3)
ā‡’
FOO
(define freds-center
(make-shared-array fred (lambda (i j) (list (+ 3 i) (+ 3 j)))
2 2))
(array-ref freds-center 0 0)
ā‡’
FOO
[Function]list->array rank proto list
list must be a rank-nested list consisting of all the elements, in row-major order, of
the array to be created.
list->array returns an array of rank rank and type proto consisting of all the
elements, in row-major order, of list. When rank is 0, list is the lone array element;
not necessarily a list.
(list->array 2 ā€™#() ā€™((1 2) (3 4)))
ā‡’
#2A((1 2) (3 4))
(list->array 0 ā€™#() 3)
ā‡’
#0A 3
[Function]array->list array
Returns a rank-nested list consisting of all the elements, in row-major order, of array.
In the case of a rank-0 array, array->list returns the single element.
(array->list #2A((ho ho ho) (ho oh oh)))
ā‡’
((ho ho ho) (ho oh oh))
Chapter 7: Other Packages 198
(array->list #0A ho)
ā‡’
ho
[Function]vector->array vect proto dim1 . . .
vect must be a vector of length equal to the product of exact nonnegative integers
dim1, . . . .
vector->array returns an array of type proto consisting of all the elements, in row-
major order, of vect. In the case of a rank-0 array, vect has a single element.
(vector->array #(1 2 3 4) #() 2 2)
ā‡’
#2A((1 2) (3 4))
(vector->array ā€™#(3) ā€™#())
ā‡’
#0A 3
[Function]array->vector array
Returns a new vector consisting of all the elements of array in row-major order.
(array->vector #2A ((1 2)( 3 4)))
ā‡’
#(1 2 3 4)
(array->vector #0A ho)
ā‡’
#(ho)
[Function]array-in-bounds? array index1 . . .
Returns #t if its arguments would be acceptable to array-ref.
[Function]array-ref array k1 . . .
Returns the (k1, . . . ) element of array.
[Procedure]array-set! array obj k1 . . .
Stores obj in the (k1, . . . ) element of array. The value returned by array-set! is
unspeciļ¬ed.
These functions return a prototypical uniform-array enclosing the optional argument (which
must be of the correct type). If the uniform-array type is supported by the implementation,
then it is returned; defaulting to the next larger precision type; resorting ļ¬nally to vector.
[Function]A:floC128b z
[Function]A:floC128b
Returns an inexact 128.bit ļ¬‚onum complex uniform-array prototype.
[Function]A:floC64b z
[Function]A:floC64b
Returns an inexact 64.bit ļ¬‚onum complex uniform-array prototype.
[Function]A:floC32b z
[Function]A:floC32b
Returns an inexact 32.bit ļ¬‚onum complex uniform-array prototype.
[Function]A:floC16b z
[Function]A:floC16b
Returns an inexact 16.bit ļ¬‚onum complex uniform-array prototype.
Chapter 7: Other Packages 199
[Function]A:floR128b x
[Function]A:floR128b
Returns an inexact 128.bit ļ¬‚onum real uniform-array prototype.
[Function]A:floR64b x
[Function]A:floR64b
Returns an inexact 64.bit ļ¬‚onum real uniform-array prototype.
[Function]A:floR32b x
[Function]A:floR32b
Returns an inexact 32.bit ļ¬‚onum real uniform-array prototype.
[Function]A:floR16b x
[Function]A:floR16b
Returns an inexact 16.bit ļ¬‚onum real uniform-array prototype.
[Function]A:floR128d q
[Function]A:floR128d
Returns an exact 128.bit decimal ļ¬‚onum rational uniform-array prototype.
[Function]A:floR64d q
[Function]A:floR64d
Returns an exact 64.bit decimal ļ¬‚onum rational uniform-array prototype.
[Function]A:floR32d q
[Function]A:floR32d
Returns an exact 32.bit decimal ļ¬‚onum rational uniform-array prototype.
[Function]A:fixZ64b n
[Function]A:fixZ64b
Returns an exact binary ļ¬xnum uniform-array prototype with at least 64 bits of
precision.
[Function]A:fixZ32b n
[Function]A:fixZ32b
Returns an exact binary ļ¬xnum uniform-array prototype with at least 32 bits of
precision.
[Function]A:fixZ16b n
[Function]A:fixZ16b
Returns an exact binary ļ¬xnum uniform-array prototype with at least 16 bits of
precision.
[Function]A:fixZ8b n
[Function]A:fixZ8b
Returns an exact binary ļ¬xnum uniform-array prototype with at least 8 bits of pre-
cision.
Chapter 7: Other Packages 200
[Function]A:fixN64b k
[Function]A:fixN64b
Returns an exact non-negative binary ļ¬xnum uniform-array prototype with at least
64 bits of precision.
[Function]A:fixN32b k
[Function]A:fixN32b
Returns an exact non-negative binary ļ¬xnum uniform-array prototype with at least
32 bits of precision.
[Function]A:fixN16b k
[Function]A:fixN16b
Returns an exact non-negative binary ļ¬xnum uniform-array prototype with at least
16 bits of precision.
[Function]A:fixN8b k
[Function]A:fixN8b
Returns an exact non-negative binary ļ¬xnum uniform-array prototype with at least
8 bits of precision.
[Function]A:bool bool
[Function]A:bool
Returns a boolean uniform-array prototype.
7.1.2 Subarrays
(require ā€™subarray)
[Function]subarray array select . . .
selects a subset of an array. For 0 <= j < n, selectj is either an integer, a list of two
integers within the range for the j th index, or #f.
When selectj is a list of two integers, then the j th index is restricted to that subrange
in the returned array.
When selectj is #f, then the full range of the j th index is accessible in the returned
array. An elided argument is equivalent to #f.
When selectj is an integer, then the rank of the returned array is less than array, and
only elements whose j th index equals selectj are shared.
> (define ra ā€™#2A((a b c) (d e f)))
#<unspecified>
> (subarray ra 0 #f)
#1A(a b c)
> (subarray ra 1 #f)
#1A(d e f)
> (subarray ra #f 1)
#1A(b e)
> (subarray ra ā€™(0 1) #f)
#2A((a b c) (d e f))
> (subarray ra #f ā€™(0 1))
Chapter 7: Other Packages 201
#2A((a b) (d e))
> (subarray ra #f ā€™(1 2))
#2A((b c) (e f))
> (subarray ra #f ā€™(2 1))
#2A((c b) (f e))
Arrays can be reļ¬‚ected (reversed) using subarray:
> (subarray ā€™#1A(a b c d e) ā€™(4 0))
#1A(e d c b a)
[Function]array-trim array trim . . .
Returns a subarray sharing contents with array except for slices removed from either
side of each dimension. Each of the trims is an exact integer indicating how much to
trim. A positive s trims the data from the lower end and reduces the upper bound of
the result; a negative s trims from the upper end and increases the lower bound.
For example:
(array-trim ā€™#(0 1 2 3 4) 1)
ā‡’
#1A(1 2 3 4)
(array-trim ā€™#(0 1 2 3 4) -1)
ā‡’
#1A(0 1 2 3)
(require ā€™array-for-each)
(define (centered-difference ra)
(array-map ra - (array-trim ra 1) (array-trim ra -1)))
(centered-difference ā€™#(0 1 3 5 9 22))
ā‡’
#(1 2 2 4 13)
7.1.3 Array Mapping
(require ā€™array-for-each)
[Procedure]array-map! array0 proc array1 . . .
array1, . . . must have the same number of dimensions as array0 and have a range
for each index which includes the range for the corresponding index in array0. proc
is applied to each tuple of elements of array1 . . . and the result is stored as the
corresponding element in array0. The value returned is unspeciļ¬ed. The order of
application is unspeciļ¬ed.
[Function]array-map prototype proc array1 array2 . . .
array2, . . . must have the same number of dimensions as array1 and have a range for
each index which includes the range for the corresponding index in array1. proc is
applied to each tuple of elements of array1, array2, . . . and the result is stored as the
corresponding element in a new array of type prototype. The new array is returned.
The order of application is unspeciļ¬ed.
[Function]array-for-each proc array0 . . .
proc is applied to each tuple of elements of array0 . . . in row-major order. The value
returned is unspeciļ¬ed.
Chapter 7: Other Packages 202
[Function]array-indexes array
Returns an array of lists of indexes for array such that, if li is a list of indexes for
which array is deļ¬ned, (equal? li (apply array-ref (array-indexes array) li)).
[Function]array-index-for-each array proc
applies proc to the indices of each element of array in turn. The value returned and
the order of application are unspeciļ¬ed.
One can implement array-index-map! as
(define (array-index-map! ra fun)
(array-index-for-each
ra
(lambda is (apply array-set! ra (apply fun is) is))))
[Procedure]array-index-map! array proc
applies proc to the indices of each element of array in turn, storing the result in
the corresponding element. The value returned and the order of application are
unspeciļ¬ed.
One can implement array-indexes as
(define (array-indexes array)
(let ((ra (apply make-array ā€™#() (array-dimensions array))))
(array-index-map! ra (lambda x x))
ra))
Another example:
(define (apl:index-generator n)
(let ((v (make-vector n 1)))
(array-index-map! v (lambda (i) i))
v))
[Procedure]array:copy! destination source
Copies every element from vector or array source to the corresponding element of
destination. destination must have the same rank as source, and be at least as large
in each dimension. The order of copying is unspeciļ¬ed.
7.1.4 Array Interpolation
(require ā€™array-interpolate)
[Function]interpolate-array-ref ra x1 . . . xj
ra must be an array of rank j containing numbers. interpolate-array-ref returns
a value interpolated from the nearest j-dimensional cube of elements of ra.
(interpolate-array-ref ā€™#2A:fixZ32b((1 2 3) (4 5 6)) 1 0.1)
==> 4.1
(interpolate-array-ref ā€™#2A:fixZ32b((1 2 3) (4 5 6)) 0.5 0.25)
==> 2.75
Chapter 7: Other Packages 203
[Procedure]resample-array! ra1 ra2
ra1 and ra2 must be numeric arrays of equal rank. resample-array! sets ra1 to
values interpolated from ra2 such that the values of elements at the corners of ra1
and ra2 are equal.
(define ra (make-array (A:fixZ32b) 2 2))
(resample-array! ra ā€™#2A:fixZ32b((1 2 3) (4 5 6)))
ra ==> #2A:fixZ32b((1 3) (4 6))
(define ra (make-array (A:floR64b) 3 2))
(resample-array! ra ā€™#2A:fixZ32b((1 2 3) (4 5 6)))
ra ==> #2A:floR64b((1.0 3.0) (2.5 4.5) (4.0 6.0))
7.1.5 Association Lists
(require ā€™alist)
Alist functions provide utilities for treating a list of key-value pairs as an associative
database. These functions take an equality predicate, pred, as an argument. This predicate
should be repeatable, symmetric, and transitive.
Alist functions can be used with a secondary index method such as hash tables for
improved performance.
[Function]predicate->asso pred
Returns an association function (like assq, assv, or assoc) corresponding to pred.
The returned function returns a key-value pair whose key is pred-equal to its ļ¬rst
argument or #f if no key in the alist is pred-equal to the ļ¬rst argument.
[Function]alist-inquirer pred
Returns a procedure of 2 arguments, alist and key, which returns the value associated
with key in alist or #f if key does not appear in alist.
[Function]alist-associator pred
Returns a procedure of 3 arguments, alist, key, and value, which returns an alist
with key and value associated. Any previous value associated with key will be lost.
This returned procedure may or may not have side eļ¬€ects on its alist argument. An
example of correct usage is:
(define put (alist-associator string-ci=?))
(define alist ā€™())
(set! alist (put alist "Foo" 9))
[Function]alist-remover pred
Returns a procedure of 2 arguments, alist and key, which returns an alist with an
association whose key is key removed. This returned procedure may or may not have
side eļ¬€ects on its alist argument. An example of correct usage is:
(define rem (alist-remover string-ci=?))
(set! alist (rem alist "foo"))
[Function]alist-map proc alist
Returns a new association list formed by mapping proc over the keys and values of
alist. proc must be a function of 2 arguments which returns the new value part.
Chapter 7: Other Packages 204
[Function]alist-for-each proc alist
Applies proc to each pair of keys and values of alist. proc must be a function of 2
arguments. The returned value is unspeciļ¬ed.
7.1.6 Byte
(require ā€™byte)
Some algorithms are expressed in terms of arrays of small integers. Using Scheme strings to
implement these arrays is not portable vis-a-vis the correspondence between integers and
characters and non-ascii character sets. These functions abstract the notion of a byte.
[Function]byte-ref bytes k
k must be a valid index of bytes. byte-ref returns byte k of bytes using zero-origin
indexing.
[Procedure]byte-set! bytes k byte
k must be a valid index of bytes, and byte must be a small nonnegative integer.
byte-set! stores byte in element k of bytes and returns an unspeciļ¬ed value.
[Function]make-bytes k byte
[Function]make-bytes k
make-bytes returns a newly allocated byte-array of length k. If byte is given, then
all elements of the byte-array are initialized to byte, otherwise the contents of the
byte-array are unspeciļ¬ed.
[Function]bytes-length bytes
bytes-length returns length of byte-array bytes.
[Function]bytes byte . . .
Returns a newly allocated byte-array composed of the small nonnegative arguments.
[Function]list->bytes bytes
list->bytes returns a newly allocated byte-array formed from the small nonnegative
integers in the list bytes.
[Function]bytes->list bytes
bytes->list returns a newly allocated list of the bytes that make up the given byte-
array.
Bytes->list and list->bytes are inverses so far as equal? is concerned.
[Function]bytes->string bytes
Returns a new string formed from applying integer->char to each byte in
bytes->string. Note that this may signal an error for bytes having values between
128 and 255.
[Function]string->bytes string
Returns a new byte-array formed from applying char->integer to each character in
string->bytes. Note that this may signal an error if an integer is larger than 255.
Chapter 7: Other Packages 205
[Function]bytes-copy bytes
Returns a newly allocated copy of the given bytes.
[Function]subbytes bytes start end
bytes must be a bytes, and start and end must be exact integers satisfying
0 <= start <= end <= (bytes-length bytes).
subbytes returns a newly allocated bytes formed from the bytes of bytes beginning
with index start (inclusive) and ending with index end (exclusive).
[Procedure]bytes-reverse! bytes
Reverses the order of byte-array bytes.
[Function]bytes-reverse bytes
Returns a newly allocated bytes-array consisting of the elements of bytes in reverse
order.
Input and output of bytes should be with ports opened in binary mode (see Section 2.3
[Input/Output], page 13). Calling open-file with ā€™rb or ā€™wb modes argument will return
a binary port if the Scheme implementation supports it.
[Function]write-byte byte port
[Function]write-byte byte
Writes the byte byte (not an external representation of the byte) to the given port
and returns an unspeciļ¬ed value. The port argument may be omitted, in which case
it defaults to the value returned by current-output-port.
[Function]read-byte port
[Function]read-byte
Returns the next byte available from the input port, updating the port to point to the
following byte. If no more bytes are available, an end-of-ļ¬le object is returned. port
may be omitted, in which case it defaults to the value returned by current-input-
port.
When reading and writing binary numbers with read-bytes and write-bytes, the sign
of the length argument determines the endianness (order) of bytes. Positive treats them
as big-endian, the ļ¬rst byte input or output is highest order. Negative treats them as
little-endian, the ļ¬rst byte input or output is the lowest order.
Once read in, SLIB treats byte sequences as big-endian. The multi-byte sequences produced
and used by number conversion routines see Section 7.1.7 [Byte/Number Conversions],
page 206, are always big-endian.
[Function]read-bytes n port
[Function]read-bytes n
read-bytes returns a newly allocated bytes-array ļ¬lled with (abs n) bytes read from
port. If n is positive, then the ļ¬rst byte read is stored at index 0; otherwise the last
byte read is stored at index 0. Note that the length of the returned byte-array will
be less than (abs n) if port reaches end-of-ļ¬le.
port may be omitted, in which case it defaults to the value returned by
current-input-port.
Chapter 7: Other Packages 206
[Function]write-bytes bytes n port
[Function]write-bytes bytes n
write-bytes writes (abs n) bytes to output-port port. If n is positive, then the ļ¬rst
byte written is index 0 of bytes; otherwise the last byte written is index 0 of bytes.
write-bytes returns an unspeciļ¬ed value.
port may be omitted, in which case it defaults to the value returned by
current-output-port.
subbytes-read! and subbytes-write provide lower-level procedures for reading and writ-
ing blocks of bytes. The relative size of start and end determines the order of writing.
[Procedure]subbytes-read! bts start end port
[Procedure]subbytes-read! bts start end
Fills bts with up to (abs (- start end)) bytes read from port. The ļ¬rst byte read
is stored at index bts. subbytes-read! returns the number of bytes read.
port may be omitted, in which case it defaults to the value returned by
current-input-port.
[Function]subbytes-write bts start end port
[Function]subbytes-write bts start end
subbytes-write writes (abs (- start end)) bytes to output-port port. The ļ¬rst
byte written is index start of bts. subbytes-write returns the number of bytes
written.
port may be omitted, in which case it defaults to the value returned by
current-output-port.
7.1.7 Byte/Number Conversions
(require ā€™byte-number)
The multi-byte sequences produced and used by numeric conversion routines are always big-
endian. Endianness can be changed during reading and writing bytes using read-bytes
and write-bytes See Section 7.1.6 [Byte], page 204.
The sign of the length argument to bytes/integer conversion procedures determines the
signedness of the number.
[Function]bytes->integer bytes n
Converts the ļ¬rst (abs n) bytes of big-endian bytes array to an integer. If n is
negative then the integer coded by the bytes are treated as twoā€™s-complement (can
be negative).
(bytes->integer (bytes 0 0 0 15) -4)
ā‡’
15
(bytes->integer (bytes 0 0 0 15) 4)
ā‡’
15
(bytes->integer (bytes 255 255 255 255) -4)
ā‡’
-1
(bytes->integer (bytes 255 255 255 255) 4)
ā‡’
4294967295
(bytes->integer (bytes 128 0 0 0) -4)
ā‡’
-2147483648
(bytes->integer (bytes 128 0 0 0) 4)
ā‡’
2147483648
Chapter 7: Other Packages 207
[Function]integer->bytes n len
Converts the integer n to a byte-array of (abs n) bytes. If n and len are both negative,
then the bytes in the returned array are coded twoā€™s-complement.
(bytes->list (integer->bytes 15 -4))
ā‡’
(0 0 0 15)
(bytes->list (integer->bytes 15 4))
ā‡’
(0 0 0 15)
(bytes->list (integer->bytes -1 -4))
ā‡’
(255 255 255 255)
(bytes->list (integer->bytes 4294967295 4))
ā‡’
(255 255 255 255)
(bytes->list (integer->bytes -2147483648 -4))
ā‡’
(128 0 0 0)
(bytes->list (integer->bytes 2147483648 4))
ā‡’
(128 0 0 0)
[Function]bytes->ieee-float bytes
bytes must be a 4-element byte-array. bytes->ieee-float calculates and returns
the value of bytes interpreted as a big-endian IEEE 4-byte (32-bit) number.
(bytes->ieee-float (bytes 0 0 0 0))
ā‡’
0.0
(bytes->ieee-float (bytes #x80 0 0 0))
ā‡’
-0.0
(bytes->ieee-float (bytes #x40 0 0 0))
ā‡’
2.0
(bytes->ieee-float (bytes #x40 #xd0 0 0))
ā‡’
6.5
(bytes->ieee-float (bytes #xc0 #xd0 0 0))
ā‡’
-6.5
(bytes->ieee-float (bytes 0 #x80 0 0))
ā‡’
11.754943508222875e-39
(bytes->ieee-float (bytes 0 #x40 0 0))
ā‡’
5.877471754111437e-39
(bytes->ieee-float (bytes 0 0 0 1))
ā‡’
1.401298464324817e-45
(bytes->ieee-float (bytes #xff #x80 0 0))
ā‡’
-inf.0
(bytes->ieee-float (bytes #x7f #x80 0 0))
ā‡’
+inf.0
(bytes->ieee-float (bytes #x7f #x80 0 1))
ā‡’
0/0
(bytes->ieee-float (bytes #x7f #xc0 0 0))
ā‡’
0/0
[Function]bytes->ieee-double bytes
bytes must be a 8-element byte-array. bytes->ieee-double calculates and returns
the value of bytes interpreted as a big-endian IEEE 8-byte (64-bit) number.
(bytes->ieee-double (bytes 0 0 0 0 0 0 0 0))
ā‡’
0.0
(bytes->ieee-double (bytes #x80 0 0 0 0 0 0 0))
ā‡’
-0.0
(bytes->ieee-double (bytes #x40 0 0 0 0 0 0 0))
ā‡’
2.0
(bytes->ieee-double (bytes #x40 #x1A 0 0 0 0 0 0))
ā‡’
6.5
(bytes->ieee-double (bytes #xC0 #x1A 0 0 0 0 0 0))
ā‡’
-6.5
(bytes->ieee-double (bytes 0 8 0 0 0 0 0 0))
ā‡’
11.125369292536006e-309
(bytes->ieee-double (bytes 0 4 0 0 0 0 0 0))
ā‡’
5.562684646268003e-309
(bytes->ieee-double (bytes 0 0 0 0 0 0 0 1))
ā‡’
4.0e-324
(bytes->ieee-double (list->bytes ā€™(127 239 255 255 255 255 255 255))) 179.76931348623157e306
(bytes->ieee-double (bytes #xFF #xF0 0 0 0 0 0 0))
ā‡’
-inf.0
(bytes->ieee-double (bytes #x7F #xF0 0 0 0 0 0 0))
ā‡’
+inf.0
(bytes->ieee-double (bytes #x7F #xF8 0 0 0 0 0 0))
ā‡’
0/0
Chapter 7: Other Packages 208
[Function]ieee-float->bytes x
Returns a 4-element byte-array encoding the IEEE single-precision ļ¬‚oating-point of
x.
(bytes->list (ieee-float->bytes 0.0))
ā‡’
(0 0 0 0)
(bytes->list (ieee-float->bytes -0.0))
ā‡’
(128 0 0 0)
(bytes->list (ieee-float->bytes 2.0))
ā‡’
(64 0 0 0)
(bytes->list (ieee-float->bytes 6.5))
ā‡’
(64 208 0 0)
(bytes->list (ieee-float->bytes -6.5))
ā‡’
(192 208 0 0)
(bytes->list (ieee-float->bytes 11.754943508222875e-39))
ā‡’
( 0 128 0 0)
(bytes->list (ieee-float->bytes 5.877471754111438e-39))
ā‡’
( 0 64 0 0)
(bytes->list (ieee-float->bytes 1.401298464324817e-45))
ā‡’
( 0 0 0 1)
(bytes->list (ieee-float->bytes -inf.0))
ā‡’
(255 128 0 0)
(bytes->list (ieee-float->bytes +inf.0))
ā‡’
(127 128 0 0)
(bytes->list (ieee-float->bytes 0/0))
ā‡’
(127 192 0 0)
[Function]ieee-double->bytes x
Returns a 8-element byte-array encoding the IEEE double-precision ļ¬‚oating-point of
x.
(bytes->list (ieee-double->bytes 0.0))
ā‡’
(0 0 0 0 0 0 0 0)
(bytes->list (ieee-double->bytes -0.0))
ā‡’
(128 0 0 0 0 0 0 0)
(bytes->list (ieee-double->bytes 2.0))
ā‡’
(64 0 0 0 0 0 0 0)
(bytes->list (ieee-double->bytes 6.5))
ā‡’
(64 26 0 0 0 0 0 0)
(bytes->list (ieee-double->bytes -6.5))
ā‡’
(192 26 0 0 0 0 0 0)
(bytes->list (ieee-double->bytes 11.125369292536006e-309))
ā‡’
( 0 8 0 0 0 0 0 0)
(bytes->list (ieee-double->bytes 5.562684646268003e-309))
ā‡’
( 0 4 0 0 0 0 0 0)
(bytes->list (ieee-double->bytes 4.0e-324))
ā‡’
( 0 0 0 0 0 0 0 1)
(bytes->list (ieee-double->bytes -inf.0))
ā‡’
(255 240 0 0 0 0 0 0)
(bytes->list (ieee-double->bytes +inf.0))
ā‡’
(127 240 0 0 0 0 0 0)
(bytes->list (ieee-double->bytes 0/0))
ā‡’
(127 248 0 0 0 0 0 0)
Byte Collation Order
The string<? ordering of big-endian byte-array representations of ļ¬xed and IEEE ļ¬‚oating-
point numbers agrees with the numerical ordering only when those numbers are non-
negative.
Straighforward modiļ¬cation of these formats can extend the byte-collating order to work
for their entire ranges. This agreement enables the full range of numbers as keys in indexed-
sequential-access-method databases.
Chapter 7: Other Packages 209
[Procedure]integer-byte-collate! byte-vector
Modiļ¬es sign bit of byte-vector so that string<? ordering of twoā€™s-complement byte-
vectors matches numerical order. integer-byte-collate! returns byte-vector and
is its own functional inverse.
[Function]integer-byte-collate byte-vector
Returns copy of byte-vector with sign bit modiļ¬ed so that string<? ordering of
twoā€™s-complement byte-vectors matches numerical order. integer-byte-collate is
its own functional inverse.
[Procedure]ieee-byte-collate! byte-vector
Modiļ¬es byte-vector so that string<? ordering of IEEE ļ¬‚oating-point byte-vectors
matches numerical order. ieee-byte-collate! returns byte-vector.
[Procedure]ieee-byte-decollate! byte-vector
Given byte-vector modiļ¬ed by ieee-byte-collate!, reverses the byte-vector modi-
ļ¬cations.
[Function]ieee-byte-collate byte-vector
Returns copy of byte-vector encoded so that string<? ordering of IEEE ļ¬‚oating-point
byte-vectors matches numerical order.
[Function]ieee-byte-decollate byte-vector
Given byte-vector returned by ieee-byte-collate, reverses the byte-vector modiļ¬-
cations.
7.1.8 MAT-File Format
(require ā€™matfile)
http: / / www . mathworks . com / access / helpdesk / help / pdf_doc / matlab /
matfile_format.pdf
This package reads MAT-File Format version 4 (MATLAB) binary data ļ¬les. MAT-ļ¬les
written from big-endian or little-endian computers having IEEE format numbers are cur-
rently supported. Support for ļ¬les written from VAX or Cray machines could also be
added.
The numeric and text matrix types handled; support for sparse matrices awaits a sample
ļ¬le.
[Function]matfile:read ļ¬lename
ļ¬lename should be a string naming an existing ļ¬le containing a MATLAB Version 4
MAT-File. The matfile:read procedure reads matrices from the ļ¬le and returns a
list of the results; a list of the name string and array for each matrix.
[Function]matfile:load ļ¬lename
ļ¬lename should be a string naming an existing ļ¬le containing a MATLAB Version
4 MAT-File. The matfile:load procedure reads matrices from the ļ¬le and deļ¬nes
the string-ci->symbol for each matrix to its corresponding array. matfile:load
returns a list of the symbols deļ¬ned.
Chapter 7: Other Packages 210
7.1.9 Portable Image Files
(require ā€™pnm)
[Function]pnm:type-dimensions path
The string path must name a portable bitmap graphics ļ¬le. pnm:type-dimensions
returns a list of 4 items:
1. A symbol describing the type of the ļ¬le named by path.
2. The image width in pixels.
3. The image height in pixels.
4. The maximum value of pixels assume in the ļ¬le.
The current set of ļ¬le-type symbols is:
pbm
pbm-raw Black-and-White image; pixel values are 0 or 1.
pgm
pgm-raw Gray (monochrome) image; pixel values are from 0 to maxval speciļ¬ed
in ļ¬le header.
ppm
ppm-raw RGB (full color) image; red, green, and blue interleaved pixel values are
from 0 to maxval
[Function]pnm:image-file->array path array
Reads the portable bitmap graphics ļ¬le named by path into array. array must be
the correct size and type for path. array is returned.
[Function]pnm:image-file->array path
pnm:image-file->array creates and returns an array with the portable bitmap
graphics ļ¬le named by path read into it.
[Function]pnm:array-write type array maxval path comment . . .
Writes the contents of array to a type image ļ¬le named path. The ļ¬le will have pixel
values between 0 and maxval, which must be compatible with type. For ā€˜pbmā€™ ļ¬les,
maxval must be ā€˜1ā€™. comments are included in the ļ¬le header.
7.1.10 Collections
(require ā€™collect)
Routines for managing collections. Collections are aggregate data structures supporting
iteration over their elements, similar to the Dylan(TM) language, but with a diļ¬€erent
interface. They have elements indexed by corresponding keys, although the keys may be
implicit (as with lists).
New types of collections may be deļ¬ned as YASOS objects (see Section 3.14 [Yasos],
page 35). They must support the following operations:
ā€¢ (collection? self) (always returns #t);
ā€¢ (size self) returns the number of elements in the collection;
Chapter 7: Other Packages 211
ā€¢ (print self port) is a specialized print operation for the collection which prints a
suitable representation on the given port or returns it as a string if port is #t;
ā€¢ (gen-elts self) returns a thunk which on successive invocations yields elements of
self in order or gives an error if it is invoked more than (size self) times;
ā€¢ (gen-keys self) is like gen-elts, but yields the collectionā€™s keys in order.
They might support specialized for-each-key and for-each-elt operations.
[Function]collection? obj
A predicate, true initially of lists, vectors and strings. New sorts of collections must
answer #t to collection?.
[Procedure]map-elts proc collection1 . . .
[Procedure]do-elts proc collection1 . . .
proc is a procedure taking as many arguments as there are collections (at least one).
The collections are iterated over in their natural order and proc is applied to the
elements yielded by each iteration in turn. The order in which the arguments are sup-
plied corresponds to te order in which the collections appear. do-elts is used when
only side-eļ¬€ects of proc are of interest and its return value is unspeciļ¬ed. map-elts
returns a collection (actually a vector) of the results of the applications of proc.
Example:
(map-elts + (list 1 2 3) (vector 1 2 3))
ā‡’
#(2 4 6)
[Procedure]map-keys proc collection1 . . .
[Procedure]do-keys proc collection1 . . .
These are analogous to map-elts and do-elts, but each iteration is over the collec-
tionsā€™ keys rather than their elements.
Example:
(map-keys + (list 1 2 3) (vector 1 2 3))
ā‡’
#(0 2 4)
[Procedure]for-each-key collection proc
[Procedure]for-each-elt collection proc
These are like do-keys and do-elts but only for a single collection; they are poten-
tially more eļ¬ƒcient.
[Function]reduce proc seed collection1 . . .
A generalization of the list-based reduce-init (see Section 7.2.1.3 [Lists as se-
quences], page 226) to collections.
Examples:
(reduce + 0 (vector 1 2 3))
ā‡’
6
(reduce union ā€™() ā€™((a b c) (b c d) (d a)))
ā‡’
(c b d a).
Reduce called with two arguments will work as does the procedure of the same name
from See Section 7.2.1 [Common List Functions], page 221.
Chapter 7: Other Packages 212
[Function]any? pred collection1 . . .
A generalization of the list-based some (see Section 7.2.1.3 [Lists as sequences],
page 226) to collections.
Example:
(any? odd? (list 2 3 4 5))
ā‡’
#t
[Function]every? pred collection1 . . .
A generalization of the list-based every (see Section 7.2.1.3 [Lists as sequences],
page 226) to collections.
Example:
(every? collection? ā€™((1 2) #(1 2)))
ā‡’
#t
[Function]empty? collection
Returns #t iļ¬€ there are no elements in collection.
(empty? collection) ā‰” (zero? (size collection))
[Function]size collection
Returns the number of elements in collection.
[Function]Setter list-ref
See Section 3.14.3 [Setters], page 37, for a deļ¬nition of setter. N.B. (setter
list-ref) doesnā€™t work properly for element 0 of a list.
Here is a sample collection: simple-table which is also a table.
(define-predicate TABLE?)
(define-operation (LOOKUP table key failure-object))
(define-operation (ASSOCIATE! table key value)) ;; returns key
(define-operation (REMOVE! table key)) ;; returns value
(define (MAKE-SIMPLE-TABLE)
(let ( (table (list)) )
(object
;; table behaviors
((TABLE? self) #t)
((SIZE self) (size table))
((PRINT self port) (format port "#<SIMPLE-TABLE>"))
((LOOKUP self key failure-object)
(cond
((assq key table) => cdr)
(else failure-object)
))
((ASSOCIATE! self key value)
(cond
((assq key table)
Chapter 7: Other Packages 213
=> (lambda (bucket) (set-cdr! bucket value) key))
(else
(set! table (cons (cons key value) table))
key)
))
((REMOVE! self key);; returns old value
(cond
((null? table) (slib:error "TABLE:REMOVE! Key not found: " key))
((eq? key (caar table))
(let ( (value (cdar table)) )
(set! table (cdr table))
value)
)
(else
(let loop ( (last table) (this (cdr table)) )
(cond
((null? this)
(slib:error "TABLE:REMOVE! Key not found: " key))
((eq? key (caar this))
(let ( (value (cdar this)) )
(set-cdr! last (cdr this))
value)
)
(else
(loop (cdr last) (cdr this)))
) ) )
))
;; collection behaviors
((COLLECTION? self) #t)
((GEN-KEYS self) (collect:list-gen-elts (map car table)))
((GEN-ELTS self) (collect:list-gen-elts (map cdr table)))
((FOR-EACH-KEY self proc)
(for-each (lambda (bucket) (proc (car bucket))) table)
)
((FOR-EACH-ELT self proc)
(for-each (lambda (bucket) (proc (cdr bucket))) table)
) ) ) )
7.1.11 Dynamic Data Type
(require ā€™dynamic)
[Function]make-dynamic obj
Create and returns a new dynamic whose global value is obj.
[Function]dynamic? obj
Returns true if and only if obj is a dynamic. No object satisfying dynamic? satisļ¬es
any of the other standard type predicates.
Chapter 7: Other Packages 214
[Function]dynamic-ref dyn
Return the value of the given dynamic in the current dynamic environment.
[Procedure]dynamic-set! dyn obj
Change the value of the given dynamic to obj in the current dynamic environment.
The returned value is unspeciļ¬ed.
[Function]call-with-dynamic-binding dyn obj thunk
Invoke and return the value of the given thunk in a new, nested dynamic environment
in which the given dynamic has been bound to a new location whose initial contents
are the value obj. This dynamic environment has precisely the same extent as the
invocation of the thunk and is thus captured by continuations created within that
invocation and re-established by those continuations when they are invoked.
The dynamic-bind macro is not implemented.
7.1.12 Hash Tables
(require ā€™hash-table)
[Function]predicate->hash pred
Returns a hash function (like hashq, hashv, or hash) corresponding to the equality
predicate pred. pred should be eq?, eqv?, equal?, =, char=?, char-ci=?, string=?,
or string-ci=?.
A hash table is a vector of association lists.
[Function]make-hash-table k
Returns a vector of k empty (association) lists.
Hash table functions provide utilities for an associative database. These functions take an
equality predicate, pred, as an argument. pred should be eq?, eqv?, equal?, =, char=?,
char-ci=?, string=?, or string-ci=?.
[Function]predicate->hash-asso pred
Returns a hash association function of 2 arguments, key and hashtab, corresponding
to pred. The returned function returns a key-value pair whose key is pred-equal to
its ļ¬rst argument or #f if no key in hashtab is pred-equal to the ļ¬rst argument.
[Function]hash-inquirer pred
Returns a procedure of 2 arguments, hashtab and key, which returns the value asso-
ciated with key in hashtab or #f if key does not appear in hashtab.
[Function]hash-associator pred
Returns a procedure of 3 arguments, hashtab, key, and value, which modiļ¬es hashtab
so that key and value associated. Any previous value associated with key will be lost.
[Function]hash-remover pred
Returns a procedure of 2 arguments, hashtab and key, which modiļ¬es hashtab so that
the association whose key is key is removed.
Chapter 7: Other Packages 215
[Function]hash-map proc hash-table
Returns a new hash table formed by mapping proc over the keys and values of hash-
table. proc must be a function of 2 arguments which returns the new value part.
[Function]hash-for-each proc hash-table
Applies proc to each pair of keys and values of hash-table. proc must be a function
of 2 arguments. The returned value is unspeciļ¬ed.
[Function]hash-rehasher pred
hash-rehasher accepts a hash table predicate and returns a function of two argu-
ments hashtab and new-k which is specialized for that predicate.
This function is used for nondestrutively resizing a hash table. hashtab should be an
existing hash-table using pred, new-k is the size of a new hash table to be returned.
The new hash table will have all of the associations of the old hash table.
7.1.13 Macroless Object System
(require ā€™object)
This is the Macroless Object System written by Wade Humeniuk (whume-
[email protected]). Conceptual Tributes: Section 3.14 [Yasos], page 35, MacSchemeā€™s %object,
CLOS, Lack of R4RS macros.
7.1.14 Concepts
OBJECT An object is an ordered association-list (by eq?) of methods (procedures).
Methods can be added (make-method!), deleted (unmake-method!) and re-
trieved (get-method). Objects may inherit methods from other objects. The
object binds to the environment it was created in, allowing closures to be used
to hide private procedures and data.
GENERIC-METHOD
A generic-method associates (in terms of eq?) objectā€™s method. This allows
scheme function style to be used for objects. The calling scheme for using a
generic method is (generic-method object param1 param2 ...).
METHOD A method is a procedure that exists in the object. To use a method get-method
must be called to look-up the method. Generic methods implement the get-
method functionality. Methods may be added to an object associated with any
scheme obj in terms of eq?
GENERIC-PREDICATE
A generic method that returns a boolean value for any scheme obj.
PREDICATE
A objectā€™s method asscociated with a generic-predicate. Returns #t.
7.1.15 Procedures
[Function]make-object ancestor . . .
Returns an object. Current object implementation is a tagged vector. ancestors are
optional and must be objects in terms of object?. ancestors methods are included
Chapter 7: Other Packages 216
in the object. Multiple ancestors might associate the same generic-method with a
method. In this case the method of the ancestor ļ¬rst appearing in the list is the one
returned by get-method.
[Function]object? obj
Returns boolean value whether obj was created by make-object.
[Function]make-generic-method exception-procedure
Returns a procedure which be associated with an objectā€™s methods. If exception-
procedure is speciļ¬ed then it is used to process non-objects.
[Function]make-generic-predicate
Returns a boolean procedure for any scheme object.
[Function]make-method! object generic-method method
Associates method to the generic-method in the object. The method over-
rides any previous association with the generic-method within the object.
Using unmake-method! will restore the objectā€™s previous association with the
generic-method. method must be a procedure.
[Function]make-predicate! object generic-preciate
Makes a predicate method associated with the generic-predicate.
[Function]unmake-method! object generic-method
Removes an objectā€™s association with a generic-method .
[Function]get-method object generic-method
Returns the objectā€™s method associated (if any) with the generic-method. If no asso-
ciated method exists an error is ļ¬‚agged.
7.1.16 Examples
(require ā€™object)
(define instantiate (make-generic-method))
(define (make-instance-object . ancestors)
(define self (apply make-object
(map (lambda (obj) (instantiate obj)) ancestors)))
(make-method! self instantiate (lambda (self) self))
self)
(define who (make-generic-method))
(define imigrate! (make-generic-method))
(define emigrate! (make-generic-method))
(define describe (make-generic-method))
(define name (make-generic-method))
(define address (make-generic-method))
(define members (make-generic-method))
Chapter 7: Other Packages 217
(define society
(let ()
(define self (make-instance-object))
(define population ā€™())
(make-method! self imigrate!
(lambda (new-person)
(if (not (eq? new-person self))
(set! population (cons new-person population)))))
(make-method! self emigrate!
(lambda (person)
(if (not (eq? person self))
(set! population
(comlist:remove-if (lambda (member)
(eq? member person))
population)))))
(make-method! self describe
(lambda (self)
(map (lambda (person) (describe person)) population)))
(make-method! self who
(lambda (self) (map (lambda (person) (name person))
population)))
(make-method! self members (lambda (self) population))
self))
(define (make-person %name %address)
(define self (make-instance-object society))
(make-method! self name (lambda (self) %name))
(make-method! self address (lambda (self) %address))
(make-method! self who (lambda (self) (name self)))
(make-method! self instantiate
(lambda (self)
(make-person (string-append (name self) "-son-of")
%address)))
(make-method! self describe
(lambda (self) (list (name self) (address self))))
(imigrate! self)
self)
7.1.16.1 Inverter Documentation
Inheritance:
<inverter>::(<number> <description>)
Generic-methods
<inverter>::value
ā‡’
<number>::value
<inverter>::set-value!
ā‡’
<number>::set-value!
<inverter>::describe
ā‡’
<description>::describe
Chapter 7: Other Packages 218
<inverter>::help
<inverter>::invert
<inverter>::inverter?
7.1.16.2 Number Documention
Inheritance
<number>::()
Slots
<number>::<x>
Generic Methods
<number>::value
<number>::set-value!
7.1.16.3 Inverter code
(require ā€™object)
(define value (make-generic-method (lambda (val) val)))
(define set-value! (make-generic-method))
(define invert (make-generic-method
(lambda (val)
(if (number? val)
(/ 1 val)
(error "Method not supported:" val)))))
(define noop (make-generic-method))
(define inverter? (make-generic-predicate))
(define describe (make-generic-method))
(define help (make-generic-method))
(define (make-number x)
(define self (make-object))
(make-method! self value (lambda (this) x))
(make-method! self set-value!
(lambda (this new-value) (set! x new-value)))
self)
(define (make-description str)
(define self (make-object))
(make-method! self describe (lambda (this) str))
(make-method! self help (lambda (this) "Help not available"))
self)
(define (make-inverter)
(let* ((self (make-object
(make-number 1)
(make-description "A number which can be inverted")))
Chapter 7: Other Packages 219
(<value> (get-method self value)))
(make-method! self invert (lambda (self) (/ 1 (<value> self))))
(make-predicate! self inverter?)
(unmake-method! self help)
(make-method! self help
(lambda (self)
(display "Inverter Methods:") (newline)
(display " (value inverter) ==> n") (newline)))
self))
;;;; Try it out
(define invert! (make-generic-method))
(define x (make-inverter))
(make-method! x invert! (lambda (x) (set-value! x (/ 1 (value x)))))
(value x)
ā‡’
1
(set-value! x 33)
ā‡’
undefined
(invert! x)
ā‡’
undefined
(value x)
ā‡’
1/33
(unmake-method! x invert!)
ā‡’
undefined
(invert! x)
error
ERROR: Method not supported: x
7.1.17 Priority Queues
(require ā€™priority-queue)
This algorithm for priority queues is due to Introduction to Algorithms by T. Cormen, C.
Leiserson, R. Rivest. 1989 MIT Press.
[Function]make-heap pred<?
Returns a binary heap suitable which can be used for priority queue operations.
[Function]heap-length heap
Returns the number of elements in heap.
[Procedure]heap-insert! heap item
Inserts item into heap. item can be inserted multiple times. The value returned is
unspeciļ¬ed.
[Procedure]heap-extract-max! heap
Returns the item which is larger than all others according to the pred<? argument to
make-heap. If there are no items in heap, an error is signaled.
7.1.18 Queues
(require ā€™queue)
Chapter 7: Other Packages 220
A queue is a list where elements can be added to both the front and rear, and removed
from the front (i.e., they are what are often called dequeues). A queue may also be used
like a stack.
[Function]make-queue
Returns a new, empty queue.
[Function]queue? obj
Returns #t if obj is a queue.
[Function]queue-empty? q
Returns #t if the queue q is empty.
[Procedure]queue-push! q datum
Adds datum to the front of queue q.
[Procedure]enqueue! q datum
Adds datum to the rear of queue q.
[Procedure]dequeue! q
[Procedure]queue-pop! q
Both of these procedures remove and return the datum at the front of the queue.
queue-pop! is used to suggest that the queue is being used like a stack.
All of the following functions raise an error if the queue q is empty.
[Procedure]dequeue-all! q
Removes and returns (the list) of all contents of queue q.
[Function]queue-front q
Returns the datum at the front of the queue q.
[Function]queue-rear q
Returns the datum at the rear of the queue q.
7.1.19 Records
(require ā€™record)
The Record package provides a facility for user to deļ¬ne their own record data types.
[Function]make-record-type type-name ļ¬eld-names
Returns a record-type descriptor, a value representing a new data type disjoint from
all others. The type-name argument must be a string, but is only used for debugging
purposes (such as the printed representation of a record of the new type). The ļ¬eld-
names argument is a list of symbols naming the ļ¬elds of a record of the new type.
It is an error if the list contains any duplicates. It is unspeciļ¬ed how record-type
descriptors are represented.
[Function]record-constructor rtd [ļ¬eld-names]
Returns a procedure for constructing new members of the type represented by rtd.
The returned procedure accepts exactly as many arguments as there are symbols in the
Chapter 7: Other Packages 221
given list, ļ¬eld-names; these are used, in order, as the initial values of those ļ¬elds in a
new record, which is returned by the constructor procedure. The values of any ļ¬elds
not named in that list are unspeciļ¬ed. The ļ¬eld-names argument defaults to the list
of ļ¬eld names in the call to make-record-type that created the type represented by
rtd; if the ļ¬eld-names argument is provided, it is an error if it contains any duplicates
or any symbols not in the default list.
[Function]record-predicate rtd
Returns a procedure for testing membership in the type represented by rtd. The
returned procedure accepts exactly one argument and returns a true value if the
argument is a member of the indicated record type; it returns a false value otherwise.
[Function]record-accessor rtd ļ¬eld-name
Returns a procedure for reading the value of a particular ļ¬eld of a member of the type
represented by rtd. The returned procedure accepts exactly one argument which must
be a record of the appropriate type; it returns the current value of the ļ¬eld named by
the symbol ļ¬eld-name in that record. The symbol ļ¬eld-name must be a member of the
list of ļ¬eld-names in the call to make-record-type that created the type represented
by rtd.
[Function]record-modifier rtd ļ¬eld-name
Returns a procedure for writing the value of a particular ļ¬eld of a member of the type
represented by rtd. The returned procedure accepts exactly two arguments: ļ¬rst, a
record of the appropriate type, and second, an arbitrary Scheme value; it modiļ¬es
the ļ¬eld named by the symbol ļ¬eld-name in that record to contain the given value.
The returned value of the modiļ¬er procedure is unspeciļ¬ed. The symbol ļ¬eld-name
must be a member of the list of ļ¬eld-names in the call to make-record-type that
created the type represented by rtd.
In May of 1996, as a product of discussion on the rrrs-authors mailing list, I rewrote
record.scm to portably implement type disjointness for record data types.
As long as an implementationā€™s procedures are opaque and the record code is loaded
before other programs, this will give disjoint record types which are unforgeable and incor-
ruptible by R4RS procedures.
As a consequence, the procedures record?, record-type-descriptor, record-type-
name.and record-type-field-names are no longer supported.
7.2 Sorting and Searching
7.2.1 Common List Functions
(require ā€™common-list-functions)
The procedures below follow the Common LISP equivalents apart from optional argu-
ments in some cases.
7.2.1.1 List construction
[Function]make-list k
Chapter 7: Other Packages 222
[Function]make-list k init
make-list creates and returns a list of k elements. If init is included, all elements in
the list are initialized to init.
Example:
(make-list 3)
ā‡’
(#<unspecified> #<unspecified> #<unspecified>)
(make-list 5 ā€™foo)
ā‡’
(foo foo foo foo foo)
[Function]list* obj1 obj2 . . .
Works like list except that the cdr of the last pair is the last argument unless there
is only one argument, when the result is just that argument. Sometimes called cons*.
E.g.:
(list* 1)
ā‡’
1
(list* 1 2 3)
ā‡’
(1 2 . 3)
(list* 1 2 ā€™(3 4))
ā‡’
(1 2 3 4)
(list* args ā€™())
ā‰” (list args)
[Function]copy-list lst
copy-list makes a copy of lst using new pairs and returns it. Only the top level
of the list is copied, i.e., pairs forming elements of the copied list remain eq? to the
corresponding elements of the original; the copy is, however, not eq? to the original,
but is equal? to it.
Example:
(copy-list ā€™(foo foo foo))
ā‡’
(foo foo foo)
(define q ā€™(foo bar baz bang))
(define p q)
(eq? p q)
ā‡’
#t
(define r (copy-list q))
(eq? q r)
ā‡’
#f
(equal? q r)
ā‡’
#t
(define bar ā€™(bar))
(eq? bar (car (copy-list (list bar ā€™foo))))
ā‡’
#t
7.2.1.2 Lists as sets
eqv? is used to test for membership by procedures which treat lists as sets.
Chapter 7: Other Packages 223
[Function]adjoin e l
adjoin returns the adjoint of the element e and the list l. That is, if e is in l, adjoin
returns l, otherwise, it returns (cons e l).
Example:
(adjoin ā€™baz ā€™(bar baz bang))
ā‡’
(bar baz bang)
(adjoin ā€™foo ā€™(bar baz bang))
ā‡’
(foo bar baz bang)
[Function]union l1 l2
union returns a list of all elements that are in l1 or l2. Duplicates between l1 and l2
are culled. Duplicates within l1 or within l2 may or may not be removed.
Example:
(union ā€™(1 2 3 4) ā€™(5 6 7 8))
ā‡’
(1 2 3 4 5 6 7 8)
(union ā€™(0 1 2 3 4) ā€™(3 4 5 6))
ā‡’
(5 6 0 1 2 3 4)
[Function]intersection l1 l2
intersection returns a list of all elements that are in both l1 and l2.
Example:
(intersection ā€™(1 2 3 4) ā€™(3 4 5 6))
ā‡’
(3 4)
(intersection ā€™(1 2 3 4) ā€™(5 6 7 8))
ā‡’
()
[Function]set-difference l1 l2
set-difference returns a list of all elements that are in l1 but not in l2.
Example:
(set-difference ā€™(1 2 3 4) ā€™(3 4 5 6))
ā‡’
(1 2)
(set-difference ā€™(1 2 3 4) ā€™(1 2 3 4 5 6))
ā‡’
()
[Function]subset? list1 list2
Returns #t if every element of list1 is eqv? an element of list2; otherwise returns #f.
Example:
(subset? ā€™(1 2 3 4) ā€™(3 4 5 6))
ā‡’
#f
(subset? ā€™(1 2 3 4) ā€™(6 5 4 3 2 1 0))
ā‡’
#t
[Function]member-if pred lst
member-if returns the list headed by the ļ¬rst element of lst to satisfy (pred
element). Member-if returns #f if pred returns #f for every element in lst.
Chapter 7: Other Packages 224
Example:
(member-if vector? ā€™(a 2 b 4))
ā‡’
#f
(member-if number? ā€™(a 2 b 4))
ā‡’
(2 b 4)
[Function]some pred lst1 lst2 . . .
pred is a boolean function of as many arguments as there are list arguments to some
i.e., lst plus any optional arguments. pred is applied to successive elements of the list
arguments in order. some returns #t as soon as one of these applications returns #t,
and is #f if none returns #t. All the lists should have the same length.
Example:
(some odd? ā€™(1 2 3 4))
ā‡’
#t
(some odd? ā€™(2 4 6 8))
ā‡’
#f
(some > ā€™(1 3) ā€™(2 4))
ā‡’
#f
[Function]every pred lst1 lst2 . . .
every is analogous to some except it returns #t if every application of pred is #t and
#f otherwise.
Example:
(every even? ā€™(1 2 3 4))
ā‡’
#f
(every even? ā€™(2 4 6 8))
ā‡’
#t
(every > ā€™(2 3) ā€™(1 4))
ā‡’
#f
[Function]notany pred lst1 . . .
notany is analogous to some but returns #t if no application of pred returns #t or #f
as soon as any one does.
[Function]notevery pred lst1 . . .
notevery is analogous to some but returns #t as soon as an application of pred returns
#f, and #f otherwise.
Example:
(notevery even? ā€™(1 2 3 4))
ā‡’
#t
(notevery even? ā€™(2 4 6 8))
Chapter 7: Other Packages 225
ā‡’
#f
[Function]list-of?? predicate
Returns a predicate which returns true if its argument is a list every element of which
satisļ¬es predicate.
[Function]list-of?? predicate low-bound high-bound
low-bound and high-bound are non-negative integers. list-of?? returns a predicate
which returns true if its argument is a list of length between low-bound and high-
bound (inclusive); every element of which satisļ¬es predicate.
[Function]list-of?? predicate bound
bound is an integer. If bound is negative, list-of?? returns a predicate which
returns true if its argument is a list of length greater than (- bound); every element
of which satisļ¬es predicate. Otherwise, list-of?? returns a predicate which returns
true if its argument is a list of length less than or equal to bound; every element of
which satisļ¬es predicate.
[Function]find-if pred lst
find-if searches for the ļ¬rst element in lst such that (pred element) returns #t. If
it ļ¬nds any such element in lst, element is returned. Otherwise, #f is returned.
Example:
(find-if number? ā€™(foo 1 bar 2))
ā‡’
1
(find-if number? ā€™(foo bar baz bang))
ā‡’
#f
(find-if symbol? ā€™(1 2 foo bar))
ā‡’
foo
[Function]remove elt lst
remove removes all occurrences of elt from lst using eqv? to test for equality and
returns everything thatā€™s left. N.B.: other implementations (Chez, Scheme->C and
T, at least) use equal? as the equality test.
Example:
(remove 1 ā€™(1 2 1 3 1 4 1 5))
ā‡’
(2 3 4 5)
(remove ā€™foo ā€™(bar baz bang))
ā‡’
(bar baz bang)
[Function]remove-if pred lst
remove-if removes all elements from lst where (pred element) is #t and returns
everything thatā€™s left.
Example:
(remove-if number? ā€™(1 2 3 4))
Chapter 7: Other Packages 226
ā‡’
()
(remove-if even? ā€™(1 2 3 4 5 6 7 8))
ā‡’
(1 3 5 7)
[Function]remove-if-not pred lst
remove-if-not removes all elements from lst for which (pred element) is #f and
returns everything thatā€™s left.
Example:
(remove-if-not number? ā€™(foo bar baz))
ā‡’
()
(remove-if-not odd? ā€™(1 2 3 4 5 6 7 8))
ā‡’
(1 3 5 7)
[Function]has-duplicates? lst
returns #t if 2 members of lst are equal?, #f otherwise.
Example:
(has-duplicates? ā€™(1 2 3 4))
ā‡’
#f
(has-duplicates? ā€™(2 4 3 4))
ā‡’
#t
The procedure remove-duplicates uses member (rather than memv).
[Function]remove-duplicates lst
returns a copy of lst with its duplicate members removed. Elements are considered
duplicate if they are equal?.
Example:
(remove-duplicates ā€™(1 2 3 4))
ā‡’
(1 2 3 4)
(remove-duplicates ā€™(2 4 3 4))
ā‡’
(2 4 3)
7.2.1.3 Lists as sequences
[Function]position obj lst
position returns the 0-based position of obj in lst, or #f if obj does not occur in lst.
Example:
(position ā€™foo ā€™(foo bar baz bang))
ā‡’
0
(position ā€™baz ā€™(foo bar baz bang))
ā‡’
2
(position ā€™oops ā€™(foo bar baz bang))
ā‡’
#f
Chapter 7: Other Packages 227
[Function]reduce p lst
reduce combines all the elements of a sequence using a binary operation (the com-
bination is left-associative). For example, using +, one can add up all the elements.
reduce allows you to apply a function which accepts only two arguments to more than
2 objects. Functional programmers usually refer to this as foldl. collect:reduce
(see Section 7.1.10 [Collections], page 210) provides a version of collect generalized
to collections.
Example:
(reduce + ā€™(1 2 3 4))
ā‡’
10
(define (bad-sum . l) (reduce + l))
(bad-sum 1 2 3 4)
ā‰” (reduce + (1 2 3 4))
ā‰” (+ (+ (+ 1 2) 3) 4)
ā‡’
10
(bad-sum)
ā‰” (reduce + ())
ā‡’
()
(reduce string-append ā€™("hello" "cruel" "world"))
ā‰” (string-append (string-append "hello" "cruel") "world")
ā‡’
"hellocruelworld"
(reduce anything ā€™())
ā‡’
()
(reduce anything ā€™(x))
ā‡’
x
What follows is a rather non-standard implementation of reverse in terms of reduce
and a combinator elsewhere called C.
;;; Contributed by Jussi Piitulainen (jpiitula @ ling.helsinki.fi)
(define commute
(lambda (f)
(lambda (x y)
(f y x))))
(define reverse
(lambda (args)
(reduce-init (commute cons) ā€™() args)))
[Function]reduce-init p init lst
reduce-init is the same as reduce, except that it implicitly inserts init at the start of
the list. reduce-init is preferred if you want to handle the null list, the one-element,
and lists with two or more elements consistently. It is common to use the operatorā€™s
idempotent as the initializer. Functional programmers usually call this foldl.
Example:
(define (sum . l) (reduce-init + 0 l))
Chapter 7: Other Packages 228
(sum 1 2 3 4)
ā‰” (reduce-init + 0 (1 2 3 4))
ā‰” (+ (+ (+ (+ 0 1) 2) 3) 4)
ā‡’
10
(sum)
ā‰” (reduce-init + 0 ā€™())
ā‡’
0
(reduce-init string-append "@" ā€™("hello" "cruel" "world"))
ā‰”
(string-append (string-append (string-append "@" "hello")
"cruel")
"world")
ā‡’
"@hellocruelworld"
Given a diļ¬€erentiation of 2 arguments, diff, the following will diļ¬€erentiate by any
number of variables.
(define (diff* exp . vars)
(reduce-init diff exp vars))
Example:
;;; Real-world example: Insertion sort using reduce-init.
(define (insert l item)
(if (null? l)
(list item)
(if (< (car l) item)
(cons (car l) (insert (cdr l) item))
(cons item l))))
(define (insertion-sort l) (reduce-init insert ā€™() l))
(insertion-sort ā€™(3 1 4 1 5)
ā‰” (reduce-init insert () (3 1 4 1 5))
ā‰” (insert (insert (insert (insert (insert () 3) 1) 4) 1) 5)
ā‰” (insert (insert (insert (insert (3)) 1) 4) 1) 5)
ā‰” (insert (insert (insert (1 3) 4) 1) 5)
ā‰” (insert (insert (1 3 4) 1) 5)
ā‰” (insert (1 1 3 4) 5)
ā‡’
(1 1 3 4 5)
[Function]last lst n
last returns the last n elements of lst. n must be a non-negative integer.
Example:
(last ā€™(foo bar baz bang) 2)
ā‡’
(baz bang)
(last ā€™(1 2 3) 0)
Chapter 7: Other Packages 229
ā‡’
()
[Function]butlast lst n
butlast returns all but the last n elements of lst.
Example:
(butlast ā€™(a b c d) 3)
ā‡’
(a)
(butlast ā€™(a b c d) 4)
ā‡’
()
last and butlast split a list into two parts when given identical arguments.
(last ā€™(a b c d e) 2)
ā‡’
(d e)
(butlast ā€™(a b c d e) 2)
ā‡’
(a b c)
[Function]nthcdr n lst
nthcdr takes n cdrs of lst and returns the result. Thus (nthcdr 3 lst) ā‰” (cdddr
lst)
Example:
(nthcdr 2 ā€™(a b c d))
ā‡’
(c d)
(nthcdr 0 ā€™(a b c d))
ā‡’
(a b c d)
[Function]butnthcdr n lst
butnthcdr returns all but the nthcdr n elements of lst.
Example:
(butnthcdr 3 ā€™(a b c d))
ā‡’
(a b c)
(butnthcdr 4 ā€™(a b c d))
ā‡’
(a b c d)
nthcdr and butnthcdr split a list into two parts when given identical arguments.
(nthcdr 2 ā€™(a b c d e))
ā‡’
(c d e)
(butnthcdr 2 ā€™(a b c d e))
ā‡’
(a b)
[Function]butnth n lst
butnth returns a list of all but the nth element of lst.
Example:
(butnth 2 ā€™(a b c d))
ā‡’
(a b d)
(butnth 4 ā€™(a b c d))
ā‡’
(a b c d)
Chapter 7: Other Packages 230
7.2.1.4 Destructive list operations
These procedures may mutate the list they operate on, but any such mutation is undeļ¬ned.
[Procedure]nconc args
nconc destructively concatenates its arguments. (Compare this with append, which
copies arguments rather than destroying them.) Sometimes called append! (see
Section 7.4.4 [Rev2 Procedures], page 249).
Example: You want to ļ¬nd the subsets of a set. Hereā€™s the obvious way:
(define (subsets set)
(if (null? set)
ā€™(())
(append (map (lambda (sub) (cons (car set) sub))
(subsets (cdr set)))
(subsets (cdr set)))))
But that does way more consing than you need. Instead, you could replace the append
with nconc, since you donā€™t have any need for all the intermediate results.
Example:
(define x ā€™(a b c))
(define y ā€™(d e f))
(nconc x y)
ā‡’
(a b c d e f)
x
ā‡’
(a b c d e f)
nconc is the same as append! in sc2.scm.
[Procedure]nreverse lst
nreverse reverses the order of elements in lst by mutating cdrs of the list. Sometimes
called reverse!.
Example:
(define foo ā€™(a b c))
(nreverse foo)
ā‡’
(c b a)
foo
ā‡’
(a)
Some people have been confused about how to use nreverse, thinking that it doesnā€™t
return a value. It needs to be pointed out that
(set! lst (nreverse lst))
is the proper usage, not
(nreverse lst)
The example should suļ¬ƒce to show why this is the case.
[Procedure]delete elt lst
[Procedure]delete-if pred lst
Chapter 7: Other Packages 231
[Procedure]delete-if-not pred lst
Destructive versions of remove remove-if, and remove-if-not.
Example:
(define lst (list ā€™foo ā€™bar ā€™baz ā€™bang))
(delete ā€™foo lst)
ā‡’
(bar baz bang)
lst
ā‡’
(foo bar baz bang)
(define lst (list 1 2 3 4 5 6 7 8 9))
(delete-if odd? lst)
ā‡’
(2 4 6 8)
lst
ā‡’
(1 2 4 6 8)
Some people have been confused about how to use delete, delete-if, and
delete-if, thinking that they donā€™t return a value. It needs to be pointed out that
(set! lst (delete el lst))
is the proper usage, not
(delete el lst)
The examples should suļ¬ƒce to show why this is the case.
7.2.1.5 Non-List functions
[Function]and? arg1 . . .
and? checks to see if all its arguments are true. If they are, and? returns #t, otherwise,
#f. (In contrast to and, this is a function, so all arguments are always evaluated and
in an unspeciļ¬ed order.)
Example:
(and? 1 2 3)
ā‡’
#t
(and #f 1 2)
ā‡’
#f
[Function]or? arg1 . . .
or? checks to see if any of its arguments are true. If any is true, or? returns #t, and
#f otherwise. (To or as and? is to and.)
Example:
(or? 1 2 #f)
ā‡’
#t
(or? #f #f #f)
ā‡’
#f
[Function]atom? object
Returns #t if object is not a pair and #f if it is pair. (Called atom in Common LISP.)
Chapter 7: Other Packages 232
(atom? 1)
ā‡’
#t
(atom? ā€™(1 2))
ā‡’
#f
(atom? #(1 2)) ; dubious!
ā‡’
#t
7.2.2 Tree operations
(require ā€™tree)
These are operations that treat lists a representations of trees.
[Function]subst new old tree
[Function]substq new old tree
[Function]substv new old tree
[Function]subst new old tree equ?
subst makes a copy of tree, substituting new for every subtree or leaf of tree which is
equal? to old and returns a modiļ¬ed tree. The original tree is unchanged, but may
share parts with the result.
substq and substv are similar, but test against old using eq? and eqv? respectively.
If subst is called with a fourth argument, equ? is the equality predicate.
Examples:
(substq ā€™tempest ā€™hurricane ā€™(shakespeare wrote (the hurricane)))
ā‡’
(shakespeare wrote (the tempest))
(substq ā€™foo ā€™() ā€™(shakespeare wrote (twelfth night)))
ā‡’
(shakespeare wrote (twelfth night . foo) . foo)
(subst ā€™(a . cons) ā€™(old . pair)
ā€™((old . spice) ((old . shoes) old . pair) (old . pair)))
ā‡’
((old . spice) ((old . shoes) a . cons) (a . cons))
[Function]copy-tree tree
Makes a copy of the nested list structure tree using new pairs and returns it. All
levels are copied, so that none of the pairs in the tree are eq? to the original ones ā€“
only the leaves are.
Example:
(define bar ā€™(bar))
(copy-tree (list bar ā€™foo))
ā‡’
((bar) foo)
(eq? bar (car (copy-tree (list bar ā€™foo))))
ā‡’
#f
7.2.3 Chapter Ordering
(require ā€™chapter-order)
The ā€˜chap:ā€™ functions deal with strings which are ordered like chapter numbers (or
letters) in a book. Each section of the string consists of consecutive numeric or consecutive
aphabetic characters of like case.
Chapter 7: Other Packages 233
[Function]chap:string<? string1 string2
Returns #t if the ļ¬rst non-matching run of alphabetic upper-case or the ļ¬rst non-
matching run of alphabetic lower-case or the ļ¬rst non-matching run of numeric char-
acters of string1 is string<? than the corresponding non-matching run of characters
of string2.
(chap:string<? "a.9" "a.10")
ā‡’
#t
(chap:string<? "4c" "4aa")
ā‡’
#t
(chap:string<? "Revised^{3.99}" "Revised^{4}")
ā‡’
#t
[Function]chap:string>? string1 string2
[Function]chap:string<=? string1 string2
[Function]chap:string>=? string1 string2
Implement the corresponding chapter-order predicates.
[Function]chap:next-string string
Returns the next string in the chapter order. If string has no alphabetic or numeric
characters, (string-append string "0") is returnd. The argument to chap:next-
string will always be chap:string<? than the result.
(chap:next-string "a.9")
ā‡’
"a.10"
(chap:next-string "4c")
ā‡’
"4d"
(chap:next-string "4z")
ā‡’
"4aa"
(chap:next-string "Revised^{4}")
ā‡’
"Revised^{5}"
7.2.4 Sorting
(require ā€™sort) or (require ā€™srfi-95)
[by Richard A. Oā€™Keefe, 1991]
I am providing this source code with no restrictions at all on its use (but please retain
D.H.D.Warrenā€™s credit for the original idea).
The code of merge and merge! could have been quite a bit simpler, but they have been
coded to reduce the amount of work done per iteration. (For example, we only have one
null? test per iteration.)
I gave serious consideration to producing Common-LISP-compatible functions. How-
ever, Common LISPā€™s sort is our sort! (well, in fact Common LISPā€™s stable-sort is our
sort!; merge sort is fast as well as stable!) so adapting CL code to Scheme takes a bit of
work anyway. I did, however, appeal to CL to determine the order of the arguments.
The standard functions <, >, char<?, char>?, char-ci<?, char-ci>?, string<?,
string>?, string-ci<?, and string-ci>? are suitable for use as comparison functions.
Think of (less? x y) as saying when x must not precede y.
[Addendum by Aubrey Jaļ¬€er, 2006]
These procedures are stable when called with predicates which return #f when applied
to identical arguments.
The sorted?, merge, and merge! procedures consume asymptotic time and space no
larger than O(N), where N is the sum of the lengths of the sequence arguments. The sort
Chapter 7: Other Packages 234
and sort! procedures consume asymptotic time and space no larger than O(N*log(N)),
where N is the length of the sequence argument.
All ļ¬ve functions take an optional key argument corresponding to a CL-style ā€˜&keyā€™
argument. A less? predicate with a key argument behaves like:
(lambda (x y) (less? (key x) (key y)))
All ļ¬ve functions will call the key argument at most once per element.
The ā€˜!ā€™ variants sort in place; sort! returns its sequence argument.
[Function]sorted? sequence less?
[Function]sorted? sequence less? key
Returns #t when the sequence argument is in non-decreasing order according to less?
(that is, there is no adjacent pair ... x y ... for which (less? y x)).
Returns #f when the sequence contains at least one out-of-order pair. It is an error
if the sequence is not a list or array (including vectors and strings).
[Function]merge list1 list2 less?
[Function]merge list1 list2 less? key
Merges two sorted lists, returning a freshly allocated list as its result.
[Function]merge! list1 list2 less?
[Function]merge! list1 list2 less? key
Merges two sorted lists, re-using the pairs of list1 and list2 to build the result. The
result will be either list1 or list2.
[Function]sort sequence less?
[Function]sort sequence less? key
Accepts a list or array (including vectors and strings) for sequence; and returns a
completely new sequence which is sorted according to less?. The returned sequence
is the same type as the argument sequence. Given valid arguments, it is always the
case that:
(sorted? (sort sequence less?) less?)
ā‡’
#t
[Function]sort! sequence less?
[Function]sort! sequence less? key
Returns list, array, vector, or string sequence which has been mutated to order its
elements according to less?. Given valid arguments, it is always the case that:
(sorted? (sort! sequence less?) less?)
ā‡’
#t
7.2.5 Topological Sort
(require ā€™topological-sort) or (require ā€™tsort)
The algorithm is inspired by Cormen, Leiserson and Rivest (1990) Introduction to Algo-
rithms, chapter 23.
[Function]tsort dag pred
[Function]topological-sort dag pred
where
Chapter 7: Other Packages 235
dag is a list of sublists. The car of each sublist is a vertex. The cdr is the
adjacency list of that vertex, i.e. a list of all vertices to which there exists
an edge from the car vertex.
pred is one of eq?, eqv?, equal?, =, char=?, char-ci=?, string=?, or
string-ci=?.
Sort the directed acyclic graph dag so that for every edge from vertex u to v, u will
come before v in the resulting list of vertices.
Time complexity: O (|V| + |E|)
Example (from Cormen):
Prof. Bumstead topologically sorts his clothing when getting dressed.
The ļ¬rst argument to tsort describes which garments he needs to put
on before others. (For example, Prof Bumstead needs to put on his shirt
before he puts on his tie or his belt.) tsort gives the correct order of
dressing:
(require ā€™tsort)
(tsort ā€™((shirt tie belt)
(tie jacket)
(belt jacket)
(watch)
(pants shoes belt)
(undershorts pants shoes)
(socks shoes))
eq?)
ā‡’
(socks undershorts pants shoes watch shirt belt tie jacket)
7.2.6 Hashing
(require ā€™hash)
These hashing functions are for use in quickly classifying objects. Hash tables use these
functions.
[Function]hashq obj k
[Function]hashv obj k
[Function]hash obj k
Returns an exact non-negative integer less than k. For each non-negative integer less
than k there are arguments obj for which the hashing functions applied to obj and k
returns that integer.
For hashq, (eq? obj1 obj2) implies (= (hashq obj1 k) (hashq obj2)).
For hashv, (eqv? obj1 obj2) implies (= (hashv obj1 k) (hashv obj2)).
For hash, (equal? obj1 obj2) implies (= (hash obj1 k) (hash obj2)).
hash, hashv, and hashq return in time bounded by a constant. Notice that items
having the same hash implies the items have the same hashv implies the items have
the same hashq.
Chapter 7: Other Packages 236
7.2.7 Space-Filling Curves
7.2.7.1 Multidimensional Space-Filling Curves
(require ā€™space-filling)
The algorithms and cell properties are described in http://people.csail.mit.edu/
jaffer/Geometry/RMDSFF.pdf
[Function]make-cell type rank side precession
[Function]make-cell type rank side
[Function]make-cell type rank
type must be the symbol diagonal, adjacent, or centered. rank must be an integer
larger than 1. side, if present, must be an even integer larger than 1 if type is
adjacent or an odd integer larger than 2 otherwise; side defaults to the smallest
value. precession, if present, must be an integer between 0 and side^rank-1; it is
relevant only when type is diagonal or centered.
[Function]make-cell Hamiltonian-path-vector precession
[Function]make-cell Hamiltonian-path-vector
type must be a vector of side^rank lists of rank of integers encoding the coordinate
positions of a Hamiltonian path on the rank-dimensional grid of points starting and
ending on corners of the grid. The starting corner must be the origin (all-zero coor-
dinates). If the side-length is even, then the ending corner must be non-zero in only
one coordinate; otherwise, the ending corner must be the furthest diagonally opposite
corner from the origin.
make-cell returns a data object suitable for passing as the ļ¬rst argument to
integer->coordinates or coordinates->integer.
Hilbert, Peano, and centered Peano cells are generated respectively by:
(make-cell ā€™adjacent rank 2) ; Hilbert
(make-cell ā€™diagonal rank 3) ; Peano
(make-cell ā€™centered rank 3) ; centered Peano
In the conversion procedures, if the cell is diagonal or adjacent, then the coordinates
and scalar must be nonnegative integers. If centered, then the integers can be negative.
[Function]integer->coordinates cell u
integer->coordinates converts the integer u to a list of coordinates according to
cell.
[Function]coordinates->integer cell v
coordinates->integer converts the list of coordinates v to an integer according to
cell.
coordinates->integer and integer->coordinates are inverse functions when passed the
same cell argument.
7.2.7.2 Hilbert Space-Filling Curve
(require ā€™hilbert-fill)
Chapter 7: Other Packages 237
The Hilbert Space-Filling Curve is a one-to-one mapping between a unit line segment and
an n-dimensional unit cube. This implementation treats the nonnegative integers either as
fractional bits of a given width or as nonnegative integers.
The integer procedures map the non-negative integers to an arbitrarily large n-dimensional
cube with its corner at the origin and all coordinates are non-negative.
For any exact nonnegative integer scalar and exact integer rank > 2,
(= scalar (hilbert-coordinates->integer
(integer->hilbert-coordinates scalar rank)))
ā‡’
#t
When treating integers as k fractional bits,
(= scalar (hilbert-coordinates->integer
(integer->hilbert-coordinates scalar rank k)) k)
ā‡’
#t
[Function]integer->hilbert-coordinates scalar rank
Returns a list of rank integer coordinates corresponding to exact non-negative integer
scalar. The lists returned by integer->hilbert-coordinates for scalar arguments
0 and 1 will diļ¬€er in the ļ¬rst element.
[Function]integer->hilbert-coordinates scalar rank k
scalar must be a nonnegative integer of no more than rank*k bits.
integer->hilbert-coordinates Returns a list of rank k-bit nonnegative integer
coordinates corresponding to exact non-negative integer scalar. The curves generated
by integer->hilbert-coordinates have the same alignment independent of k.
[Function]hilbert-coordinates->integer coords
[Function]hilbert-coordinates->integer coords k
Returns an exact non-negative integer corresponding to coords, a list of non-negative
integer coordinates.
7.2.7.3 Gray code
A Gray code is an ordering of non-negative integers in which exactly one bit diļ¬€ers between
each pair of successive elements. There are multiple Gray codings. An n-bit Gray code
corresponds to a Hamiltonian cycle on an n-dimensional hypercube.
Gray codes ļ¬nd use communicating incrementally changing values between asynchronous
agents. De-laminated Gray codes comprise the coordinates of Hilbert space-ļ¬lling curves.
[Function]integer->gray-code k
Converts k to a Gray code of the same integer-length as k.
[Function]gray-code->integer k
Converts the Gray code k to an integer of the same integer-length as k.
For any non-negative integer k,
(eqv? k (gray-code->integer (integer->gray-code k)))
Chapter 7: Other Packages 238
[Function]= k1 k2
[Function]gray-code<? k1 k2
[Function]gray-code>? k1 k2
[Function]gray-code<=? k1 k2
[Function]gray-code>=? k1 k2
These procedures return #t if their Gray code arguments are (respectively): equal,
monotonically increasing, monotonically decreasing, monotonically nondecreasing, or
monotonically nonincreasing.
For any non-negative integers k1 and k2, the Gray code predicate of (integer->gray-
code k1) and (integer->gray-code k2) will return the same value as the corre-
sponding predicate of k1 and k2.
7.2.7.4 Bitwise Lamination
[Function]delaminate-list count ks
Returns a list of count integers comprised of the jth bit of the integers ks where j
ranges from count-1 to 0.
(map (lambda (k) (number->string k 2))
(delaminate-list 4 ā€™(7 6 5 4 0 0 0 0)))
ā‡’
("0" "11110000" "11000000" "10100000")
delaminate-list is its own inverse:
(delaminate-list 8 (delaminate-list 4 ā€™(7 6 5 4 0 0 0 0)))
ā‡’
(7 6 5 4 0 0 0 0)
7.2.7.5 Peano Space-Filling Curve
(require ā€™peano-fill)
[Function]natural->peano-coordinates scalar rank
Returns a list of rank nonnegative integer coordinates corresponding to exact nonneg-
ative integer scalar. The lists returned by natural->peano-coordinates for scalar
arguments 0 and 1 will diļ¬€er in the ļ¬rst element.
[Function]peano-coordinates->natural coords
Returns an exact nonnegative integer corresponding to coords, a list of nonnegative
integer coordinates.
[Function]integer->peano-coordinates scalar rank
Returns a list of rank integer coordinates corresponding to exact integer scalar. The
lists returned by integer->peano-coordinates for scalar arguments 0 and 1 will
diļ¬€er in the ļ¬rst element.
[Function]peano-coordinates->integer coords
Returns an exact integer corresponding to coords, a list of integer coordinates.
7.2.7.6 Sierpinski Curve
(require ā€™sierpinski)
Chapter 7: Other Packages 239
[Function]make-sierpinski-indexer max-coordinate
Returns a procedure (eg hash-function) of 2 numeric arguments which preserves near-
ness in its mapping from NxN to N.
max-coordinate is the maximum coordinate (a positive integer) of a population of
points. The returned procedures is a function that takes the x and y coordinates of
a point, (non-negative integers) and returns an integer corresponding to the relative
position of that point along a Sierpinski curve. (You can think of this as computing
a (pseudo-) inverse of the Sierpinski spaceļ¬lling curve.)
Example use: Make an indexer (hash-function) for integer points lying in square of
integer grid points [0,99]x[0,99]:
(define space-key (make-sierpinski-indexer 100))
Now letā€™s compute the index of some points:
(space-key 24 78)
ā‡’
9206
(space-key 23 80)
ā‡’
9172
Note that locations (24, 78) and (23, 80) are near in index and therefore, because
the Sierpinski spaceļ¬lling curve is continuous, we know they must also be near in the
plane. Nearness in the plane does not, however, necessarily correspond to nearness
in index, although it tends to be so.
Example applications:
ā€¢ Sort points by Sierpinski index to get heuristic solution to travelling salesman
problem. For details of performance, see L. Platzman and J. Bartholdi, "Spaceļ¬ll-
ing curves and the Euclidean travelling salesman problem", JACM 36(4):719ā€“737
(October 1989) and references therein.
ā€¢ Use Sierpinski index as key by which to store 2-dimensional data in a
1-dimensional data structure (such as a table). Then locations that are near
each other in 2-d space will tend to be near each other in 1-d data structure; and
locations that are near in 1-d data structure will be near in 2-d space. This can
signiļ¬cantly speed retrieval from secondary storage because contiguous regions
in the plane will tend to correspond to contiguous regions in secondary storage.
(This is a standard technique for managing CAD/CAM or geographic data.)
7.2.8 Soundex
(require ā€™soundex)
[Function]soundex name
Computes the soundex hash of name. Returns a string of an initial letter and up to
three digits between 0 and 6. Soundex supposedly has the property that names that
sound similar in normal English pronunciation tend to map to the same key.
Soundex was a classic algorithm used for manual ļ¬ling of personal records before the
advent of computers. It performs adequately for English names but has trouble with
other languages.
See Knuth, Vol. 3 Sorting and searching, pp 391ā€“2
Chapter 7: Other Packages 240
To manage unusual inputs, soundex omits all non-alphabetic characters. Conse-
quently, in this implementation:
(soundex <string of blanks>)
ā‡’
""
(soundex "")
ā‡’
""
Examples from Knuth:
(map soundex ā€™("Euler" "Gauss" "Hilbert" "Knuth"
"Lloyd" "Lukasiewicz"))
ā‡’
("E460" "G200" "H416" "K530" "L300" "L222")
(map soundex ā€™("Ellery" "Ghosh" "Heilbronn" "Kant"
"Ladd" "Lissajous"))
ā‡’
("E460" "G200" "H416" "K530" "L300" "L222")
Some cases in which the algorithm fails (Knuth):
(map soundex ā€™("Rogers" "Rodgers"))
ā‡’
("R262" "R326")
(map soundex ā€™("Sinclair" "St. Clair"))
ā‡’
("S524" "S324")
(map soundex ā€™("Tchebysheff" "Chebyshev"))
ā‡’
("T212" "C121")
7.2.9 String Search
(require ā€™string-search)
[Procedure]string-index string char
[Procedure]string-index-ci string char
Returns the index of the ļ¬rst occurence of char within string, or #f if the string does
not contain a character char.
[Procedure]string-reverse-index string char
[Procedure]string-reverse-index-ci string char
Returns the index of the last occurence of char within string, or #f if the string does
not contain a character char.
[Procedure]substring? pattern string
[Procedure]substring-ci? pattern string
Searches string to see if some substring of string is equal to pattern. substring?
returns the index of the ļ¬rst character of the ļ¬rst substring of string that is equal to
pattern; or #f if string does not contain pattern.
(substring? "rat" "pirate")
ā‡’
2
(substring? "rat" "outrage")
ā‡’
#f
(substring? "" any-string)
ā‡’
0
[Procedure]find-string-from-port? str in-port max-no-chars
Looks for a string str within the ļ¬rst max-no-chars chars of the input port in-port.
[Procedure]find-string-from-port? str in-port
When called with two arguments, the search span is limited by the end of the input
stream.
Chapter 7: Other Packages 241
[Procedure]find-string-from-port? str in-port char
Searches up to the ļ¬rst occurrence of character char in str.
[Procedure]find-string-from-port? str in-port proc
Searches up to the ļ¬rst occurrence of the procedure proc returning non-false when
called with a character (from in-port) argument.
When the str is found, find-string-from-port? returns the number of characters
it has read from the port, and the port is set to read the ļ¬rst char after that (that is,
after the str) The function returns #f when the str isnā€™t found.
find-string-from-port? reads the port strictly sequentially, and does not perform
any buļ¬€ering. So find-string-from-port? can be used even if the in-port is open
to a pipe or other communication channel.
[Function]string-subst txt old1 new1 . . .
Returns a copy of string txt with all occurrences of string old1 in txt replaced with
new1; then old2 replaced with new2 . . .. Matches are found from the left. Matches
do not overlap.
[Function]count-newlines str
Returns the number of ā€˜#\newlineā€™ characters in string str.
7.2.10 Sequence Comparison
(require ā€™diff)
diff:edit-length implements the algorithm:
The values returned by diff:edit-length can be used to gauge the degree of match be-
tween two sequences.
diff:edits and diff:longest-common-subsequence combine the algorithm with the
divide-and-conquer method outlined in:
If the items being sequenced are text lines, then the computed edit-list is equivalent to the
output of the diļ¬€ utility program. If the items being sequenced are words, then it is like
the lesser known spiļ¬€ program.
[Function]diff:longest-common-subsequence array1 array2 p-lim
[Function]diff:longest-common-subsequence array1 array2
array1 and array2 are one-dimensional arrays.
The non-negative integer p-lim, if provided, is maximum number of deletions of the
shorter sequence to allow. diff:longest-common-subsequence will return #f if more
deletions would be necessary.
diff:longest-common-subsequence returns a one-dimensional array of length
(quotient (- (+ len1 len2) (diff:edit-length array1 array2)) 2) holding the
longest sequence common to both arrays.
[Function]diff:edits array1 array2 p-lim
[Function]diff:edits array1 array2
array1 and array2 are one-dimensional arrays.
Chapter 7: Other Packages 242
The non-negative integer p-lim, if provided, is maximum number of deletions of the
shorter sequence to allow. diff:edits will return #f if more deletions would be
necessary.
diff:edits returns a vector of length (diff:edit-length array1 array2) com-
posed of a shortest sequence of edits transformaing array1 to array2.
Each edit is an integer:
k > 0 Inserts (array-ref array1 (+ -1 j)) into the sequence.
k < 0 Deletes (array-ref array2 (- -1 k)) from the sequence.
[Function]diff:edit-length array1 array2 p-lim
[Function]diff:edit-length array1 array2
array1 and array2 are one-dimensional arrays.
The non-negative integer p-lim, if provided, is maximum number of deletions of the
shorter sequence to allow. diff:edit-length will return #f if more deletions would
be necessary.
diff:edit-length returns the length of the shortest sequence of edits transformaing
array1 to array2.
(diff:longest-common-subsequence "fghiejcklm" "fgehijkpqrlm")
ā‡’
"fghijklm"
(diff:edit-length "fghiejcklm" "fgehijkpqrlm")
ā‡’
6
(diff:edits "fghiejcklm" "fgehijkpqrlm")
ā‡’
#A:fixZ32b(3 -5 -7 8 9 10)
; e c h p q r
7.3 Procedures
Anything that doesnā€™t fall neatly into any of the other categories winds up here.
7.3.1 Type Coercion
(require ā€™coerce)
[Function]type-of obj
Returns a symbol name for the type of obj.
[Function]coerce obj result-type
Converts and returns obj of type char, number, string, symbol, list, or vector to
result-type (which must be one of these symbols).
7.3.2 String-Case
(require ā€™string-case)
[Procedure]string-upcase str
[Procedure]string-downcase str
Chapter 7: Other Packages 243
[Procedure]string-capitalize str
The obvious string conversion routines. These are non-destructive.
[Function]string-upcase! str
[Function]string-downcase! str
[Function]string-capitalize! str
The destructive versions of the functions above.
[Function]string-ci->symbol str
Converts string str to a symbol having the same case as if the symbol had been read.
[Function]symbol-append obj1 . . .
Converts obj1 . . . to strings, appends them, and converts to a symbol which is
returned. Strings and numbers are converted to readā€™s symbol case; the case of
symbol characters is not changed. #f is converted to the empty string (symbol).
[Function]StudlyCapsExpand str delimiter
[Function]StudlyCapsExpand str
delimiter must be a string or character. If absent, delimiter defaults to ā€˜-ā€™.
StudlyCapsExpand returns a copy of str where delimiter is inserted between each
lower-case character immediately followed by an upper-case character; and between
two upper-case characters immediately followed by a lower-case character.
(StudlyCapsExpand "aX" " ")
ā‡’
"a X"
(StudlyCapsExpand "aX" "..")
ā‡’
"a..X"
(StudlyCapsExpand "AX")
ā‡’
"AX"
(StudlyCapsExpand "Ax")
ā‡’
"Ax"
(StudlyCapsExpand "AXLE")
ā‡’
"AXLE"
(StudlyCapsExpand "aAXACz")
ā‡’
"a-AXA-Cz"
(StudlyCapsExpand "AaXACz")
ā‡’
"Aa-XA-Cz"
(StudlyCapsExpand "AAaXACz")
ā‡’
"A-Aa-XA-Cz"
(StudlyCapsExpand "AAaXAC")
ā‡’
"A-Aa-XAC"
7.3.3 String Ports
(require ā€™string-port)
[Procedure]call-with-output-string proc
proc must be a procedure of one argument. This procedure calls proc with one
argument: a (newly created) output port. When the function returns, the string
composed of the characters written into the port is returned.
[Procedure]call-with-input-string string proc
proc must be a procedure of one argument. This procedure calls proc with one
argument: an (newly created) input port from which stringā€™s contents may be read.
When proc returns, the port is closed and the value yielded by the procedure proc is
returned.
7.3.4 Line I/O
(require ā€™line-i/o)
Chapter 7: Other Packages 244
[Function]read-line
[Function]read-line port
Returns a string of the characters up to, but not including a newline or end of ļ¬le,
updating port to point to the character following the newline. If no characters are
available, an end of ļ¬le object is returned. The port argument may be omitted, in
which case it defaults to the value returned by current-input-port.
[Procedure]read-line! string
[Procedure]read-line! string port
Fills string with characters up to, but not including a newline or end of ļ¬le, updating
the port to point to the last character read or following the newline if it was read. If
no characters are available, an end of ļ¬le object is returned. If a newline or end of
ļ¬le was found, the number of characters read is returned. Otherwise, #f is returned.
The port argument may be omitted, in which case it defaults to the value returned
by current-input-port.
[Function]write-line string
[Function]write-line string port
Writes string followed by a newline to the given port and returns an unspeciļ¬ed value.
The Port argument may be omitted, in which case it defaults to the value returned
by current-input-port.
[Function]system->line command tmp
[Function]system->line command
command must be a string. The string tmp, if supplied, is a path to use as a temporary
ļ¬le. system->line calls system with command as argument, redirecting stdout to
ļ¬le tmp. system->line returns a string containing the ļ¬rst line of output from tmp.
system->line is intended to be a portable method for getting one-line results from
programs like pwd, whoami, hostname, which, identify, and cksum. Its behavior
when called with programs which generate lots of output is unspeciļ¬ed.
7.3.5 Multi-Processing
(require ā€™process)
This module implements asynchronous (non-polled) time-sliced multi-processing in the
SCM Scheme implementation using procedures alarm and alarm-interrupt. Until this is
ported to another implementation, consider it an example of writing schedulers in Scheme.
[Procedure]add-process! proc
Adds proc, which must be a procedure (or continuation) capable of accepting accept-
ing one argument, to the process:queue. The value returned is unspeciļ¬ed. The
argument to proc should be ignored. If proc returns, the process is killed.
[Procedure]process:schedule!
Saves the current process on process:queue and runs the next process from
process:queue. The value returned is unspeciļ¬ed.
Chapter 7: Other Packages 245
[Procedure]kill-process!
Kills the current process and runs the next process from process:queue. If there
are no more processes on process:queue, (slib:exit) is called (see Section 2.4
[System], page 15).
7.3.6 Metric Units
(require ā€™metric-units)
http://people.csail.mit.edu/jaffer/MIXF
Metric Interchange Format is a character string encoding for numerical values and units
which:
ā€¢ is unambiguous in all locales;
ā€¢ uses only [TOG] "Portable Character Set" characters matching "Basic Latin" charac-
ters in Plane 0 of the Universal Character Set [UCS];
ā€¢ is transparent to [UTF-7] and [UTF-8] UCS transformation formats;
ā€¢ is human readable and writable;
ā€¢ is machine readable and writable;
ā€¢ incorporates SI preļ¬xes and units;
ā€¢ incorporates [ISO 6093] numbers; and
ā€¢ incorporates [IEC 60027-2] binary preļ¬xes.
In the expression for the value of a quantity, the unit symbol is placed after the nu-
merical value. A dot (PERIOD, ā€˜.ā€™) is placed between the numerical value and the unit
symbol.
Within a compound unit, each of the base and derived symbols can optionally have an
attached SI preļ¬x.
Unit symbols formed from other unit symbols by multiplication are indicated by means
of a dot (PERIOD, ā€˜.ā€™) placed between them.
Unit symbols formed from other unit symbols by division are indicated by means of a
SOLIDUS (ā€˜/ā€™) or negative exponents. The SOLIDUS must not be repeated in the same
compound unit unless contained within a parenthesized subexpression.
The grouping formed by a preļ¬x symbol attached to a unit symbol constitutes a new
inseparable symbol (forming a multiple or submultiple of the unit concerned) which can be
raised to a positive or negative power and which can be combined with other unit symbols
to form compound unit symbols.
The grouping formed by surrounding compound unit symbols with parentheses (ā€˜(ā€™
and ā€˜)ā€™) constitutes a new inseparable symbol which can be raised to a positive or negative
power and which can be combined with other unit symbols to form compound unit symbols.
Compound preļ¬x symbols, that is, preļ¬x symbols formed by the juxtaposition of two
or more preļ¬x symbols, are not permitted.
Preļ¬x symbols are not used with the time-related unit symbols min (minute), h (hour),
d (day). No preļ¬x symbol may be used with dB (decibel). Only submultiple preļ¬x symbols
may be used with the unit symbols L (liter), Np (neper), o (degree), oC (degree Celsius),
Chapter 7: Other Packages 246
rad (radian), and sr (steradian). Submultiple preļ¬x symbols may not be used with the unit
symbols t (metric ton), r (revolution), or Bd (baud).
A unit exponent follows the unit, separated by a CIRCUMFLEX (ā€˜^ā€™). Exponents may
be positive or negative. Fractional exponents must be parenthesized.
7.3.6.1 SI Preļ¬xes
Factor Name Symbol | Factor Name Symbol
====== ==== ====== | ====== ==== ======
1e24 yotta Y | 1e-1 deci d
1e21 zetta Z | 1e-2 centi c
1e18 exa E | 1e-3 milli m
1e15 peta P | 1e-6 micro u
1e12 tera T | 1e-9 nano n
1e9 giga G | 1e-12 pico p
1e6 mega M | 1e-15 femto f
1e3 kilo k | 1e-18 atto a
1e2 hecto h | 1e-21 zepto z
1e1 deka da | 1e-24 yocto y
7.3.6.2 Binary Preļ¬xes
These binary preļ¬xes are valid only with the units B (byte) and bit. However, decimal
preļ¬xes can also be used with bit; and decimal multiple (not submultiple) preļ¬xes can also
be used with B (byte).
Factor (power-of-2) Name Symbol
====== ============ ==== ======
1.152921504606846976e18 (2^60) exbi Ei
1.125899906842624e15 (2^50) pebi Pi
1.099511627776e12 (2^40) tebi Ti
1.073741824e9 (2^30) gibi Gi
1.048576e6 (2^20) mebi Mi
1.024e3 (2^10) kibi Ki
7.3.6.3 Unit Symbols
Type of Quantity Name Symbol Equivalent
================ ==== ====== ==========
time second s
time minute min = 60.s
time hour h = 60.min
time day d = 24.h
frequency hertz Hz s^-1
signaling rate baud Bd s^-1
length meter m
volume liter L dm^3
plane angle radian rad
solid angle steradian sr rad^2
plane angle revolution * r = 6.283185307179586.rad
Chapter 7: Other Packages 247
plane angle degree * o = 2.777777777777778e-3.r
information capacity bit bit
information capacity byte, octet B = 8.bit
mass gram g
mass ton t Mg
mass unified atomic mass unit u = 1.66053873e-27.kg
amount of substance mole mol
catalytic activity katal kat mol/s
thermodynamic temperature kelvin K
centigrade temperature degree Celsius oC
luminous intensity candela cd
luminous flux lumen lm cd.sr
illuminance lux lx lm/m^2
force newton N m.kg.s^-2
pressure, stress pascal Pa N/m^2
energy, work, heat joule J N.m
energy electronvolt eV = 1.602176462e-19.J
power, radiant flux watt W J/s
logarithm of power ratio neper Np
logarithm of power ratio decibel * dB = 0.1151293.Np
electric current ampere A
electric charge coulomb C s.A
electric potential, EMF volt V W/A
capacitance farad F C/V
electric resistance ohm Ohm V/A
electric conductance siemens S A/V
magnetic flux weber Wb V.s
magnetic flux density tesla T Wb/m^2
inductance henry H Wb/A
radionuclide activity becquerel Bq s^-1
absorbed dose energy gray Gy m^2.s^-2
dose equivalent sievert Sv m^2.s^-2
* The formulas are:
ā€¢ r/rad = 8 * atan(1)
ā€¢ o/r = 1 / 360
ā€¢ db/Np = ln(10) / 20
[Function]si:conversion-factor to-unit from-unit
If the strings from-unit and to-unit express valid unit expressions for quantities of
the same unit-dimensions, then the value returned by si:conversion-factor will
be such that multiplying a numerical value expressed in from-units by the returned
conversion factor yields the numerical value expressed in to-units.
Otherwise, si:conversion-factor returns:
-3 if neither from-unit nor to-unit is a syntactically valid unit.
-2 if from-unit is not a syntactically valid unit.
Chapter 7: Other Packages 248
-1 if to-unit is not a syntactically valid unit.
0 if linear conversion (by a factor) is not possible.
(si:conversion-factor "km/s" "m/s" )
ā‡’
0.001
(si:conversion-factor "N" "m/s" )
ā‡’
0
(si:conversion-factor "moC" "oC" )
ā‡’
1000
(si:conversion-factor "mK" "oC" )
ā‡’
0
(si:conversion-factor "rad" "o" )
ā‡’
0.0174533
(si:conversion-factor "K" "o" )
ā‡’
0
(si:conversion-factor "K" "K" )
ā‡’
1
(si:conversion-factor "oK" "oK" )
ā‡’
-3
(si:conversion-factor "" "s/s" )
ā‡’
1
(si:conversion-factor "km/h" "mph" )
ā‡’
-2
7.4 Standards Support
7.4.1 RnRS
The r2rs, r3rs, r4rs, and r5rs features attempt to provide procedures and macros to
bring a Scheme implementation to the desired version of Scheme.
[Feature]r2rs
Requires features implementing procedures and optional procedures speciļ¬ed by Re-
vised^2 Report on the Algorithmic Language Scheme; namely rev3-procedures and
rev2-procedures.
[Feature]r3rs
Requires features implementing procedures and optional procedures speciļ¬ed by Re-
vised^3 Report on the Algorithmic Language Scheme; namely rev3-procedures.
Note: SLIB already mandates the r3rs procedures which can be portably imple-
mented in r4rs implementations.
[Feature]r4rs
Requires features implementing procedures and optional procedures spec-
iļ¬ed by Revised^4 Report on the Algorithmic Language Scheme; namely
rev4-optional-procedures.
[Feature]r5rs
Requires features implementing procedures and optional procedures speciļ¬ed by Re-
vised^5 Report on the Algorithmic Language Scheme; namely values, macro, and
eval.
7.4.2 With-File
(require ā€™with-file)
[Function]with-input-from-file ļ¬le thunk
[Function]with-output-to-file ļ¬le thunk
Description found in R4RS.
Chapter 7: Other Packages 249
7.4.3 Transcripts
(require ā€™transcript)
[Function]transcript-on ļ¬lename
[Function]transcript-off ļ¬lename
Redeļ¬nes read-char, read, write-char, write, display, and newline.
7.4.4 Rev2 Procedures
(require ā€™rev2-procedures)
The procedures below were speciļ¬ed in the Revised^2 Report on Scheme. N.B.: The
symbols 1+ and -1+ are not R4RS syntax. Scheme->C, for instance, chokes on this module.
[Procedure]substring-move-left! string1 start1 end1 string2 start2
[Procedure]substring-move-right! string1 start1 end1 string2 start2
string1 and string2 must be a strings, and start1, start2 and end1 must be exact
integers satisfying
0 <= start1 <= end1 <= (string-length string1)
0 <= start2 <= end1 - start1 + start2 <= (string-length string2)
substring-move-left! and substring-move-right! store characters of string1 be-
ginning with index start1 (inclusive) and ending with index end1 (exclusive) into
string2 beginning with index start2 (inclusive).
substring-move-left! stores characters in time order of increasing indices.
substring-move-right! stores characters in time order of increasing indeces.
[Procedure]substring-fill! string start end char
Fills the elements startā€“end of string with the character char.
[Function]string-null? str
ā‰” (= 0 (string-length str))
[Procedure]append! pair1 . . .
Destructively appends its arguments. Equivalent to nconc.
[Function]1+ n
Adds 1 to n.
[Function]-1+ n
Subtracts 1 from n.
[Function]<?
[Function]<=?
[Function]=?
[Function]>?
[Function]>=?
These are equivalent to the procedures of the same name but without the trailing ā€˜?ā€™.
Chapter 7: Other Packages 250
7.4.5 Rev4 Optional Procedures
(require ā€™rev4-optional-procedures)
For the speciļ¬cation of these optional procedures, See Section ā€œStandard proceduresā€
in Revised(4) Scheme.
[Function]list-tail l p
[Function]string-copy
[Procedure]string-fill! s obj
[Procedure]vector-fill! s obj
7.4.6 Multi-argument / and -
(require ā€™multiarg/and-)
For the speciļ¬cation of these optional forms, See Section ā€œNumerical operationsā€ in
Revised(4) Scheme.
[Function]/ dividend divisor1 . . .
[Function]- minuend subtrahend1 . . .
7.4.7 Multi-argument Apply
(require ā€™multiarg-apply)
For the speciļ¬cation of this optional form, See Section ā€œControl featuresā€ in Revised(4)
Scheme.
[Function]apply proc arg1 . . .
7.4.8 Rationalize
(require ā€™rationalize)
[Function]rationalize x e
Computes the correct result for exact arguments (provided the implementation sup-
ports exact rational numbers of unlimited precision); and produces a reasonable an-
swer for inexact arguments when inexact arithmetic is implemented using ļ¬‚oating-
point.
Rationalize has limited use in implementations lacking exact (non-integer) rational
numbers. The following procedures return a list of the numerator and denominator.
[Function]find-ratio x e
find-ratio returns the list of the simplest numerator and denominator whose quo-
tient diļ¬€ers from x by no more than e.
(find-ratio 3/97 .0001)
ā‡’
(3 97)
(find-ratio 3/97 .001)
ā‡’
(1 32)
Chapter 7: Other Packages 251
[Function]find-ratio-between x y
find-ratio-between returns the list of the simplest numerator and denominator
between x and y.
(find-ratio-between 2/7 3/5)
ā‡’
(1 2)
(find-ratio-between -3/5 -2/7)
ā‡’
(-1 2)
7.4.9 Promises
(require ā€™promise)
[Function]make-promise proc
[Function]force promise
(require ā€™delay) provides force and delay:
[Macro]delay obj
Change occurrences of (delay expression) to
(make-promise (lambda () expression))
(see
Section ā€œControl featuresā€ in Revised(4) Scheme).
7.4.10 Dynamic-Wind
(require ā€™dynamic-wind)
This facility is a generalization of Common LISP unwind-protect, designed to take
into account the fact that continuations produced by call-with-current-continuation
may be reentered.
[Procedure]dynamic-wind thunk1 thunk2 thunk3
The arguments thunk1, thunk2, and thunk3 must all be procedures of no arguments
(thunks).
dynamic-wind calls thunk1, thunk2, and then thunk3. The value returned by thunk2
is returned as the result of dynamic-wind. thunk3 is also called just before control
leaves the dynamic context of thunk2 by calling a continuation created outside that
context. Furthermore, thunk1 is called before reentering the dynamic context of
thunk2 by calling a continuation created inside that context. (Control is inside the
context of thunk2 if thunk2 is on the current return stack).
Warning: There is no provision for dealing with errors or interrupts. If an error or
interrupt occurs while using dynamic-wind, the dynamic environment will be that in
eļ¬€ect at the time of the error or interrupt.
7.4.11 Eval
(require ā€™eval)
[Function]eval expression environment-speciļ¬er
Evaluates expression in the speciļ¬ed environment and returns its value. Expression
must be a valid Scheme expression represented as data, and environment-speciļ¬er
Chapter 7: Other Packages 252
must be a value returned by one of the three procedures described below. Im-
plementations may extend eval to allow non-expression programs (deļ¬nitions) as
the ļ¬rst argument and to allow other values as environments, with the restriction
that eval is not allowed to create new bindings in the environments associated with
null-environment or scheme-report-environment.
(eval ā€™(* 7 3) (scheme-report-environment 5))
ā‡’
21
(let ((f (eval ā€™(lambda (f x) (f x x))
(null-environment))))
(f + 10))
ā‡’
20
[Function]scheme-report-environment version
[Function]null-environment version
[Function]null-environment
Version must be an exact non-negative integer n corresponding to a version of one of
the Revised^n Reports on Scheme. Scheme-report-environment returns a speciļ¬er
for an environment that contains the set of bindings speciļ¬ed in the corresponding re-
port that the implementation supports. Null-environment returns a speciļ¬er for an
environment that contains only the (syntactic) bindings for all the syntactic keywords
deļ¬ned in the given version of the report.
Not all versions may be available in all implementations at all times. However, an
implementation that conforms to version n of the Revised^n Reports on Scheme must
accept version n. An error is signalled if the speciļ¬ed version is not available.
The eļ¬€ect of assigning (through the use of eval) a variable bound in a
scheme-report-environment (for example car) is unspeciļ¬ed. Thus the
environments speciļ¬ed by scheme-report-environment may be immutable.
[Function]interaction-environment
This optional procedure returns a speciļ¬er for the environment that contains
implementation-deļ¬ned bindings, typically a superset of those listed in the report.
The intent is that this procedure will return the environment in which the
implementation would evaluate expressions dynamically typed by the user.
Here are some more eval examples:
(require ā€™eval)
ā‡’
#<unspecified>
(define car ā€™volvo)
ā‡’
#<unspecified>
car
ā‡’
volvo
(eval ā€™car (interaction-environment))
ā‡’
volvo
(eval ā€™car (scheme-report-environment 5))
ā‡’
#<primitive-procedure car>
Chapter 7: Other Packages 253
(eval ā€™(eval ā€™car (interaction-environment))
(scheme-report-environment 5))
ā‡’
volvo
(eval ā€™(eval ā€™(set! car ā€™buick) (interaction-environment))
(scheme-report-environment 5))
ā‡’
#<unspecified>
car
ā‡’
buick
(eval ā€™car (scheme-report-environment 5))
ā‡’
#<primitive-procedure car>
(eval ā€™(eval ā€™car (interaction-environment))
(scheme-report-environment 5))
ā‡’
buick
7.4.12 Values
(require ā€™values)
[Function]values obj . . .
values takes any number of arguments, and passes (returns) them to its continuation.
[Function]call-with-values thunk proc
thunk must be a procedure of no arguments, and proc must be a procedure.
call-with-values calls thunk with a continuation that, when passed some values,
calls proc with those values as arguments.
Except for continuations created by the call-with-values procedure, all continua-
tions take exactly one value, as now; the eļ¬€ect of passing no value or more than one
value to continuations that were not created by the call-with-values procedure is
unspeciļ¬ed.
7.4.13 SRFI
(require ā€™srfi)
Implements Scheme Request For Implementation (SRFI) as described at http://srfi.
schemers.org/
[Macro]cond-expand <clause1> <clause2> . . .
Syntax: Each <clause> should be of the form
(<feature> <expression1> ...)
where <feature> is a boolean expression composed of symbols and ā€˜andā€™, ā€˜orā€™, and
ā€˜notā€™ of boolean expressions. The last <clause> may be an ā€œelse clause,ā€ which has
the form
(else <expression1> <expression2> ...).
The ļ¬rst clause whose feature expression is satisļ¬ed is expanded. If no feature ex-
pression is satisļ¬ed and there is no else clause, an error is signaled.
SLIB cond-expand is an extension of SRFI-0, http://srfi.schemers.org/srfi-0/
srfi-0.html.
Chapter 7: Other Packages 254
ā€¢ SRFI-2 Section 3.12 [Guarded LET* special form], page 34,
ā€¢ SRFI-8 Section 3.11 [Binding to multiple values], page 34,
ā€¢ SRFI-9 Section 3.8 [Deļ¬ne-Record-Type], page 33,
ā€¢ SRFI-11 Section 3.11 [Binding to multiple values], page 34,
ā€¢ SRFI-23 (define error slib:error)
ā€¢ SRFI-28 Section 4.2 [Format], page 46,
ā€¢ SRFI-39 Section 3.10 [Parameter Objects], page 34,
ā€¢ SRFI-47 Section 7.1.1 [Arrays], page 196,
ā€¢ SRFI-59 Section 2.1 [Vicinity], page 11,
ā€¢ SRFI-60 Section 5.1 [Bit-Twiddling], page 103,
ā€¢ SRFI-61 Section 3.13 [Guarded COND Clause], page 34,
ā€¢ SRFI-63 Section 7.1.1 [Arrays], page 196,
ā€¢ SRFI-94 Section 5.3 [Irrational Integer Functions], page 108, and Section 5.4 [Irrational
Real Functions], page 109,
ā€¢ SRFI-95 Section 7.2.4 [Sorting], page 233,
ā€¢ SRFI-96 Chapter 2 [Universal SLIB Procedures], page 11,
7.4.13.1 SRFI-1
(require ā€™srfi-1)
Implements the SRFI-1 list-processing library as described at http://srfi.schemers.
org/srfi-1/srfi-1.html
Constructors
[Function]xcons d a
(define (xcons d a) (cons a d)).
[Function]list-tabulate len proc
Returns a list of length len. Element i is (proc i) for 0 <= i < len.
[Function]cons* obj1 obj2
[Function]list-copy ļ¬‚ist
[Function]iota count start step
[Function]iota count start
[Function]iota count
Returns a list of count numbers: (start, start+step, . . . , start+(count-1)*step).
[Function]circular-list obj1 obj2 . . .
Returns a circular list of obj1, obj2, . . ..
Predicates
[Function]proper-list? obj
[Function]circular-list? x
Chapter 7: Other Packages 255
[Function]dotted-list? obj
[Function]null-list? obj
[Function]not-pair? obj
[Function]list= =pred list . . .
Selectors
[Function]first pair
[Function]second pair
[Function]third pair
[Function]fourth pair
[Function]fifth pair
[Function]sixth pair
[Function]seventh pair
[Function]eighth pair
[Function]ninth pair
[Function]tenth pair
[Function]car+cdr pair
[Function]drop lst k
[Function]take lst k
[Function]take! lst k
[Function]take-right lst k
[Function]drop-right lst k
[Procedure]drop-right! lst k
[Function]split-at lst k
[Function]split-at! lst k
[Function]last lst k . . .
Miscellaneous
[Function]length+ clist
[Function]concatenate lists
[Function]concatenate! lists
[Procedure]reverse! lst
[Function]append-reverse rev-head tail
[Function]append-reverse! rev-head tail
[Function]zip list1 list2 . . .
[Function]unzip1 lst
[Function]unzip2 lst
[Function]unzip3 lst
[Function]unzip4 lst
[Function]unzip5 lst
[Function]count pred list1 list2 . . .
Chapter 7: Other Packages 256
Fold and Unfold
[Function]fold kons knil clist1 clist2 . . .
[Function]fold-right kons knil clist1 clist2 . . .
[Function]pair-fold kons knil clist1 clist2 . . .
[Function]pair-fold-right kons knil clist1 clist2 . . .
[Function]reduce arg . . .
[Procedure]map! f clist1 clist2 . . .
[Function]pair-for-each f clist1 clist2 . . .
Filtering and Partitioning
[Function]filter pred list
[Procedure]filter! pred list
[Function]partition pred list
[Function]remove pred list
[Procedure]partition! pred list
[Procedure]remove! pred list
Searching
[Function]find pred clist
[Function]find-tail pred clist
[Function]span pred list
[Procedure]span! pred list
[Function]break pred list
[Procedure]break! pred list
[Function]any pred clist1 clist2 . . .
[Function]list-index pred clist1 clist2 . . .
[Function]member obj list =
[Function]member obj list
Deleting
[Function]delete-duplicates x list =
[Function]delete-duplicates x list
[Procedure]delete-duplicates! x list =
[Procedure]delete-duplicates! x list
Chapter 7: Other Packages 257
Association lists
[Function]assoc obj alist pred
[Function]assoc obj alist
[Function]alist-cons key datum alist
[Function]alist-copy alist
[Function]alist-delete key alist =
[Function]alist-delete key alist
[Procedure]alist-delete! key alist =
[Procedure]alist-delete! key alist
Set operations
[Function]lset<= = list1 . . .
Determine if a transitive subset relation exists between the lists list1 . . ., using = to
determine equality of list members.
[Function]lset= = list1 list2 . . .
[Function]lset-adjoin list elt1 . . .
[Function]lset-union = list1 . . .
[Function]lset-intersection = list1 list2 . . .
[Function]lset-difference = list1 list2 . . .
[Function]lset-xor = list1 . . .
[Function]lset-diff+intersection = list1 list2 . . .
These are linear-update variants. They are allowed, but not required, to use the cons cells
in their ļ¬rst list parameter to construct their answer. lset-union! is permitted to recycle
cons cells from any of its list arguments.
[Procedure]lset-intersection! = list1 list2 . . .
[Procedure]lset-difference! = list1 list2 . . .
[Procedure]lset-union! = list1 . . .
[Procedure]lset-xor! = list1 . . .
[Procedure]lset-diff+intersection! = list1 list2 . . .
7.5 Session Support
If (provided? ā€™abort):
[Function]abort
Resumes the top level Read-Eval-Print loop. If provided, abort is used by the break
and debug packages.
Chapter 7: Other Packages 258
7.5.1 Repl
(require ā€™repl)
Here is a read-eval-print-loop which, given an eval, evaluates forms.
[Procedure]repl:top-level repl:eval
reads, repl:evals and writes expressions from (current-input-port) to
(current-output-port) until an end-of-ļ¬le is encountered. load, slib:eval,
slib:error, and repl:quit dynamically bound during repl:top-level.
[Procedure]repl:quit
Exits from the invocation of repl:top-level.
The repl: procedures establish, as much as is possible to do portably, a top level envi-
ronment supporting macros. repl:top-level uses dynamic-wind to catch error conditions
and interrupts. If your implementation supports this you are all set.
Otherwise, if there is some way your implementation can catch error conditions and
interrupts, then have them call slib:error. It will display its arguments and reenter
repl:top-level. slib:error dynamically bound by repl:top-level.
To have your top level loop always use macros, add any interrupt catching lines and
the following lines to your Scheme init ļ¬le:
(require ā€™macro)
(require ā€™repl)
(repl:top-level macro:eval)
7.5.2 Quick Print
(require ā€™qp)
When displaying error messages and warnings, it is paramount that the output generated
for circular lists and large data structures be limited. This section supplies a procedure to
do this. It could be much improved.
Notice that the neccessity for truncating output eliminates Common-Lispā€™s
Section 4.2 [Format], page 46, from consideration; even when variables
*print-level* and *print-level* are set, huge strings and bit-vectors are
not limited.
[Procedure]qp arg1 . . .
[Procedure]qpn arg1 . . .
[Procedure]qpr arg1 . . .
qp writes its arguments, separated by spaces, to (current-output-port). qp com-
presses printing by substituting ā€˜...ā€™ for substructure it does not have suļ¬ƒcient room
to print. qpn is like qp but outputs a newline before returning. qpr is like qpn except
that it returns its last argument.
[Variable]*qp-width*
*qp-width* is the largest number of characters that qp should use. If *qp-width* is
#f, then all items will be writen. If *qp-width* is 0, then all items except procedures
will be writen; procedures will be indicated by ā€˜#[proc]ā€™.
Chapter 7: Other Packages 259
7.5.3 Debug
(require ā€™debug)
Requiring debug automatically requires trace and break.
An application with its own datatypes may want to substitute its own printer for qp. This
example shows how to do this:
(define qpn (lambda args) ...)
(provide ā€™qp)
(require ā€™debug)
[Procedure]trace-all ļ¬le . . .
Traces (see Section 7.5.5 [Trace], page 260) all procedures defined at top-level in
file . . . .
[Procedure]track-all ļ¬le . . .
Tracks (see Section 7.5.5 [Trace], page 260) all procedures defined at top-level in
file . . . .
[Procedure]stack-all ļ¬le . . .
Stacks (see Section 7.5.5 [Trace], page 260) all procedures defined at top-level in
file . . . .
[Procedure]break-all ļ¬le . . .
Breakpoints (see Section 7.5.4 [Breakpoints], page 259) all procedures defined at
top-level in file . . . .
7.5.4 Breakpoints
(require ā€™break)
[Function]init-debug
If your Scheme implementation does not support break or abort, a message will
appear when you (require ā€™break) or (require ā€™debug) telling you to type
(init-debug). This is in order to establish a top-level continuation. Typing
(init-debug) at top level sets up a continuation for break.
[Function]breakpoint arg1 . . .
Returns from the top level continuation and pushes the continuation from which it
was called on a continuation stack.
[Function]continue
Pops the topmost continuation oļ¬€ of the continuation stack and returns an unspeciļ¬ed
value to it.
[Function]continue arg1 . . .
Pops the topmost continuation oļ¬€ of the continuation stack and returns arg1 . . . to
it.
[Macro]break proc1 . . .
Redeļ¬nes the top-level named procedures given as arguments so that breakpoint is
called before calling proc1 . . ..
Chapter 7: Other Packages 260
[Macro]break
With no arguments, makes sure that all the currently broken identiļ¬ers are broken
(even if those identiļ¬ers have been redeļ¬ned) and returns a list of the broken identi-
ļ¬ers.
[Macro]unbreak proc1 . . .
Turns breakpoints oļ¬€ for its arguments.
[Macro]unbreak
With no arguments, unbreaks all currently broken identiļ¬ers and returns a list of
these formerly broken identiļ¬ers.
These are procedures for breaking. If defmacros are not natively supported by your
implementation, these might be more convenient to use.
[Function]breakf proc
[Function]breakf proc name
To break, type
(set! symbol (breakf symbol))
or
(set! symbol (breakf symbol ā€™symbol))
or
(define symbol (breakf function))
or
(define symbol (breakf function ā€™symbol))
[Function]unbreakf proc
To unbreak, type
(set! symbol (unbreakf symbol))
7.5.5 Tracing
(require ā€™trace)
This feature provides three ways to monitor procedure invocations:
stack Pushes the procedure-name when the procedure is called; pops when it returns.
track Pushes the procedure-name and arguments when the procedure is called; pops
when it returns.
trace Pushes the procedure-name and prints ā€˜CALL procedure-name arg1 ...ā€™ when
the procdure is called; pops and prints ā€˜RETN procedure-name valueā€™ when the
procedure returns.
[Variable]debug:max-count
If a traced procedure calls itself or untraced procedures which call it, stack, track,
and trace will limit the number of stack pushes to debug:max-count.
Chapter 7: Other Packages 261
[Function]print-call-stack
[Function]print-call-stack port
Prints the call-stack to port or the current-error-port.
[Macro]trace proc1 . . .
Traces the top-level named procedures given as arguments.
[Macro]trace
With no arguments, makes sure that all the currently traced identiļ¬ers are traced
(even if those identiļ¬ers have been redeļ¬ned) and returns a list of the traced identiļ¬ers.
[Macro]track proc1 . . .
Traces the top-level named procedures given as arguments.
[Macro]track
With no arguments, makes sure that all the currently tracked identiļ¬ers are tracked
(even if those identiļ¬ers have been redeļ¬ned) and returns a list of the tracked iden-
tiļ¬ers.
[Macro]stack proc1 . . .
Traces the top-level named procedures given as arguments.
[Macro]stack
With no arguments, makes sure that all the currently stacked identiļ¬ers are stacked
(even if those identiļ¬ers have been redeļ¬ned) and returns a list of the stacked iden-
tiļ¬ers.
[Macro]untrace proc1 . . .
Turns tracing, tracking, and oļ¬€ for its arguments.
[Macro]untrace
With no arguments, untraces all currently traced identiļ¬ers and returns a list of these
formerly traced identiļ¬ers.
[Macro]untrack proc1 . . .
Turns tracing, tracking, and oļ¬€ for its arguments.
[Macro]untrack
With no arguments, untracks all currently tracked identiļ¬ers and returns a list of
these formerly tracked identiļ¬ers.
[Macro]unstack proc1 . . .
Turns tracing, stacking, and oļ¬€ for its arguments.
[Macro]unstack
With no arguments, unstacks all currently stacked identiļ¬ers and returns a list of
these formerly stacked identiļ¬ers.
These are procedures for tracing. If defmacros are not natively supported by your
implementation, these might be more convenient to use.
Chapter 7: Other Packages 262
[Function]tracef proc
[Function]tracef proc name
[Function]trackf proc
[Function]trackf proc name
[Function]stackf proc
[Function]stackf proc name
To trace, type
(set! symbol (tracef symbol))
or
(set! symbol (tracef symbol ā€™symbol))
or
(define symbol (tracef function))
or
(define symbol (tracef function ā€™symbol))
[Function]untracef proc
Removes tracing, tracking, or stacking for proc. To untrace, type
(set! symbol (untracef symbol))
7.6 System Interface
If (provided? ā€™getenv):
[Function]getenv name
Looks up name, a string, in the program environment. If name is found a string of
its value is returned. Otherwise, #f is returned.
If (provided? ā€™system):
[Function]system command-string
Executes the command-string on the computer and returns the integer status code.
This behaves the same as the POSIX system call.
If (provided? ā€™program-arguments):
[Function]program-arguments
Returns a list of strings, the ļ¬rst of which is the program name followed by the
command-line arguments.
7.6.1 Directories
(require ā€™directory)
[Function]current-directory
current-directory returns a string containing the absolute ļ¬le name representing
the current working directory. If this string cannot be obtained, #f is returned.
If current-directory cannot be supported by the platform, then #f is returned.
Chapter 7: Other Packages 263
[Function]make-directory name
Creates a sub-directory name of the current-directory. If successful, make-directory
returns #t; otherwise #f.
[Function]directory-for-each proc directory
proc must be a procedure taking one argument. ā€˜Directory-For-Eachā€™ applies proc
to the (string) name of each ļ¬le in directory. The dynamic order in which proc is
applied to the ļ¬lenames is unspeciļ¬ed. The value returned by ā€˜directory-for-eachā€™
is unspeciļ¬ed.
[Function]directory-for-each proc directory pred
Applies proc only to those ļ¬lenames for which the procedure pred returns a non-false
value.
[Function]directory-for-each proc directory match
Applies proc only to those ļ¬lenames for which (filename:match?? match) would
return a non-false value (see Section ā€œFilenamesā€ in SLIB).
(require ā€™directory)
(directory-for-each print "." "[A-Z]*.scm")
a
"Bev2slib.scm"
"Template.scm"
[Function]directory*-for-each proc path-glob
path-glob is a pathname whose last component is a (wildcard) pattern (see
Section ā€œFilenamesā€ in SLIB). proc must be a procedure taking one argument.
ā€˜directory*-for-eachā€™ applies proc to the (string) name of each ļ¬le in the current
directory. The dynamic order in which proc is applied to the ļ¬lenames is unspeciļ¬ed.
The value returned by ā€˜directory*-for-eachā€™ is unspeciļ¬ed.
7.6.2 Transactions
If system is provided by the Scheme implementation, the transact package provides func-
tions for ļ¬le-locking and ļ¬le-replacement transactions.
(require ā€™transact)
File Locking
Unix ļ¬le-locking is focussed on write permissions for segments of a existing ļ¬le. While
this might be employed for (binary) database access, it is not used for everyday contention
(between users) for text ļ¬les.
Microsoft has several ļ¬le-locking protocols. Their model denies write access to a ļ¬le if any
reader has it open. This is too restrictive. Write access is denied even when the reader
has reached end-of-ļ¬le. And tracking read access (which is much more common than write
access) causes havoc when remote hosts crash or disconnect.
It is bizarre that the concept of multi-user contention for modifying ļ¬les has not been
adequately addressed by either of the large operating system development eļ¬€orts. There
is further irony that both camps support contention detection and resolution only through
weak conventions of some their document editing programs.
Chapter 7: Other Packages 264
The ļ¬le-lock procedures implement a transaction method for ļ¬le replacement compatible
with the methods used by the GNU emacs text editor on Unix systems and the Microsoft
Word editor.
Both protocols employ what I term a certiļ¬cate containing the user, hostname, time, and
(on Unix) process-id. Intent to replace ļ¬le is indicated by adding to ļ¬leā€™s directory a
certiļ¬cate object whose name is derived from ļ¬le.
The Microsoft Word certiļ¬cate is contained in a 162 byte ļ¬le named for the visited ļ¬le with
a ā€˜~$ā€™ preļ¬x. Emacs/Unix creates a symbolic link to a certiļ¬cate named for the visited ļ¬le
preļ¬xed with ā€˜.#ā€™. Because Unix systems can import Microsoft ļ¬le systems, these routines
maintain and check both Emacs and Word certiļ¬cates.
[Function]file-lock-owner path
Returns the string ā€˜user@hostnameā€™ associated with the lock owner of ļ¬le path if
locked; and #f otherwise.
[Procedure]file-lock! path email
[Procedure]file-lock! path
path must be a string naming the ļ¬le to be locked. If supplied, email must be a
string formatted as ā€˜user@hostnameā€™. If absent, email defaults to the value returned
by user-email-address.
If path is already locked, then file-lock! returns ā€˜#fā€™. If path is unlocked, then
file-lock! returns the certiļ¬cate string associated with the new lock for ļ¬le path.
[Procedure]file-unlock! path certiļ¬cate
path must be a string naming the ļ¬le to be unlocked. certiļ¬cate must be the string
returned by file-lock! for path.
If path is locked with certiļ¬cate, then file-unlock! removes the locks and returns
ā€˜#tā€™. Otherwise, file-unlock! leaves the ļ¬le system unaltered and returns ā€˜#fā€™.
[Function]describe-file-lock path preļ¬x
[Function]describe-file-lock path
path must be a string naming a ļ¬le. Optional argument preļ¬x is a string printed
before each line of the message. describe-file-lock prints to (current-error-
port) that path is locked for writing and lists its lock-ļ¬les.
(describe-file-lock "my.txt" ">> ")
a
>> "my.txt" is locked for writing by ā€™[email protected]:1200536423ā€™
>> (lock files are "~$my.txt" and ".#my.txt")
File Transactions
[Function]emacs:backup-name path backup-style
path must be a string. backup-style must be a symbol. Depending on backup-style,
emacs:backup-name returns:
none #f
simple the string "path~"
Chapter 7: Other Packages 265
numbered the string "path.~n~", where n is one greater than the highest number
appearing in a ļ¬lename matching "path.~*~". n defauls to 1 when no
ļ¬lename matches.
existing the string "path.~n~" if a numbered backup already exists in this direc-
tory; otherwise. "path~"
orig the string "path.orig"
bak the string "path.bak"
[Function]transact-file-replacement proc path backup-style certiļ¬cate
[Function]transact-file-replacement proc path backup-style
[Function]transact-file-replacement proc path
path must be a string naming an existing ļ¬le. backup-style is one of the symbols
none, simple, numbered, existing, orig, bak or #f; with meanings described above; or
a string naming the location of a backup ļ¬le. backup-style defaults to #f. If supplied,
certiļ¬cate is the certiļ¬cate with which path is locked.
proc must be a procedure taking two string arguments:
ā€¢ path, the original ļ¬lename (to be read); and
ā€¢ a temporary ļ¬le-name.
If path is locked by other than certiļ¬cate, or if certiļ¬cate is supplied and path is
not locked, then transact-file-replacement returns #f. If certiļ¬cate is not sup-
plied, then, transact-file-replacement creates temporary (Emacs and Word) locks
for path during the transaction. The lock status of path will be restored before
transact-file-replacement returns.
transact-file-replacement calls proc with path (which should not be modiļ¬ed)
and a temporary ļ¬le path to be written. If proc returns any value other than #t, then
the ļ¬le named by path is not altered and transact-file-replacement returns #f.
Otherwise, emacs:backup-name is called with path and backup-style. If it returns a
string, then path is renamed to it.
Finally, the temporary ļ¬le is renamed path. transact-file-replacement returns
#t if path was successfully replaced; and #f otherwise.
Identiļ¬cation
[Function]user-email-address
user-email-address returns a string of the form ā€˜username@hostnameā€™. If this e-
mail address cannot be obtained, #f is returned.
7.6.3 CVS
(require ā€™cvs)
[Function]cvs-files directory/
Returns a list of the local pathnames (with preļ¬x directory/) of all CVS controlled
ļ¬les in directory/ and in directory/ā€™s subdirectories.
Chapter 7: Other Packages 266
[Function]cvs-directories directory/
Returns a list of all of directory/ and all directory/ā€™s CVS controlled subdirectories.
[Function]cvs-root path/
Returns the (string) contents of path/CVS/Root; or (getenv "CVSROOT") if Root
doesnā€™t exist.
[Function]cvs-repository directory/
Returns the (string) contents of directory/CVS/Root appended with direc-
tory/CVS/Repository; or #f if directory/CVS/Repository doesnā€™t exist.
[Procedure]cvs-set-root! new-root directory/
Writes new-root to ļ¬le CVS/Root of directory/.
[Procedure]cvs-set-roots! new-root directory/
Writes new-root to ļ¬le CVS/Root of directory/ and all its CVS subdirectories.
[Function]cvs-vet directory/
Signals an error if CVS/Repository or CVS/Root ļ¬les in directory/ or any subdirec-
tory do not match.
7.7 Extra-SLIB Packages
Several Scheme packages have been written using SLIB. There are several reasons why a
package might not be included in the SLIB distribution:
ā€¢ Because it requires special hardware or software which is not universal.
ā€¢ Because it is large and of limited interest to most Scheme users.
ā€¢ Because it has copying terms diļ¬€erent enough from the other SLIB packages that its
inclusion would cause confusion.
ā€¢ Because it is an application program, rather than a library module.
ā€¢ Because I have been too busy to integrate it.
Once an optional package is installed (and an entry added to *catalog*), the require
mechanism allows it to be called up and used as easily as any other SLIB package. Some
optional packages (for which *catalog* already has entries) available from SLIB sites are:
SLIB-PSD is a portable debugger for Scheme (requires emacs editor).
http://groups.csail.mit.edu/mac/ftpdir/scm/slib-psd1-3.tar.gz
ftp://ftp.cs.indiana.edu/pub/scheme-repository/utl/slib-psd1-3.
tar.gz
With PSD, you can run a Scheme program in an Emacs buļ¬€er, set breakpoints,
single step evaluation and access and modify the programā€™s variables. It works
by instrumenting the original source code, so it should run with any R4RS
compliant Scheme. It has been tested with SCM, Elk 1.5, and the sci interpreter
in the Scheme->C system, but should work with other Schemes with a minimal
amount of porting, if at all. Includes documentation and userā€™s manual. Written
by Pertti KellomĀØaki, the Lisp Pointers article describing PSD (Lisp Pointers
Chapter 7: Other Packages 267
VI(1):15-23, January-March 1993) is available at
http://www.cs.tut.fi/staff/pk/scheme/psd/article/article.html
SCHELOG
is an embedding of Prolog in Scheme.
http://www.ccs.neu.edu/~dorai/schelog/schelog.html
JFILTER is a Scheme program which converts text among the JIS, EUC, and Shift-JIS
Japanese character sets.
http://www.math.u-toyama.ac.jp/~iwao/Scheme/Jfilter
268
8 About SLIB
More people than I can name have contributed to SLIB. Thanks to all of you!
SLIB 3b6, released February 2020.
Aubrey Jaļ¬€er <ag[email protected]>
Current information about SLIB can be found on SLIBā€™s WWW home page:
http://people.csail.mit.edu/jaffer/SLIB
SLIB is part of the GNU project.
8.1 Installation
There are ļ¬ve parts to installation:
ā€¢ Unpack the SLIB distribution.
ā€¢ Install documentation and slib script.
ā€¢ Conļ¬gure the Scheme implementation(s) to locate the SLIB directory and implemen-
tation directories.
ā€¢ Arrange for each Scheme implementation to load its SLIB initialization ļ¬le.
ā€¢ Build the SLIB catalog for each Scheme implementation.
8.1.1 Unpacking the SLIB Distribution
If the SLIB distribution is a GNU/Linux RPM, it will create the SLIB directory
/usr/share/slib.
If the SLIB distribution is a ZIP ļ¬le, unzip the distribution to create the SLIB directory.
Locate this slib directory either in your home directory (if only you will use this SLIB
installation); or put it in a location where libraries reside on your system. On unix systems
this might be /usr/share/slib, /usr/local/lib/slib, or /usr/lib/slib. If you know
where SLIB should go on other platforms, please inform ag[email protected].
8.1.2 Install documentation and slib script
make infoz
make install
8.1.3 Conļ¬gure Scheme Implementation to Locate SLIB
If the Scheme implementation supports getenv, then the value of the shell environment
variable SCHEME LIBRARY PATH will be used for (library-vicinity) if it is deļ¬ned.
Currently, Bigloo, Chez, Elk, Gambit, Gauche, Guile, Jscheme, Larceny, MITScheme,
MzScheme, RScheme, S7, STk, VSCM, and SCM support getenv. Scheme48 supports
getenv but does not use it for determining library-vicinity. (That is done from the
Makeļ¬le.)
The (library-vicinity) can also be set from the SLIB initialization ļ¬le or by
implementation-speciļ¬c means.
Chapter 8: About SLIB 269
8.1.4 Conļ¬gure Scheme Implementation to Locate and
Implementation Directory
Support for locating an implementationā€™s auxiliary directory is uneven among implementa-
tions. Also, the person installing SLIB may not have write permission to some of these direc-
tories (necessary for writing slibcat). Therefore, those implementations supporting getenv
(except SCM and Scheme48) provide a means for specifying the implementation-vicinity
through environment variables. Deļ¬ne the indicated environment variable to the path-
name (with trailing slash or backslash) of the desired directory. Do not use slib/ as an
implementation-vicinity!
Bigloo BIGLOO IMPLEMENTATION PATH
Chez CHEZ IMPLEMENTATION PATH
ELK ELK IMPLEMENTATION PATH
Gambit GAMBIT IMPLEMENTATION PATH
Guile GUILE IMPLEMENTATION PATH
Jscheme JSCHEME IMPLEMENTATION PATH
MIT-Scheme MITSCHEME IMPLEMENTATION PATH
MzScheme MZSCHEME IMPLEMENTATION PATH
RScheme RSCHEME IMPLEMENTATION PATH
S7 S7 IMPLEMENTATION PATH
STk STK IMPLEMENTATION PATH
Vscm VSCM IMPLEMENTATION PATH
8.1.5 Loading SLIB Initialization File
If you use the slib script to start your SLIB session, then this step is unnecessary.
Check the manifest in README to ļ¬nd a conļ¬guration ļ¬le for your Scheme implemen-
tation. Initialization ļ¬les for most IEEE P1178 compliant Scheme Implementations are
included with this distribution.
You should check the deļ¬nitions of software-type, scheme-implementation-
version,
implementation-vicinity, and library-vicinity in the initialization ļ¬le. There are
comments in the ļ¬le for how to conļ¬gure it.
Once this is done, modify the startup ļ¬le for your Scheme implementation to load this
initialization ļ¬le.
8.1.6 Build New SLIB Catalog for the Implementation
When SLIB is ļ¬rst used from an implementation, a ļ¬le named slibcat is written to the
implementation-vicinity for that implementation. Because users may lack permission
to write in implementation-vicinity, it is good practice to build the new catalog when
installing SLIB.
To build (or rebuild) the catalog, start the Scheme implementation (with SLIB), then:
(require ā€™new-catalog)
The catalog also supports color-name dictionaries. With an SLIB-installed scheme
implementation, type:
(require ā€™color-names)
(make-slib-color-name-db)
Chapter 8: About SLIB 270
(require ā€™new-catalog)
(slib:exit)
8.1.7 Implementation-speciļ¬c Instructions
Multiple implementations of Scheme can all use the same SLIB directory. Simply conļ¬gure
each implementationā€™s initialization ļ¬le as outlined above.
[Implementation]SCM
The SCM implementation does not require any initialization ļ¬le as SLIB support is
already built into SCM. See the documentation with SCM for installation instructions.
[Implementation]Larceny
Starting with version 0.96, Larceny contains its own SLIB initialization ļ¬le, loaded by
(require ā€™srfi-96). If SCHEME LIBRARY PATH is not set, then Larceny looks
for an slib subdirectory of a directory in the list returned by (current-require-
path)
larceny -- -e "(require ā€™srfi-96)"
[Implementation]Gauche-0.9
Gauche also supports SLIB. It ļ¬nds SLIB at installation time; (use slib) to enable.
gosh -u slib
[Implementation]ELK
elk -i -l ${SCHEME_LIBRARY_PATH}elk.init
[Implementation]PLT Scheme
[Implementation]DrScheme
[Implementation]MzScheme
The init.ss ļ¬le in the slibinit collection is an SLIB initialization ļ¬le. To run SLIB
in MzScheme:
mzscheme -f ${SCHEME_LIBRARY_PATH}mzscheme.init
[Implementation]MIT Scheme
scheme -load ${SCHEME_LIBRARY_PATH}mitscheme.init
[Implementation]Gambit-C 3.0
gsi -:s ${SCHEME_LIBRARY_PATH}gambit.init -
[Implementation]SISC
sisc -e "(load \"${SCHEME_LIBRARY_PATH}sisc.init\")" --
[Implementation]Kawa
kawa -f ${SCHEME_LIBRARY_PATH}kawa.init --
[Implementation]Guile
Guile versions 1.6 and earlier link to an archaic SLIB version. In RedHat or Fedora
installations:
rm /usr/share/guile/slib
Chapter 8: About SLIB 271
ln -s ${SCHEME_LIBRARY_PATH} /usr/share/guile/slib
In Debian installations:
rm /usr/share/guile/1.6/slib
ln -s ${SCHEME_LIBRARY_PATH} /usr/share/guile/1.6/slib
${SCHEME_LIBRARY_PATH} is where SLIB gets installed.
Guile before version 1.8 with SLIB can then be started thus:
guile -l ${SCHEME_LIBRARY_PATH}guile.init
Guile version 1.8 and after with SLIB can then be started thus:
guile -l ${SCHEME_LIBRARY_PATH}guile.init \
-l ${SCHEME_LIBRARY_PATH}guile.use
The Guile manual has a diļ¬€erent way of installing SLIB:
http://www.gnu.org/software/guile/manual/html_node/SLIB-installation.html
[Implementation]Scheme48
To make a Scheme48 image for an installation under <prefix>,
1. cd to the SLIB directory
2. type make prefix=<prefix> slib48.
3. To install the image, type make prefix=<prefix> install48. This will also
create a shell script with the name slib48 which will invoke the saved image.
[Implementation]VSCM
From: Matthias Blume <blume @ cs.Princeton.EDU>
Date: Tue, 1 Mar 1994 11:42:31 -0500
Disclaimer: The code below is only a quick hack. If I ļ¬nd some time to spare I might
get around to make some more things work.
You have to provide vscm.init as an explicit command line argument. Since this is
not very nice I would recommend the following installation procedure:
1. run scheme
2. (load "vscm.init")
3. (slib:dump "dumpfile")
4. mv dumpļ¬le place-where-vscm-standard-bootļ¬le-resides. For example:
mv dumpfile /usr/local/vscm/lib/scheme-boot
In this case vscm should have been compiled with ļ¬‚ag:
-DDEFAULT BOOTFILE=ā€™"/usr/local/vscm/lib/scheme-boot"ā€™
See Makeļ¬le (deļ¬nition of DDP) for details.
[Implementation]S7
S7 is not a standalone implementation, but runs as the extension language for the
Snd sound editor. ${SCHEME_LIBRARY_PATH}s7.init can be loaded from the Snd
init ļ¬le or on the Snd command line thus:
Chapter 8: About SLIB 272
snd -l ${SCHEME_LIBRARY_PATH}s7.init
8.2 The SLIB script
SLIB comes with shell script for Unix platforms.
slib [ scheme | scm | gsi | mzscheme | guile
| scheme48 | scmlit | elk | sisc | kawa ]
Starts an interactive Scheme-with-SLIB session.
The optional argument to the slib script is the Scheme implementation to run. Absent
the argument, it searches for implementations in the above order.
8.3 Porting
If there is no initialization ļ¬le for your Scheme implementation, you will have to create one.
Your Scheme implementation must be largely compliant with
IEEE Std 1178-1990,
Revised^4 Report on the Algorithmic Language Scheme, or
Revised^5 Report on the Algorithmic Language Scheme
in order to support SLIB.
1
http://cvs.savannah.gnu.org/viewcvs/*checkout*/scm/scm/r4rstest.scm is a ļ¬le
which checks compliance with much of R4RS.
Template.scm is an example conļ¬guration ļ¬le. The comments inside will direct you on
how to customize it to reļ¬‚ect your system. Give your new initialization ļ¬le the implemen-
tationā€™s name with .init appended. For instance, if you were porting foo-scheme then
the initialization ļ¬le might be called foo.init.
Your customized version should then be loaded as part of your scheme implementationā€™s
initialization. It will load require.scm from the library; this will allow the use of provide,
provided?, and require along with the vicinity functions (these functions are documented
in the sections Section 1.1 [Feature], page 1, and Section 1.2 [Require], page 2). The rest of
the library will then be accessible in a system independent fashion.
Please mail new working conļ¬guration ļ¬les to [email protected] so that they can be
included in the SLIB distribution.
8.4 Compiled and Implementation-Speciļ¬c Features
Often an implementation can implement an SLIB feature more eļ¬ƒciently than the R4RS-
compliant source code in SLIB. Alternatively, implementations with compilers can compile
SLIB source code into binary ļ¬les which run faster than loading source code.
Additionally, the SLIB catalog can be augmented with extra-SLIB features which can
be loaded by the implementation. The catalog format is described in See Section 1.3 [Library
Catalogs], page 3.
1
If you are porting a Revised^3 Report on the Algorithmic Language Scheme implementation, then you
will need to ļ¬nish writing sc4sc3.scm and load it from your initialization ļ¬le.
Chapter 8: About SLIB 273
These implementation-speciļ¬c modiļ¬cations are made when a new catalog
is created (see Section 1.4 [Catalog Creation], page 3). If mkimpcat.scm in
implementation-invicinity exists, it is loaded. That should produce the ļ¬le implcat in
implementation-invicinity, whose associations will override those of SLIB. implcat is
copied into slibcat in implementation-vicinity as part of the catalog creation process;
modiļ¬cations to implcat after that will have no eļ¬€ect.
8.5 Coding Guidelines
All library packages are written in IEEE P1178 Scheme and assume that a conļ¬guration
ļ¬le and require.scm package have already been loaded. Other versions of Scheme can
be supported in library packages as well by using, for example, (provided? ā€™r3rs) or
(require ā€™r3rs) (see Section 1.2 [Require], page 2).
If a procedure deļ¬ned in a module is called by other procedures in that module, then
those procedures should instead call an alias deļ¬ned in that module:
(define module-name:foo foo)
The module name and ā€˜:ā€™ should preļ¬x that symbol for the internal name. Do not
export internal aliases.
A procedure is exported from a module by putting Schmooz-style comments (see
Section 4.15 [Schmooz], page 101) or ā€˜;@ā€™ at the beginning of the line immediately pre-
ceding the deļ¬nition (define, define-syntax, or defmacro). Modules, exports and other
relevant issues are discussed in Section 1.6 [Compiling Scheme], page 6.
Code submitted for inclusion in SLIB should not duplicate (more than one) routines
already in SLIB ļ¬les. Use require to force those library routines to be used by your
package.
Documentation should be provided in Emacs Texinfo format if possible, but documen-
tation must be provided.
Your package will be released sooner with SLIB if you send me a ļ¬le which tests your
code. Please run this test before you send me the code!
8.5.1 Modiļ¬cations
Please document your changes. A line or two for ChangeLog is suļ¬ƒcient for simple ļ¬xes or
extensions. Look at the format of ChangeLog to see what information is desired. Please send
me diff ļ¬les from the latest SLIB distribution (remember to send diffs of slib.texi and
ChangeLog). This makes for less email traļ¬ƒc and makes it easier for me to integrate when
more than one person is changing a ļ¬le (this happens a lot with slib.texi and ā€˜*.initā€™
ļ¬les).
If someone else wrote a package you want to signiļ¬cantly modify, please try to contact
the author, who may be working on a new version. This will insure against wasting eļ¬€ort
on obsolete versions.
Please do not reformat the source code with your favorite beautiļ¬er, make 10 ļ¬xes,
and send me the resulting source code. I do not have the time to ļ¬sh through 10000 diļ¬€s
to ļ¬nd your 10 real ļ¬xes.
Chapter 8: About SLIB 274
8.6 Copyrights
This section has instructions for SLIB authors regarding copyrights.
Each package in SLIB must either be in the public domain, or come with a statement of
terms permitting users to copy, redistribute and modify it. The comments at the beginning
of require.scm and macwork.scm illustrate copyright and appropriate terms.
If your code or changes amount to less than about 10 lines, you do not need to add
your copyright or send a disclaimer.
8.6.1 Putting code into the Public Domain
In order to put code in the public domain you should sign a copyright disclaimer and send
it to the SLIB maintainer. Contact [email protected] for the address to mail the disclaimer
to.
I, <my-name>, hereby aļ¬ƒrm that I have placed the software package <name>
in the public domain.
I aļ¬ƒrm that I am the sole author and sole copyright holder for the software
package, that I have the right to place this software package in the public
domain, and that I will do nothing to undermine this status in the future.
signature and date
This wording assumes that you are the sole author. If you are not the sole author, the
wording needs to be diļ¬€erent. If you donā€™t want to be bothered with sending a letter every
time you release or modify a module, make your letter say that it also applies to your future
revisions of that module.
Make sure no employer has any claim to the copyright on the work you are submitting.
If there is any doubt, create a copyright disclaimer and have your employer sign it. Mail
the signed disclaimer to the SLIB maintainer. Contact ag[email protected] for the address
to mail the disclaimer to. An example disclaimer follows.
8.6.2 Explicit copying terms
If you submit more than about 10 lines of code which you are not placing into the Public
Domain (by sending me a disclaimer) you need to:
ā€¢ Arrange that your name appears in a copyright line for the appropriate year. Multiple
copyright lines are acceptable.
ā€¢ With your copyright line, specify any terms you require to be diļ¬€erent from those
already in the ļ¬le.
ā€¢ Make sure no employer has any claim to the copyright on the work you are submitting.
If there is any doubt, create a copyright disclaimer and have your employer sign it.
Mail the signed disclaim to the SLIB maintainer. Contact ag[email protected] for the
address to mail the disclaimer to.
8.6.3 Example: Company Copyright Disclaimer
This disclaimer should be signed by a vice president or general manager of the company. If
you canā€™t get at them, anyone else authorized to license out software produced there will
do. Here is a sample wording:
Chapter 8: About SLIB 275
<employer> Corporation hereby disclaims all copyright interest in the program
<program> written by <name>.
<employer> Corporation aļ¬ƒrms that it has no other intellectual property inter-
est that would undermine this release, and will do nothing to undermine it in
the future.
<signature and date>,
<name>, <title>, <employer> Corporation
8.7 About this manual
ā€¢ Entries that are labeled as Functions are called for their return values. Entries that
are labeled as Procedures are called primarily for their side eļ¬€ects.
ā€¢ Examples in this text were produced using the scm Scheme implementation.
ā€¢ At the beginning of each section, there is a line that looks like:
(require ā€™feature)
Include this line in your code prior to using the package.
8.7.1 GNU Free Documentation License
Version 1.3, 3 November 2008
Copyright
c
ī€ 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.
http://fsf.org/
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
0. PREAMBLE
The purpose of this License is to make a manual, textbook, or other functional and
useful document free in the sense of freedom: to assure everyone the eļ¬€ective freedom
to copy and redistribute it, with or without modifying it, either commercially or non-
commercially. Secondarily, this License preserves for the author and publisher a way
to get credit for their work, while not being considered responsible for modiļ¬cations
made by others.
This License is a kind of ā€œcopyleftā€, which means that derivative works of the document
must themselves be free in the same sense. It complements the GNU General Public
License, which is a copyleft license designed for free software.
We have designed this License in order to use it for manuals for free software, because
free software needs free documentation: a free program should come with manuals
providing the same freedoms that the software does. But this License is not limited to
software manuals; it can be used for any textual work, regardless of subject matter or
whether it is published as a printed book. We recommend this License principally for
works whose purpose is instruction or reference.
1. APPLICABILITY AND DEFINITIONS
This License applies to any manual or other work, in any medium, that contains a
notice placed by the copyright holder saying it can be distributed under the terms
of this License. Such a notice grants a world-wide, royalty-free license, unlimited in
Chapter 8: About SLIB 276
duration, to use that work under the conditions stated herein. The ā€œDocumentā€,
below, refers to any such manual or work. Any member of the public is a licensee, and
is addressed as ā€œyouā€. You accept the license if you copy, modify or distribute the work
in a way requiring permission under copyright law.
A ā€œModiļ¬ed Versionā€ of the Document means any work containing the Document or
a portion of it, either copied verbatim, or with modiļ¬cations and/or translated into
another language.
A ā€œSecondary Sectionā€ is a named appendix or a front-matter section of the Document
that deals exclusively with the relationship of the publishers or authors of the Document
to the Documentā€™s overall subject (or to related matters) and contains nothing that
could fall directly within that overall subject. (Thus, if the Document is in part a
textbook of mathematics, a Secondary Section may not explain any mathematics.) The
relationship could be a matter of historical connection with the subject or with related
matters, or of legal, commercial, philosophical, ethical or political position regarding
them.
The ā€œInvariant Sectionsā€ are certain Secondary Sections whose titles are designated, as
being those of Invariant Sections, in the notice that says that the Document is released
under this License. If a section does not ļ¬t the above deļ¬nition of Secondary then it is
not allowed to be designated as Invariant. The Document may contain zero Invariant
Sections. If the Document does not identify any Invariant Sections then there are none.
The ā€œCover Textsā€ are certain short passages of text that are listed, as Front-Cover
Texts or Back-Cover Texts, in the notice that says that the Document is released under
this License. A Front-Cover Text may be at most 5 words, and a Back-Cover Text may
be at most 25 words.
A ā€œTransparentā€ copy of the Document means a machine-readable copy, represented
in a format whose speciļ¬cation is available to the general public, that is suitable for
revising the document straightforwardly with generic text editors or (for images com-
posed of pixels) generic paint programs or (for drawings) some widely available drawing
editor, and that is suitable for input to text formatters or for automatic translation to
a variety of formats suitable for input to text formatters. A copy made in an otherwise
Transparent ļ¬le format whose markup, or absence of markup, has been arranged to
thwart or discourage subsequent modiļ¬cation by readers is not Transparent. An image
format is not Transparent if used for any substantial amount of text. A copy that is
not ā€œTransparentā€ is called ā€œOpaqueā€.
Examples of suitable formats for Transparent copies include plain ascii without
markup, Texinfo input format, LaT
E
X input format, SGML or XML using a publicly
available DTD, and standard-conforming simple HTML, PostScript or PDF designed
for human modiļ¬cation. Examples of transparent image formats include PNG, XCF
and JPG. Opaque formats include proprietary formats that can be read and edited
only by proprietary word processors, SGML or XML for which the DTD and/or
processing tools are not generally available, and the machine-generated HTML,
PostScript or PDF produced by some word processors for output purposes only.
The ā€œTitle Pageā€ means, for a printed book, the title page itself, plus such following
pages as are needed to hold, legibly, the material this License requires to appear in the
title page. For works in formats which do not have any title page as such, ā€œTitle Pageā€
Chapter 8: About SLIB 277
means the text near the most prominent appearance of the workā€™s title, preceding the
beginning of the body of the text.
The ā€œpublisherā€ means any person or entity that distributes copies of the Document
to the public.
A section ā€œEntitled XYZā€ means a named subunit of the Document whose title either
is precisely XYZ or contains XYZ in parentheses following text that translates XYZ in
another language. (Here XYZ stands for a speciļ¬c section name mentioned below, such
as ā€œAcknowledgementsā€, ā€œDedicationsā€, ā€œEndorsementsā€, or ā€œHistoryā€.) To ā€œPreserve
the Titleā€ of such a section when you modify the Document means that it remains a
section ā€œEntitled XYZā€ according to this deļ¬nition.
The Document may include Warranty Disclaimers next to the notice which states that
this License applies to the Document. These Warranty Disclaimers are considered to
be included by reference in this License, but only as regards disclaiming warranties:
any other implication that these Warranty Disclaimers may have is void and has no
eļ¬€ect on the meaning of this License.
2. VERBATIM COPYING
You may copy and distribute the Document in any medium, either commercially or
noncommercially, provided that this License, the copyright notices, and the license
notice saying this License applies to the Document are reproduced in all copies, and
that you add no other conditions whatsoever to those of this License. You may not use
technical measures to obstruct or control the reading or further copying of the copies
you make or distribute. However, you may accept compensation in exchange for copies.
If you distribute a large enough number of copies you must also follow the conditions
in section 3.
You may also lend copies, under the same conditions stated above, and you may publicly
display copies.
3. COPYING IN QUANTITY
If you publish printed copies (or copies in media that commonly have printed covers) of
the Document, numbering more than 100, and the Documentā€™s license notice requires
Cover Texts, you must enclose the copies in covers that carry, clearly and legibly, all
these Cover Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on
the back cover. Both covers must also clearly and legibly identify you as the publisher
of these copies. The front cover must present the full title with all words of the title
equally prominent and visible. You may add other material on the covers in addition.
Copying with changes limited to the covers, as long as they preserve the title of the
Document and satisfy these conditions, can be treated as verbatim copying in other
respects.
If the required texts for either cover are too voluminous to ļ¬t legibly, you should put
the ļ¬rst ones listed (as many as ļ¬t reasonably) on the actual cover, and continue the
rest onto adjacent pages.
If you publish or distribute Opaque copies of the Document numbering more than 100,
you must either include a machine-readable Transparent copy along with each Opaque
copy, or state in or with each Opaque copy a computer-network location from which
the general network-using public has access to download using public-standard network
protocols a complete Transparent copy of the Document, free of added material. If
Chapter 8: About SLIB 278
you use the latter option, you must take reasonably prudent steps, when you begin
distribution of Opaque copies in quantity, to ensure that this Transparent copy will
remain thus accessible at the stated location until at least one year after the last time
you distribute an Opaque copy (directly or through your agents or retailers) of that
edition to the public.
It is requested, but not required, that you contact the authors of the Document well
before redistributing any large number of copies, to give them a chance to provide you
with an updated version of the Document.
4. MODIFICATIONS
You may copy and distribute a Modiļ¬ed Version of the Document under the conditions
of sections 2 and 3 above, provided that you release the Modiļ¬ed Version under precisely
this License, with the Modiļ¬ed Version ļ¬lling the role of the Document, thus licensing
distribution and modiļ¬cation of the Modiļ¬ed Version to whoever possesses a copy of
it. In addition, you must do these things in the Modiļ¬ed Version:
A. Use in the Title Page (and on the covers, if any) a title distinct from that of the
Document, and from those of previous versions (which should, if there were any,
be listed in the History section of the Document). You may use the same title as
a previous version if the original publisher of that version gives permission.
B. List on the Title Page, as authors, one or more persons or entities responsible for
authorship of the modiļ¬cations in the Modiļ¬ed Version, together with at least ļ¬ve
of the principal authors of the Document (all of its principal authors, if it has fewer
than ļ¬ve), unless they release you from this requirement.
C. State on the Title page the name of the publisher of the Modiļ¬ed Version, as the
publisher.
D. Preserve all the copyright notices of the Document.
E. Add an appropriate copyright notice for your modiļ¬cations adjacent to the other
copyright notices.
F. Include, immediately after the copyright notices, a license notice giving the public
permission to use the Modiļ¬ed Version under the terms of this License, in the form
shown in the Addendum below.
G. Preserve in that license notice the full lists of Invariant Sections and required Cover
Texts given in the Documentā€™s license notice.
H. Include an unaltered copy of this License.
I. Preserve the section Entitled ā€œHistoryā€, Preserve its Title, and add to it an item
stating at least the title, year, new authors, and publisher of the Modiļ¬ed Version
as given on the Title Page. If there is no section Entitled ā€œHistoryā€ in the Docu-
ment, create one stating the title, year, authors, and publisher of the Document
as given on its Title Page, then add an item describing the Modiļ¬ed Version as
stated in the previous sentence.
J. Preserve the network location, if any, given in the Document for public access to
a Transparent copy of the Document, and likewise the network locations given in
the Document for previous versions it was based on. These may be placed in the
ā€œHistoryā€ section. You may omit a network location for a work that was published
at least four years before the Document itself, or if the original publisher of the
version it refers to gives permission.
Chapter 8: About SLIB 279
K. For any section Entitled ā€œAcknowledgementsā€ or ā€œDedicationsā€, Preserve the Title
of the section, and preserve in the section all the substance and tone of each of the
contributor acknowledgements and/or dedications given therein.
L. Preserve all the Invariant Sections of the Document, unaltered in their text and
in their titles. Section numbers or the equivalent are not considered part of the
section titles.
M. Delete any section Entitled ā€œEndorsementsā€. Such a section may not be included
in the Modiļ¬ed Version.
N. Do not retitle any existing section to be Entitled ā€œEndorsementsā€ or to conļ¬‚ict in
title with any Invariant Section.
O. Preserve any Warranty Disclaimers.
If the Modiļ¬ed Version includes new front-matter sections or appendices that qualify
as Secondary Sections and contain no material copied from the Document, you may at
your option designate some or all of these sections as invariant. To do this, add their
titles to the list of Invariant Sections in the Modiļ¬ed Versionā€™s license notice. These
titles must be distinct from any other section titles.
You may add a section Entitled ā€œEndorsementsā€, provided it contains nothing but
endorsements of your Modiļ¬ed Version by various partiesā€”for example, statements of
peer review or that the text has been approved by an organization as the authoritative
deļ¬nition of a standard.
You may add a passage of up to ļ¬ve words as a Front-Cover Text, and a passage of up
to 25 words as a Back-Cover Text, to the end of the list of Cover Texts in the Modiļ¬ed
Version. Only one passage of Front-Cover Text and one of Back-Cover Text may be
added by (or through arrangements made by) any one entity. If the Document already
includes a cover text for the same cover, previously added by you or by arrangement
made by the same entity you are acting on behalf of, you may not add another; but
you may replace the old one, on explicit permission from the previous publisher that
added the old one.
The author(s) and publisher(s) of the Document do not by this License give permission
to use their names for publicity for or to assert or imply endorsement of any Modiļ¬ed
Version.
5. COMBINING DOCUMENTS
You may combine the Document with other documents released under this License,
under the terms deļ¬ned in section 4 above for modiļ¬ed versions, provided that you
include in the combination all of the Invariant Sections of all of the original documents,
unmodiļ¬ed, and list them all as Invariant Sections of your combined work in its license
notice, and that you preserve all their Warranty Disclaimers.
The combined work need only contain one copy of this License, and multiple identical
Invariant Sections may be replaced with a single copy. If there are multiple Invariant
Sections with the same name but diļ¬€erent contents, make the title of each such section
unique by adding at the end of it, in parentheses, the name of the original author or
publisher of that section if known, or else a unique number. Make the same adjustment
to the section titles in the list of Invariant Sections in the license notice of the combined
work.
Chapter 8: About SLIB 280
In the combination, you must combine any sections Entitled ā€œHistoryā€ in the vari-
ous original documents, forming one section Entitled ā€œHistoryā€; likewise combine any
sections Entitled ā€œAcknowledgementsā€, and any sections Entitled ā€œDedicationsā€. You
must delete all sections Entitled ā€œEndorsements.ā€
6. COLLECTIONS OF DOCUMENTS
You may make a collection consisting of the Document and other documents released
under this License, and replace the individual copies of this License in the various
documents with a single copy that is included in the collection, provided that you
follow the rules of this License for verbatim copying of each of the documents in all
other respects.
You may extract a single document from such a collection, and distribute it individu-
ally under this License, provided you insert a copy of this License into the extracted
document, and follow this License in all other respects regarding verbatim copying of
that document.
7. AGGREGATION WITH INDEPENDENT WORKS
A compilation of the Document or its derivatives with other separate and independent
documents or works, in or on a volume of a storage or distribution medium, is called
an ā€œaggregateā€ if the copyright resulting from the compilation is not used to limit the
legal rights of the compilationā€™s users beyond what the individual works permit. When
the Document is included in an aggregate, this License does not apply to the other
works in the aggregate which are not themselves derivative works of the Document.
If the Cover Text requirement of section 3 is applicable to these copies of the Document,
then if the Document is less than one half of the entire aggregate, the Documentā€™s Cover
Texts may be placed on covers that bracket the Document within the aggregate, or the
electronic equivalent of covers if the Document is in electronic form. Otherwise they
must appear on printed covers that bracket the whole aggregate.
8. TRANSLATION
Translation is considered a kind of modiļ¬cation, so you may distribute translations
of the Document under the terms of section 4. Replacing Invariant Sections with
translations requires special permission from their copyright holders, but you may
include translations of some or all Invariant Sections in addition to the original versions
of these Invariant Sections. You may include a translation of this License, and all the
license notices in the Document, and any Warranty Disclaimers, provided that you
also include the original English version of this License and the original versions of
those notices and disclaimers. In case of a disagreement between the translation and
the original version of this License or a notice or disclaimer, the original version will
prevail.
If a section in the Document is Entitled ā€œAcknowledgementsā€, ā€œDedicationsā€, or ā€œHis-
toryā€, the requirement (section 4) to Preserve its Title (section 1) will typically require
changing the actual title.
9. TERMINATION
You may not copy, modify, sublicense, or distribute the Document except as expressly
provided under this License. Any attempt otherwise to copy, modify, sublicense, or
distribute it is void, and will automatically terminate your rights under this License.
Chapter 8: About SLIB 281
However, if you cease all violation of this License, then your license from a particular
copyright holder is reinstated (a) provisionally, unless and until the copyright holder
explicitly and ļ¬nally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means prior to 60 days
after the cessation.
Moreover, your license from a particular copyright holder is reinstated permanently if
the copyright holder notiļ¬es you of the violation by some reasonable means, this is the
ļ¬rst time you have received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after your receipt of the
notice.
Termination of your rights under this section does not terminate the licenses of parties
who have received copies or rights from you under this License. If your rights have
been terminated and not permanently reinstated, receipt of a copy of some or all of the
same material does not give you any rights to use it.
10. FUTURE REVISIONS OF THIS LICENSE
The Free Software Foundation may publish new, revised versions of the GNU Free
Documentation License from time to time. Such new versions will be similar in spirit
to the present version, but may diļ¬€er in detail to address new problems or concerns.
See http://www.gnu.org/copyleft/.
Each version of the License is given a distinguishing version number. If the Document
speciļ¬es that a particular numbered version of this License ā€œor any later versionā€
applies to it, you have the option of following the terms and conditions either of that
speciļ¬ed version or of any later version that has been published (not as a draft) by
the Free Software Foundation. If the Document does not specify a version number of
this License, you may choose any version ever published (not as a draft) by the Free
Software Foundation. If the Document speciļ¬es that a proxy can decide which future
versions of this License can be used, that proxyā€™s public statement of acceptance of a
version permanently authorizes you to choose that version for the Document.
11. RELICENSING
ā€œMassive Multiauthor Collaboration Siteā€ (or ā€œMMC Siteā€) means any World Wide
Web server that publishes copyrightable works and also provides prominent facilities
for anybody to edit those works. A public wiki that anybody can edit is an example of
such a server. A ā€œMassive Multiauthor Collaborationā€ (or ā€œMMCā€) contained in the
site means any set of copyrightable works thus published on the MMC site.
ā€œCC-BY-SAā€ means the Creative Commons Attribution-Share Alike 3.0 license pub-
lished by Creative Commons Corporation, a not-for-proļ¬t corporation with a principal
place of business in San Francisco, California, as well as future copyleft versions of that
license published by that same organization.
ā€œIncorporateā€ means to publish or republish a Document, in whole or in part, as part
of another Document.
An MMC is ā€œeligible for relicensingā€ if it is licensed under this License, and if all works
that were ļ¬rst published under this License somewhere other than this MMC, and
subsequently incorporated in whole or in part into the MMC, (1) had no cover texts
or invariant sections, and (2) were thus incorporated prior to November 1, 2008.
Chapter 8: About SLIB 282
The operator of an MMC Site may republish an MMC contained in the site under
CC-BY-SA on the same site at any time before August 1, 2009, provided the MMC is
eligible for relicensing.
Chapter 8: About SLIB 283
ADDENDUM: How to use this License for your documents
To use this License in a document you have written, include a copy of the License in the
document and put the following copyright and license notices just after the title page:
Copyright (C) year your name.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3
or any later version published by the Free Software Foundation;
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
Texts. A copy of the license is included in the section entitled ā€˜ā€˜GNU
Free Documentation Licenseā€™ā€™.
If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts, replace the
ā€œwith. . . Texts.ā€ line with this:
with the Invariant Sections being list their titles, with
the Front-Cover Texts being list, and with the Back-Cover Texts
being list.
If you have Invariant Sections without Cover Texts, or some other combination of the
three, merge those two alternatives to suit the situation.
If your document contains nontrivial examples of program code, we recommend releas-
ing these examples in parallel under your choice of free software license, such as the GNU
General Public License, to permit their use in free software.
284
Procedure and Macro Index
ā€“
- . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
-1+ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
/
/ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
<
<=? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
<? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
=
= . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
=? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
>
>=? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
>? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
1
1+ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
A
A:bool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
A:fixN16b . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
A:fixN32b . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
A:fixN64b . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
A:fixN8b . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
A:fixZ16b . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
A:fixZ32b . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
A:fixZ64b . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
A:fixZ8b . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
A:floC128b . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
A:floC16b . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
A:floC32b . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
A:floC64b . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
A:floR128b . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
A:floR128d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
A:floR16b . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
A:floR32b . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
A:floR32d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
A:floR64b . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
A:floR64d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
abort. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
abs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
absolute-path? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
absolute-uri? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
add-command-tables. . . . . . . . . . . . . . . . . . . . . . . . . . 170
add-domain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
add-domain on relational-database . . . . . . . . . 171
add-macro-support . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
add-process! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
add-setter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
adjoin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
adjoin-parameters! . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
alist->wt-tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
alist-associator . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
alist-cons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
alist-copy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
alist-delete . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
alist-delete! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
alist-for-each . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
alist-inquirer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
alist-map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
alist-remover . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
alist-table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
and-let* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
and? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
any . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
any-bits-set? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
any? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
append! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
append-reverse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
append-reverse! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
apply. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
arithmetic-shift . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
array->list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
array->vector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
array-dimensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
array-for-each . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
array-in-bounds? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
array-index-for-each . . . . . . . . . . . . . . . . . . . . . . . 202
array-index-map! . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
array-indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
array-map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
array-map! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
array-rank . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
array-ref . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
array-set! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
array-trim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
array:copy! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
array? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
asctime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
ash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
assoc. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
atan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
atom?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
attlist-add . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
attlist-remove-top . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Procedure and Macro Index 285
B
batch:call-with-output-script . . . . . . . . . . . . . . 66
batch:command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
batch:comment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
batch:delete-file . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
batch:initialize! . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
batch:lines->file . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
batch:rename-file . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
batch:run-script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
batch:try-chopped-command . . . . . . . . . . . . . . . . . . . 67
batch:try-command . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
bit-field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
bit-set? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
bitwise-and . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
bitwise-bit-count . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
bitwise-if . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
bitwise-ior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
bitwise-merge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
bitwise-not . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
bitwise-xor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
blackbody-spectrum. . . . . . . . . . . . . . . . . . . . . . . . . . 143
booleans->integer . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
break . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256, 259, 260
break! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
break-all . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
breakf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
breakpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
browse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
browse-url . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
butlast . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
butnth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
butnthcdr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
byte-ref . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
byte-set! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
bytes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
bytes->ieee-double. . . . . . . . . . . . . . . . . . . . . . . . . . 207
bytes->ieee-float . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
bytes->integer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
bytes->list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
bytes->string . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
bytes-copy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
bytes-length . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
bytes-reverse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
bytes-reverse! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
C
call-with-dynamic-binding. . . . . . . . . . . . . . . . . . 214
call-with-input-string . . . . . . . . . . . . . . . . . . . . . 243
call-with-open-ports . . . . . . . . . . . . . . . . . . . . . . . . 14
call-with-output-string . . . . . . . . . . . . . . . . . . . . 243
call-with-tmpnam . . . . . . . . . . . . . . . . . . . . . . . . . 65, 66
call-with-values . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
capture-syntactic-environment . . . . . . . . . . . . . . 27
car+cdr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
cart-prod-tables on relational-database . . 188
catalog->html . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
catalog-id on base-table . . . . . . . . . . . . . . . . . . . 182
catalog:read . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
cdna:base-count . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
cdna:report-base-count . . . . . . . . . . . . . . . . . . . . . 101
cgi:serve-query . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
chap:next-string . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
chap:string<=? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
chap:string<? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
chap:string>=? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
chap:string>? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
check-parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
chromaticity->CIEXYZ . . . . . . . . . . . . . . . . . . . . . . . 144
chromaticity->whitepoint . . . . . . . . . . . . . . . . . . . 144
CIE:DE* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
CIE:DE*94 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
ciexyz->color . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
CIEXYZ->e-sRGB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
CIEXYZ->L*a*b* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
CIEXYZ->L*u*v* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
CIEXYZ->RGB709 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
CIEXYZ->sRGB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
CIEXYZ->xRGB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
circular-list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
circular-list? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
cksum. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
clear-sky-color-xyy . . . . . . . . . . . . . . . . . . . . . . . . 151
clip-to-rect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
close-base on base-table . . . . . . . . . . . . . . . . . . . 181
close-database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
close-database on relational-database . . . . 187
close-port . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
close-table on relational-table . . . . . . . . . . . 169
CMC-DE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
CMC:DE* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
codons<-cdna . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
coerce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
collection? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
color->ciexyz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
color->e-srgb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
color->l*a*b* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
color->l*c*h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
color->l*u*v* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
color->rgb709 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
color->srgb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
color->string . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
color->xrgb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
color-dictionaries->lookup . . . . . . . . . . . . . . . . 147
color-dictionary . . . . . . . . . . . . . . . . . . . . . . . 147, 148
color-name->color . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
color-name:canonicalize . . . . . . . . . . . . . . . . . . . . 147
color-precision . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
color-space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
color-white-point . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
color:ciexyz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
color:e-srgb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
color:l*a*b* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
color:l*c*h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
color:l*u*v* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
color:linear-transform . . . . . . . . . . . . . . . . . . . . . 146
Procedure and Macro Index 286
color:rgb709 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
color:srgb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
color?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134, 135
column-domains on relational-table . . . . . . . . 169
column-foreigns on relational-table . . . . . . . 169
column-names on relational-table . . . . . . . . . . 169
column-range . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
column-types on relational-table . . . . . . . . . . 169
combine-ranges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
combined-rulesets . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
command->p-specs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
command:make-editable-table . . . . . . . . . . . . . . . . 74
command:modify-table . . . . . . . . . . . . . . . . . . . . . . . . 74
concatenate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
concatenate! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
cond . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
cond-expand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
cons*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
continue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
convert-color . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
coordinates->integer . . . . . . . . . . . . . . . . . . . . . . . 236
copy-bit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
copy-bit-field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
copy-list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
copy-random-state . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
copy-tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
count. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
count-newlines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
crc:make-table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
crc16. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
crc5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
create-array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
create-database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
create-database on relational-system . . . . . . 186
create-postscript-graph . . . . . . . . . . . . . . . . . . . . 120
create-table on relational-database . . . . . . . 188
create-view on relational-database . . . . . . . . 188
cring:define-rule . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
ctime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
current-directory . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
current-error-port . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
current-input-port . . . . . . . . . . . . . . . . . . . . . . 42, 205
current-output-port . . . . . . . . . . . . . . . . . . . . . . . . 205
current-time. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
cvs-directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
cvs-files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
cvs-repository . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
cvs-root . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
cvs-set-root! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
cvs-set-roots! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
cvs-vet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
D
db->html-directory . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
db->html-files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
db->netscape. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
decode-universal-time . . . . . . . . . . . . . . . . . . . . . . . 99
define-*commands* . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
define-access-operation . . . . . . . . . . . . . . . . . . . . . 37
define-command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
define-domains . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
define-macro . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
define-operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
define-predicate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
define-record-type . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
define-structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
define-syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
define-table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
define-tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
defmacro . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
defmacro:eval . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
defmacro:expand* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
defmacro:load . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
defmacro? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
delaminate-list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
delay. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
delete . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
delete on base-table . . . . . . . . . . . . . . . . . . . . . . . . 183
delete* on base-table . . . . . . . . . . . . . . . . . . . . . . . 184
delete-domain on relational-database . . . . . . 171
delete-duplicates . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
delete-duplicates!. . . . . . . . . . . . . . . . . . . . . . . . . . 256
delete-file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
delete-if . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
delete-if-not . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
delete-table on relational-database . . . . . . . 188
dequeue! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
dequeue-all! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
describe-file-lock. . . . . . . . . . . . . . . . . . . . . . . . . . 264
determinant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
dft . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
dft-1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
diff:edit-length . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
diff:edits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
diff:longest-common-subsequence . . . . . . . . . . . 241
difftime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
directory*-for-each . . . . . . . . . . . . . . . . . . . . . . . . 263
directory-for-each. . . . . . . . . . . . . . . . . . . . . . . . . . 263
do-elts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
do-keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
domain-checker on relational-database . . . . 171
dotted-list? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
drop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
drop-right . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
drop-right! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
dynamic-ref . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
dynamic-set! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
dynamic-wind . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
dynamic? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
Procedure and Macro Index 287
E
e-srgb->color . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
e-sRGB->CIEXYZ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
e-sRGB->e-sRGB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
e-sRGB->sRGB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
eighth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
emacs:backup-name . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
empty? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
encode-universal-time . . . . . . . . . . . . . . . . . . . . . . 100
enqueue! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
equal?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196, 204
eval . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
every. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
every? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
exports<-info-index. . . . . . . . . . . . . . . . . . . . . . . . . . 10
extended-euclid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
F
factor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
feature->export-alist . . . . . . . . . . . . . . . . . . . . . . . . 8
feature->exports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
feature->requires . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
feature->requires* . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
feature-eval . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
fft . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
fft-1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
fifth. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
file->color-dictionary . . . . . . . . . . . . . . . . . . . . . 148
file->definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
file->exports. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
file->loads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
file->requires . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
file->requires* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
file-exists?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
file-lock! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
file-lock-owner . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
file-position . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
file-unlock! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
filename:match-ci??. . . . . . . . . . . . . . . . . . . . . . . . . . 64
filename:match?? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
filename:substitute-ci?? . . . . . . . . . . . . . . . . . . . . 65
filename:substitute?? . . . . . . . . . . . . . . . . . . . . . . . 65
fill-empty-parameters . . . . . . . . . . . . . . . . . . . . . . . 62
fill-rect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
filter! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
find . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
find-if . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
find-ratio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
find-ratio-between. . . . . . . . . . . . . . . . . . . . . . . . . . 251
find-string-from-port? . . . . . . . . . . . . . . . . 240, 241
find-tail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
first. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
first-set-bit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
fluid-let . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
fold . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
fold-right . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
for-each-elt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
for-each-key . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
for-each-key on base-table . . . . . . . . . . . . . . . . . 184
for-each-row on relational-table . . . . . . . . . . 167
for-each-row-in-order on
relational-table . . . . . . . . . . . . . . . . . . . . . . . . . . 168
force. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
force-output. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
form:delimited . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
form:element. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
form:image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
form:reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
form:submit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
format. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
fourth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
fprintf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
fscanf. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
G
gen-elts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
gen-keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
generic-write . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
gentemp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
get on relational-table . . . . . . . . . . . . . . . . . . . . . 165
get* on relational-table . . . . . . . . . . . . . . . . . . . 166
get-decoded-time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
get-foreign-choices. . . . . . . . . . . . . . . . . . . . . . . . . . 72
get-method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
get-universal-time . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
getenv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
getopt. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
getopt-- . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
getopt->arglist . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
getopt->parameter-list . . . . . . . . . . . . . . . . . . . . . . 63
glob-pattern? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
gmktime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
gmtime. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
golden-section-search . . . . . . . . . . . . . . . . . . . . . . 153
gray-code->integer. . . . . . . . . . . . . . . . . . . . . . . . . . 237
gray-code<=? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
gray-code<? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
gray-code>=? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
gray-code>? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
grey . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
grid-horizontals . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
grid-verticals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
gtime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Procedure and Macro Index 288
H
has-duplicates? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
hash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
hash-associator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
hash-for-each . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
hash-inquirer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
hash-map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
hash-rehasher . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
hash-remover . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
hashq. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
hashv. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
heap-extract-max! . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
heap-insert! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
heap-length . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
hilbert-coordinates->integer . . . . . . . . . . . . . . 237
histograph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
home-vicinity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
htm-fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
html-for-each . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
html:anchor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
html:atval . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
html:base . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
html:body . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
html:buttons. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
html:caption. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
html:checkbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
html:comment. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
html:delimited-list. . . . . . . . . . . . . . . . . . . . . . . . . . 72
html:editable-row-converter . . . . . . . . . . . . . . . . 74
html:form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
html:head . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
html:heading. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
html:hidden . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
html:href-heading . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
html:http-equiv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
html:isindex. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
html:link . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
html:linked-row-converter . . . . . . . . . . . . . . . . . . . 73
html:meta . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
html:meta-refresh . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
html:plain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
html:pre . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
html:read-title . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
html:select . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
html:table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
html:text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
html:text-area . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
http:content. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
http:error-page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
http:forwarding-page . . . . . . . . . . . . . . . . . . . . . . . . 75
http:header . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
http:serve-query . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
I
identifier=?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
identifier? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
identity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
ieee-byte-collate . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
ieee-byte-collate!. . . . . . . . . . . . . . . . . . . . . . . . . . 209
ieee-byte-decollate . . . . . . . . . . . . . . . . . . . . . . . . 209
ieee-byte-decollate! . . . . . . . . . . . . . . . . . . . . . . . 209
ieee-double->bytes. . . . . . . . . . . . . . . . . . . . . . . . . . 208
ieee-float->bytes . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
illuminant-map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
illuminant-map->XYZ . . . . . . . . . . . . . . . . . . . . . . . . 142
implementation-vicinity . . . . . . . . . . . . . . . . . . . . . 11
in-graphic-context. . . . . . . . . . . . . . . . . . . . . . . . . . 122
in-vicinity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
init-debug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
integer->bytes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
integer->coordinates . . . . . . . . . . . . . . . . . . . . . . . 236
integer->gray-code. . . . . . . . . . . . . . . . . . . . . . . . . . 237
integer->hilbert-coordinates . . . . . . . . . . . . . . 237
integer->list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
integer->peano-coordinates . . . . . . . . . . . . . . . . 238
integer-byte-collate . . . . . . . . . . . . . . . . . . . . . . . 209
integer-byte-collate! . . . . . . . . . . . . . . . . . . . . . . 209
integer-expt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
integer-length . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
integer-log . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
integer-sqrt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
interaction-environment . . . . . . . . . . . . . . . . . . . . 252
interpolate-array-ref . . . . . . . . . . . . . . . . . . . . . . 202
interpolate-from-table . . . . . . . . . . . . . . . . . . . . . 169
intersection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
iota . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
isam-next on relational-table . . . . . . . . . . . . . . 168
isam-prev on relational-table . . . . . . . . . . . . . . 168
iso-8601->time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
J
jacobi-symbol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
K
kill-process! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
kill-table on base-table . . . . . . . . . . . . . . . . . . . 181
L
l*a*b*->color . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
l*c*h->color . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
l*u*v*->color . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
L*a*b*->CIEXYZ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
L*a*b*->L*C*h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
L*a*b*:DE* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
L*a*b*:DE*94 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
L*C*h->L*a*b* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
L*u*v*->CIEXYZ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
laguerre:find-polynomial-root . . . . . . . . . . . . . 152
Procedure and Macro Index 289
laguerre:find-root. . . . . . . . . . . . . . . . . . . . . . . . . . 152
last . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228, 255
last-pair . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
length+ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
let-values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
let-values* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
library-vicinity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
light:ambient . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
light:beam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
light:directional . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
light:point . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
light:spot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
limit. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
list*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
list->array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
list->bytes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
list->integer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
list-copy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
list-index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
list-of?? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
list-table-definition . . . . . . . . . . . . . . . . . . . . . . 164
list-tabulate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
list-tail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
list=. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
ln . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
load->path . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
load-ciexyz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
load-color-dictionary . . . . . . . . . . . . . . . . . . . . . . 148
localtime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
log2-binary-factors . . . . . . . . . . . . . . . . . . . . . . . . 105
logand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
logbit? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
logcount . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
logior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
lognot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
logtest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
logxor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
lset-adjoin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
lset-diff+intersection . . . . . . . . . . . . . . . . . . . . . 257
lset-diff+intersection! . . . . . . . . . . . . . . . . . . . . 257
lset-difference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
lset-difference! . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
lset-intersection . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
lset-intersection!. . . . . . . . . . . . . . . . . . . . . . . . . . 257
lset-union . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
lset-union! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
lset-xor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
lset-xor! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
lset<= . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
lset=. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
M
macro:eval . . . . . . . . . . . . . . . . . . . . . . . . . 19, 20, 24, 31
macro:expand . . . . . . . . . . . . . . . . . . . . . . . 19, 20, 24, 31
macro:load . . . . . . . . . . . . . . . . . . . . . . . . . 19, 20, 24, 31
macroexpand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
macroexpand-1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
macwork:eval. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
macwork:expand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
macwork:load. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
make-array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
make-base on base-table . . . . . . . . . . . . . . . . . . . . . 180
make-bytes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
make-cell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
make-color . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
make-command-server . . . . . . . . . . . . . . . . . . . . . . . . 173
make-directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
make-dynamic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
make-exchanger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
make-generic-method . . . . . . . . . . . . . . . . . . . . . . . . 216
make-generic-predicate . . . . . . . . . . . . . . . . . . . . . 216
make-getter on base-table . . . . . . . . . . . . . . . . . . 183
make-getter-1 on base-table . . . . . . . . . . . . . . . . 183
make-hash-table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
make-heap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
make-key->list on base-table . . . . . . . . . . . . . . . 182
make-key-extractor on base-table . . . . . . . . . . 182
make-keyifier-1 on base-table . . . . . . . . . . . . . . 182
make-list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
make-list-keyifier on base-table . . . . . . . . . . 182
make-method! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
make-nexter on base-table . . . . . . . . . . . . . . . . . . 184
make-object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
make-parameter-list. . . . . . . . . . . . . . . . . . . . . . . . . . 62
make-polar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
make-predicate! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
make-prever on base-table . . . . . . . . . . . . . . . . . . 184
make-promise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
make-putter on base-table . . . . . . . . . . . . . . . . . . 183
make-query-alist-command-server . . . . . . . . . . . . 76
make-queue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
make-random-state . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
make-record-type . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
make-rectangular . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
make-relational-system . . . . . . . . . . . . . . . . . . . . . 186
make-ruleset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
make-shared-array . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
make-sierpinski-indexer . . . . . . . . . . . . . . . . . . . . 239
make-slib-color-name-db . . . . . . . . . . . . . . . . . . . . 148
make-syntactic-closure . . . . . . . . . . . . . . . . . . . . . . 26
make-table on base-table . . . . . . . . . . . . . . . . . . . 181
make-uri . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
make-vicinity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
make-wt-tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
make-wt-tree-type . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
map! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
map-elts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
map-key on base-table . . . . . . . . . . . . . . . . . . . . . . . 184
map-keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
Procedure and Macro Index 290
matfile:load . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
matfile:read . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
matrix->array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
matrix->lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
matrix:difference . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
matrix:inverse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
matrix:product . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
matrix:sum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
mdbm:report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
member . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
member-if . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
merge. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
merge! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
mktime. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
mod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
modular:* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
modular:+ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
modular:- . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
modular:characteristic . . . . . . . . . . . . . . . . . . . . . 107
modular:expt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
modular:invert . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
modular:invertable? . . . . . . . . . . . . . . . . . . . . . . . . 108
modular:negate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
modular:normalize . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
modulo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
mrna<-cdna . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
must-be-first . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
must-be-last. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
N
natural->peano-coordinates . . . . . . . . . . . . . . . . 238
ncbi:read-dna-sequence . . . . . . . . . . . . . . . . . . . . . 100
ncbi:read-file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
nconc. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
newton:find-integer-root . . . . . . . . . . . . . . . . . . . 151
newton:find-root . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
ninth. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
not-pair? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
notany . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
notevery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
nreverse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
nthcdr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
null-directory? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
null-environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
null-list? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
O
object. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
object->limited-string . . . . . . . . . . . . . . . . . . . . . . 93
object->string . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
object-with-ancestors . . . . . . . . . . . . . . . . . . . . . . . 36
object? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
offset-time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
open-base on base-table . . . . . . . . . . . . . . . . . . . . . 181
open-command-database . . . . . . . . . . . . . . . . . 170, 171
open-command-database! . . . . . . . . . . . . . . . . . . . . . 171
open-database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
open-database on relational-system . . . . . . . . 187
open-database! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
open-file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14, 205
open-table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
open-table on base-table . . . . . . . . . . . . . . . . . . . 181
open-table on relational-database . . . . . . . . . 187
open-table! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
operate-as . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
or? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
ordered-for-each-key on base-table . . . . . . . . 184
os->batch-dialect . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
outline-rect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
output-port-height . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
output-port-width . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
overcast-sky-color-xyy . . . . . . . . . . . . . . . . . . . . . 151
P
p<-cdna . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
pad-range . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
pair-fold . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
pair-fold-right . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
pair-for-each . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
parameter-list->arglist . . . . . . . . . . . . . . . . . . . . . 63
parameter-list-expand . . . . . . . . . . . . . . . . . . . . . . . 62
parameter-list-ref . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
parse-ftp-address . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
partition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
partition! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
partition-page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
path->uri . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
pathname->vicinity . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
peano-coordinates->integer . . . . . . . . . . . . . . . . 238
peano-coordinates->natural . . . . . . . . . . . . . . . . 238
plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118, 119, 125
plot-column . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
plot-text-column . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
pnm:array-write . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
pnm:image-file->array . . . . . . . . . . . . . . . . . . . . . . 210
pnm:type-dimensions . . . . . . . . . . . . . . . . . . . . . . . . 210
port? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
position . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
pprint-file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
pprint-filter-file . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
prec:commentfix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
prec:define-grammar. . . . . . . . . . . . . . . . . . . . . . . . . . 42
prec:delim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
prec:infix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
prec:inmatchfix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
prec:make-led . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
prec:make-nud . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
prec:matchfix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
prec:nary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
prec:nofix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
prec:parse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
prec:postfix. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
prec:prefix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Procedure and Macro Index 291
prec:prestfix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
predicate->asso . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
predicate->hash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
predicate->hash-asso . . . . . . . . . . . . . . . . . . . . . . . 214
present? on base-table . . . . . . . . . . . . . . . . . . . . . . 183
pretty-print. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
pretty-print->string . . . . . . . . . . . . . . . . . . . . . . . . 94
primary-limit on relational-table . . . . . . . . . 169
prime? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
primes< . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
primes> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
print . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
print-call-stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
printf. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
process:schedule! . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
program-arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
program-vicinity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
project-table on relational-database . . . . . . 188
proper-list? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
protein<-cdna . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
provide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
provided? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Q
qp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
qpn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
qpr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
queue-empty? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
queue-front . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
queue-pop! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
queue-push! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
queue-rear . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
queue? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
quo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
quotient . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
R
random . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
random:exp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
random:hollow-sphere! . . . . . . . . . . . . . . . . . . . . . . 113
random:normal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
random:normal-vector! . . . . . . . . . . . . . . . . . . . . . . 113
random:solid-sphere! . . . . . . . . . . . . . . . . . . . . . . . 113
random:uniform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
rationalize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
read-byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
read-bytes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
read-cie-illuminant . . . . . . . . . . . . . . . . . . . . . . . . 142
read-command. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
read-line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
read-line! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
read-normalized-illuminant . . . . . . . . . . . . . . . . 142
read-options-file . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
real-acos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
real-asin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
real-atan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
real-cos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
real-exp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
real-expt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
real-ln . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
real-log . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
real-sin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
real-sqrt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
real-tan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
receive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
record-accessor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
record-constructor. . . . . . . . . . . . . . . . . . . . . . . . . . 220
record-modifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
record-predicate . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
reduce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211, 227, 256
reduce-init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
rem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
remainder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
remove. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225, 256
remove! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
remove-duplicates . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
remove-if . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
remove-if-not . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
remove-parameter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
remove-setter-for . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
repl:quit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
repl:top-level . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
replace-suffix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
require . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2, 4
require-if . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
resample-array! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
resene . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
restrict-table on relational-database . . . . 188
reverse! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
reverse-bit-field . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
rgb709->color . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
RGB709->CIEXYZ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
rotate-bit-field . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
round-quotient . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
row:delete on relational-table. . . . . . . . . . . . . 166
row:delete* on relational-table . . . . . . . . . . . 167
row:insert on relational-table. . . . . . . . . . . . . 165
row:insert* on relational-table . . . . . . . . . . . 167
row:remove on relational-table. . . . . . . . . . . . . 166
row:remove* on relational-table . . . . . . . . . . . 167
row:retrieve on relational-table . . . . . . . . . . 165
row:retrieve* on relational-table . . . . . . . . . 167
row:update on relational-table. . . . . . . . . . . . . 165
row:update* on relational-table . . . . . . . . . . . 167
rule-horizontal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
rule-vertical . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
Procedure and Macro Index 292
S
saturate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
scanf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
scanf-read-list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
scene:overcast . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
scene:panorama . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
scene:sky-and-dirt. . . . . . . . . . . . . . . . . . . . . . . . . . 128
scene:sky-and-grass . . . . . . . . . . . . . . . . . . . . . . . . 128
scene:sphere . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
scene:sun . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
scene:viewpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
scene:viewpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
scheme-report-environment. . . . . . . . . . . . . . . . . . 252
schmooz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
secant:find-bracketed-root . . . . . . . . . . . . . . . . 152
secant:find-root . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
second . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
seed->random-state. . . . . . . . . . . . . . . . . . . . . . . . . . 112
set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
set-color . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
set-difference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
set-font . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
set-glyphsize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
set-linedash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
set-linewidth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
set-margin-templates . . . . . . . . . . . . . . . . . . . . . . . 124
Setter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
setter. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
setup-plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
seventh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
sft . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
sft-1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
si:conversion-factor . . . . . . . . . . . . . . . . . . . . . . . 247
singleton-wt-tree . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
sixth. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36, 212
sky-color-xyy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
slib:error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
slib:eval . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
slib:eval-load . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
slib:exit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
slib:in-catalog? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
slib:load . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
slib:load-compiled . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
slib:load-source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
slib:report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
slib:report-version. . . . . . . . . . . . . . . . . . . . . . . . . . 13
slib:warn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
snap-range . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
software-type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
solar-declination . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
solar-hour . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
solar-polar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
solid:arrow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
solid:basrelief . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
solid:box . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
solid:center-array-of . . . . . . . . . . . . . . . . . . . . . . 134
solid:center-pile-of . . . . . . . . . . . . . . . . . . . . . . . 134
solid:center-row-of . . . . . . . . . . . . . . . . . . . . . . . . 134
solid:color . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132, 133
solid:cone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
solid:cylinder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
solid:disk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
solid:ellipsoid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
solid:font . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
solid:lumber . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
solid:polyline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
solid:prism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
solid:pyramid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
solid:rotation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
solid:scale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
solid:sphere . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
solid:text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
solid:texture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
solid:translation . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
solidify-database . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
solidify-database on
relational-database . . . . . . . . . . . . . . . . . . . . . . 187
some . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
sort!. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
sorted? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
soundex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
span . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
span!. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
spectrum->chromaticity . . . . . . . . . . . . . . . . . . . . . 143
spectrum->XYZ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
split-at . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
split-at! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
sprintf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
srgb->color . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
sRGB->CIEXYZ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
sRGB->e-sRGB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
sRGB->xRGB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
ssax:assert-current-char . . . . . . . . . . . . . . . . . . . . 81
ssax:assert-token . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
ssax:complete-start-tag . . . . . . . . . . . . . . . . . . . . . 88
ssax:handle-parsed-entity . . . . . . . . . . . . . . . . . . . 87
ssax:init-buffer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
ssax:make-elem-parser . . . . . . . . . . . . . . . . . . . . . . . 90
ssax:make-parser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
ssax:make-pi-parser. . . . . . . . . . . . . . . . . . . . . . . . . . 90
ssax:next-token . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
ssax:next-token-of . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
ssax:read-attributes . . . . . . . . . . . . . . . . . . . . . . . . 87
ssax:read-cdata-body . . . . . . . . . . . . . . . . . . . . . . . . 86
ssax:read-char-data. . . . . . . . . . . . . . . . . . . . . . . . . . 89
ssax:read-char-ref . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
ssax:read-external-id . . . . . . . . . . . . . . . . . . . . . . . 89
ssax:read-markup-token . . . . . . . . . . . . . . . . . . . . . . 85
ssax:read-ncname . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
ssax:read-pi-body-as-string . . . . . . . . . . . . . . . . 86
ssax:read-qname . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
ssax:read-string . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
ssax:resolve-name . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
ssax:reverse-collect-str . . . . . . . . . . . . . . . . . . . . 80
Procedure and Macro Index 293
ssax:reverse-collect-str-drop-ws. . . . . . . . . . . 80
ssax:scan-misc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
ssax:skip-internal-dtd . . . . . . . . . . . . . . . . . . . . . . 86
ssax:skip-pi. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
ssax:skip-s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
ssax:skip-while . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
ssax:xml->sxml . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
sscanf. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
stack. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
stack-all . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
stackf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
string->bytes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
string->color . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
string-capitalize . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
string-capitalize!. . . . . . . . . . . . . . . . . . . . . . . . . . 243
string-ci->symbol . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
string-copy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
string-downcase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
string-downcase! . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
string-fill! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
string-index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
string-index-ci . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
string-join . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
string-null? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
string-reverse-index . . . . . . . . . . . . . . . . . . . . . . . 240
string-reverse-index-ci . . . . . . . . . . . . . . . . . . . . 240
string-subst . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
string-upcase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
string-upcase! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
StudlyCapsExpand . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
sub-vicinity. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
subarray . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
subbytes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
subbytes-read! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
subbytes-write . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
subset? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
subst. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
substq . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
substring-ci? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
substring-fill! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
substring-move-left! . . . . . . . . . . . . . . . . . . . . . . . 249
substring-move-right! . . . . . . . . . . . . . . . . . . . . . . 249
substring? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
substv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
sunlight-chromaticity . . . . . . . . . . . . . . . . . . . . . . 151
sunlight-spectrum . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
supported-key-type? on base-table . . . . . . . . . 182
supported-type? on base-table . . . . . . . . . . . . . . 182
symbol-append . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
symmetric:modulus . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
sync-base on base-table . . . . . . . . . . . . . . . . . . . . . 181
sync-database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
sync-database on relational-database . . . . . . 187
syncase:eval. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
syncase:expand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
syncase:load. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
syncase:sanity-check . . . . . . . . . . . . . . . . . . . . . . . . 31
synclo:eval . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
synclo:expand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
synclo:load . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
syntax-rules. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
system->line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
T
table->linked-html . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
table->linked-page . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
table-exists? on relational-database . . . . . . 187
table-name->filename . . . . . . . . . . . . . . . . . . . . . . . . 73
take . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
take!. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
take-right . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
temperature->chromaticity. . . . . . . . . . . . . . . . . . 143
temperature->XYZ . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
tenth. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
third. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
time->iso-8601 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
time->iso8601 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
time-zone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
time:gmtime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
time:invert . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
time:split . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
title-bottom . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
title-top . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
tmpnam. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
tok:char-group . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
top-refs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
top-refs<-file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
topological-sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
trace. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
trace-all . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
tracef . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
track. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
track-all . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
trackf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
transact-file-replacement. . . . . . . . . . . . . . . . . . 265
transcript-off . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
transcript-on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
transformer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
transpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
truncate-up-to . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
tsort. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
type-of . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
tz:params . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
tz:std-offset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
tzfile:read . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
tzset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Procedure and Macro Index 294
U
unbreak . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
unbreakf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
union. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
unmake-method! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
unstack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
untrace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
untracef . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
untrack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
unzip1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
unzip2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
unzip3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
unzip4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
unzip5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
uri->tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
uri:decode-query . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
uri:make-path . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
uri:path->keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
uri:split-fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
uric:decode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
uric:encode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
url->color-dictionary . . . . . . . . . . . . . . . . . . . . . . 148
user-email-address. . . . . . . . . . . . . . . . . . . . . . . . . . 265
user-vicinity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
V
values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
vector->array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
vector-fill! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
vet-slib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
vicinity:suffix? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
vrml . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
vrml-append . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
vrml-to-file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
W
wavelength->chromaticity . . . . . . . . . . . . . . . . . . . 143
wavelength->XYZ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
whole-page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120, 123
with-input-from-file . . . . . . . . . . . . . . . . . . . . . . . 248
with-load-pathname . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
with-output-to-file . . . . . . . . . . . . . . . . . . . . . . . . 248
within-database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
world:info . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
wrap-command-interface . . . . . . . . . . . . . . . . . . . . . 170
write-base on base-table . . . . . . . . . . . . . . . . . . . 181
write-byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
write-bytes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
write-database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
write-database on relational-database . . . . 187
write-line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
wt-tree/add . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
wt-tree/add! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
wt-tree/delete . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
wt-tree/delete! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
wt-tree/delete-min. . . . . . . . . . . . . . . . . . . . . . . . . . 195
wt-tree/delete-min! . . . . . . . . . . . . . . . . . . . . . . . . 195
wt-tree/difference. . . . . . . . . . . . . . . . . . . . . . . . . . 192
wt-tree/empty? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
wt-tree/fold . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
wt-tree/for-each . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
wt-tree/index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
wt-tree/index-datum . . . . . . . . . . . . . . . . . . . . . . . . 194
wt-tree/index-pair. . . . . . . . . . . . . . . . . . . . . . . . . . 194
wt-tree/intersection . . . . . . . . . . . . . . . . . . . . . . . 192
wt-tree/lookup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
wt-tree/member? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
wt-tree/min . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
wt-tree/min-datum . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
wt-tree/min-pair . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
wt-tree/rank . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
wt-tree/set-equal?. . . . . . . . . . . . . . . . . . . . . . . . . . 192
wt-tree/size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
wt-tree/split< . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
wt-tree/split> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
wt-tree/subset? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
wt-tree/union . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
wt-tree/union-merge . . . . . . . . . . . . . . . . . . . . . . . . 193
X
x-axis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
xcons. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
xrgb->color . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
xRGB->CIEXYZ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
xRGB->sRGB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
xyY->XYZ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
xyY:normalize-colors . . . . . . . . . . . . . . . . . . . . . . . 144
XYZ->chromaticity . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
XYZ->xyY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Y
y-axis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
Z
zenith-xyy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
zip . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
295
Variable Index
*
*argv*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
*base-table-implementations* . . . . . . . . . . . . . . 180
*catalog* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
*http:byline* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
*operating-system* . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
*optarg* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
*optind* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
*qp-width* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
*random-state* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
*ruleset* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
*syn-defs* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
*syn-ignore-whitespace* . . . . . . . . . . . . . . . . . . . . . 41
*timezone* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
A
atm-hec-polynomial. . . . . . . . . . . . . . . . . . . . . . . . . . 116
B
bottomedge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
C
char-code-limit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
charplot:dimensions . . . . . . . . . . . . . . . . . . . . . . . . 118
CIEXYZ:A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
CIEXYZ:B . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
CIEXYZ:C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
CIEXYZ:D50 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
CIEXYZ:D65 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
CIEXYZ:E . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
crc-08-polynomial . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
crc-10-polynomial . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
crc-12-polynomial . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
crc-16-polynomial . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
crc-32-polynomial . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
crc-ccitt-polynomial . . . . . . . . . . . . . . . . . . . . . . . 115
D
D50 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
D65 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
daylight? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
debug:max-count . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
distribute* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
distribute/ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
dowcrc-polynomial . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
G
graph:dimensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
graphrect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
L
leftedge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
M
most-positive-fixnum . . . . . . . . . . . . . . . . . . . . . . . . 12
N
nil . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
number-wt-type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
P
plotrect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
prime:prngs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
prime:trials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
R
rightedge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
S
slib:form-feed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
slib:tab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
stderr. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
stdin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
stdout. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
string-wt-type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
T
t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
tok:decimal-digits . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
tok:lower-case . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
tok:upper-case . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
tok:whitespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
topedge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
tzname. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
U
usb-token-polynomial . . . . . . . . . . . . . . . . . . . . . . . 116
296
Concept and Feature Index
=
=> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
A
aggregate. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3, 9
alarm. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
alarm-interrupt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
alist. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
alist-table . . . . . . . . . . . . . . . . . . . . . . . . 179, 180, 186
and-let* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
ange-ftp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
appearance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
array. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
array-for-each . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
association function . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
Attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
attribute-value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
AttValue. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Auto-sharing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
B
balanced binary trees . . . . . . . . . . . . . . . . . . . . . . . . . 188
base . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
base-table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
batch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66, 68
bignum. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
binary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
binary trees. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
binary trees, as discrete maps . . . . . . . . . . . . . . . . . 189
binary trees, as sets . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
binding power . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
break. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
byte-number . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
C
calendar time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96, 98
Calendar-Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
caltime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
canonical . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
careful . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
catalog. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Catalog File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
certiļ¬cate. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
cgi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
chapter-order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
charplot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
Chroma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
cie1931 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
cie1964 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
ciexyz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
CIEXYZ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
cksum-string . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
coerce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
collect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
color-database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
color-names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
command line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
commentfix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
common-lisp-time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
common-list-functions . . . . . . . . . . . . . . . . . 211, 221
commutative-ring . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
compiled . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
compiling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
complex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Coordinated Universal Time . . . . . . . . . . . . . . . . . . 98
copyright . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
crc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115, 117
cvs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
D
database-commands . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
databases . . . . . . . . . . . . . . . . . . . . . . . 68, 162, 171, 174
daylight . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
db->html . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
debug. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
define-record-type . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
defmacro. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
defmacroexpand . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18, 95
delim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
dequeues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
determinant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
dft, Fourier-transform . . . . . . . . . . . . . . . . . . . . . 113
diff . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
Discrete Fourier Transform. . . . . . . . . . . . . . . . . . . . 114
discrete maps, using binary trees . . . . . . . . . . . . . . 189
DrScheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
dynamic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
dynamic-wind . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
E
e-sRGB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
ELK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
emacs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
Encapsulated-PostScript . . . . . . . . . . . . . . . . . . . . . . 120
escaped . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Euclidean Domain . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
EUC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
eval . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
exchanger. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Concept and Feature Index 297
F
factor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
feature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1, 2, 275
File Transfer Protocol . . . . . . . . . . . . . . . . . . . . . . . . . . 79
ļ¬le-lock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
filename. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64, 68
fluid-let . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
fold . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
format. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
G
Gambit-C 3.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
gamut . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Gauche-0.9 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
generic-write . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
getenv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
getit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
getopt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58, 59, 174
getopt-parameters . . . . . . . . . . . . . . . . . . . . . . . 63, 174
glob . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Gray code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
guarded-cond-clause. . . . . . . . . . . . . . . . . . . . . . . . . . 34
Guile. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
H
hash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
hash-table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
Hilbert . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
Hilbert Space-Filling Curve . . . . . . . . . . . . . . . . . . . 237
hilbert-fill . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
homecat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
HOME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4, 11
html-for-each . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
html-form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
http . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Hue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
I
ICC Profile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
implcat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
indexed-sequential-access-method . . . . . . . . . . . . . 208
inexact . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
infix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Info. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
inmatchfix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
install . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
intrinsic feature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
ISAM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
iso-8601 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
J
Japanese . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
JFILTER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
JIS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
K
Kawa . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
L
L*a*b* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
L*C*h. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
L*u*v* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
lamination . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
Larceny . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
Left Denotation, led . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
let-values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Lightness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138, 139
line-i . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
list-processing library . . . . . . . . . . . . . . . . . . . . . . . . . 254
load-option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
logical . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
M
macro . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3, 19, 258
macro-by-example . . . . . . . . . . . . . . . . . . . . . . . . . . . 3, 19
macros-that-work. . . . . . . . . . . . . . . . . . . . . . . . . . . . 3, 20
manifest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
match . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
match-keys. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166, 183
matchfix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
matfile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
math-integer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
math-real . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
matlab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
metric-units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
minimize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
minimum ļ¬eld width (printf) . . . . . . . . . . . . . . . . . 54
MIT Scheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
mkimpcat.scm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
mklibcat.scm. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
modular . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
multiarg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
multiarg-apply . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
MzScheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
N
nary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
ncbi-dma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
new-catalog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
nofix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
null . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Null Denotation, nud . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Concept and Feature Index 298
O
object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215, 216, 218
object->string . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
oop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
option, run-time-loadable . . . . . . . . . . . . . . . . . . . . . 189
options ļ¬le. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
P
parameters. . . . . . . . . . . . . . . . . . . . . . . . . . . . 62, 68, 174
parse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
pbm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
pbm-raw. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
peano-fill . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
pgm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
pgm-raw . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
plain-text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
PLT Scheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
pnm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
portable bitmap graphics . . . . . . . . . . . . . . . . . . . . . 210
posix-time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
postfix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
ppm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
ppm-raw. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
pprint-file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
precedence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
precision (printf) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
prefix. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
prestfix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
pretty-print. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
PRE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
primes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
printf. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
priority-queue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
PRNG. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
program-arguments . . . . . . . . . . . . . . . . . . . . . . . 59, 262
Prolog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
promise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
PSD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
Q
qp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60, 258
query-string . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75, 76
queue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219, 220
R
r2rs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
r3rs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248, 273
r4rs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
r5rs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
random . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
random-inexact . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
range . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
rational . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
rationalize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
read-command. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
real . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
receive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
record . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
rectangle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
relational-database . . . . . . . . . . . . . . . . . . . . . . . . 162
relational-system. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
repl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31, 258
Resene . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
resene . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
rev2-procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
rev4-optional-procedures . . . . . . . . . . . . . . . . . . . 250
RGB709 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
ring, commutative . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
RNG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
root . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
run-time-loadable option . . . . . . . . . . . . . . . . . . . . . . 189
rwb-isam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
S
S7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
saturate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
scanf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
SCHELOG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
scheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Scheme Request For Implementation . . . . . . . . . . 253
Scheme48 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
schmooz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
SCM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
self-set. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
Sequence Comparison . . . . . . . . . . . . . . . . . . . . . . . . . 241
Server-based Naming Authority . . . . . . . . . . . . . . . . 78
session . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
sets, using binary trees . . . . . . . . . . . . . . . . . . . . . . . . 189
shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
sierpinski . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
SISC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
sitecat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
sky . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
slib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
slibcat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
solid. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
solid-modeling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
solids . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
Concept and Feature Index 299
soundex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Space-Filling. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
space-filling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
sparse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
Spectral Tristimulus Values . . . . . . . . . . . . . . . . . . . 141
spiļ¬€ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
srfi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
srfi-1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
srfi-11. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34, 254
srfi-2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34, 254
srfi-23 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
srfi-28 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
srfi-39. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34, 254
srfi-47 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
srfi-59 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
srfi-60 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103, 254
srfi-61. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34, 254
srfi-63 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
srfi-8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34, 254
srfi-9 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33, 254
srfi-94 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
srfi-95 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233, 254
srfi-96 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
SRFI-1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
sRGB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
stdio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
string-case . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
string-port . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
string-search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
subarray . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
sun . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
sunlight . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
symmetric . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
syntactic-closures . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3, 23
syntax tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
syntax-case . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3, 30, 31
system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
T
time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
time-zone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
top-level variable references . . . . . . . . . . . . . . . . . . . . . 9
top-refs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
topological-sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
trace. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
transact . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
transcript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
trees, balanced binary. . . . . . . . . . . . . . . . . . . . . . . . . 188
tristimulus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
tsort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234, 235
turbidity. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
TZ-string . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
U
Uniform Resource Identiļ¬ers . . . . . . . . . . . . . . . . . . . 78
Uniform Resource Locator . . . . . . . . . . . . . . . . . . . . . 80
Unique Factorization . . . . . . . . . . . . . . . . . . . . . . . . . . 156
unsafe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
uri . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
URI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75, 76, 79
usercat. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
UTC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
V
values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
variable references . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
vet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
VSCM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
W
wb-table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
WB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
weight-balanced binary trees . . . . . . . . . . . . . . . . . . 188
wget. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
white point . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
wild-card . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
with-file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
Word . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
wt-tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
X
xRGB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
xyY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Y
yasos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35