add env script
[bpt/guile.git] / module / slib / slib.info
1 This is slib.info, produced by makeinfo version 4.0 from slib.texi.
2
3 INFO-DIR-SECTION The Algorithmic Language Scheme
4 START-INFO-DIR-ENTRY
5 * SLIB: (slib). Scheme Library
6 END-INFO-DIR-ENTRY
7
8 This file documents SLIB, the portable Scheme library.
9
10 Copyright (C) 1993 Todd R. Eigenschink
11 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000 Aubrey
12 Jaffer
13
14 Permission is granted to make and distribute verbatim copies of this
15 manual provided the copyright notice and this permission notice are
16 preserved on all copies.
17
18 Permission is granted to copy and distribute modified versions of this
19 manual under the conditions for verbatim copying, provided that the
20 entire resulting derived work is distributed under the terms of a
21 permission notice identical to this one.
22
23 Permission is granted to copy and distribute translations of this
24 manual into another language, under the above conditions for modified
25 versions, except that this permission notice may be stated in a
26 translation approved by the author.
27
28 \1f
29 File: slib.info, Node: Top, Next: The Library System, Prev: (dir), Up: (dir)
30
31 "SLIB" is a portable library for the programming language "Scheme". It
32 provides a platform independent framework for using "packages" of
33 Scheme procedures and syntax. As distributed, SLIB contains useful
34 packages for all Scheme implementations. Its catalog can be
35 transparently extended to accomodate packages specific to a site,
36 implementation, user, or directory.
37
38 * Menu:
39
40 * The Library System:: How to use and customize.
41 * Scheme Syntax Extension Packages::
42 * Textual Conversion Packages::
43 * Mathematical Packages::
44 * Database Packages::
45 * Other Packages::
46 * About SLIB:: Install, etc.
47 * Index::
48
49 \1f
50 File: slib.info, Node: The Library System, Next: Scheme Syntax Extension Packages, Prev: Top, Up: Top
51
52 The Library System
53 ******************
54
55 * Menu:
56
57 * Feature:: SLIB names.
58 * Requesting Features::
59 * Library Catalogs::
60 * Catalog Compilation::
61 * Built-in Support::
62 * About this manual::
63
64 \1f
65 File: slib.info, Node: Feature, Next: Requesting Features, Prev: The Library System, Up: The Library System
66
67 Feature
68 =======
69
70 SLIB denotes "features" by symbols. SLIB maintains a list of features
71 supported by the Scheme "session". The set of features provided by a
72 session may change over time. Some features are properties of the
73 Scheme implementation being used. The following features detail what
74 sort of numbers are available from an implementation.
75
76 * 'inexact
77
78 * 'rational
79
80 * 'real
81
82 * 'complex
83
84 * 'bignum
85
86 Other features correspond to the presence of sets of Scheme procedures
87 or syntax (macros).
88
89 - Function: provided? feature
90 Returns `#t' if FEATURE is supported by the current Scheme session.
91
92 - Procedure: provide feature
93 Informs SLIB that FEATURE is supported. Henceforth `(provided?
94 FEATURE)' will return `#t'.
95
96 (provided? 'foo) => #f
97 (provide 'foo)
98 (provided? 'foo) => #t
99
100 \1f
101 File: slib.info, Node: Requesting Features, Next: Library Catalogs, Prev: Feature, Up: The Library System
102
103 Requesting Features
104 ===================
105
106 SLIB creates and maintains a "catalog" mapping features to locations of
107 files introducing procedures and syntax denoted by those features.
108
109 At the beginning of each section of this manual, there is a line like
110 `(require 'FEATURE)'. The Scheme files comprising SLIB are cataloged
111 so that these feature names map to the corresponding files.
112
113 SLIB provides a form, `require', which loads the files providing the
114 requested feature.
115
116 - Procedure: require feature
117 * If `(provided? FEATURE)' is true, then `require' just returns
118 an unspecified value.
119
120 * Otherwise, if FEATURE is found in the catalog, then the
121 corresponding files will be loaded and an unspecified value
122 returned.
123
124 Subsequently `(provided? FEATURE)' will return `#t'.
125
126 * Otherwise (FEATURE not found in the catalog), an error is
127 signaled.
128
129 The catalog can also be queried using `require:feature->path'.
130
131 - Function: require:feature->path feature
132 * If FEATURE is already provided, then returns `#t'.
133
134 * Otherwise, if FEATURE is in the catalog, the path or list of
135 paths associated with FEATURE is returned.
136
137 * Otherwise, returns `#f'.
138
139 \1f
140 File: slib.info, Node: Library Catalogs, Next: Catalog Compilation, Prev: Requesting Features, Up: The Library System
141
142 Library Catalogs
143 ================
144
145 At the start of a session no catalog is present, but is created with the
146 first catalog inquiry (such as `(require 'random)'). Several sources
147 of catalog information are combined to produce the catalog:
148
149 * standard SLIB packages.
150
151 * additional packages of interest to this site.
152
153 * packages specifically for the variety of Scheme which this session
154 is running.
155
156 * packages this user wants to always have available. This catalog
157 is the file `homecat' in the user's "HOME" directory.
158
159 * packages germane to working in this (current working) directory.
160 This catalog is the file `usercat' in the directory to which it
161 applies. One would typically `cd' to this directory before
162 starting the Scheme session.
163
164 Catalog files consist of one or more "association list"s. In the
165 circumstance where a feature symbol appears in more than one list, the
166 latter list's association is retrieved. Here are the supported formats
167 for elements of catalog lists:
168
169 `(FEATURE . <symbol>)'
170 Redirects to the feature named <symbol>.
171
172 `(FEATURE . "<path>")'
173 Loads file <path>.
174
175 `(FEATURE source "<path>")'
176 `slib:load's the Scheme source file <path>.
177
178 `(FEATURE compiled "<path>" ...)'
179 `slib:load-compiled's the files <path> ....
180
181 The various macro styles first `require' the named macro package, then
182 just load <path> or load-and-macro-expand <path> as appropriate for the
183 implementation.
184
185 `(FEATURE defmacro "<path>")'
186 `defmacro:load's the Scheme source file <path>.
187
188 `(FEATURE macro-by-example "<path>")'
189 `defmacro:load's the Scheme source file <path>.
190
191 `(FEATURE macro "<path>")'
192 `macro:load's the Scheme source file <path>.
193
194 `(FEATURE macros-that-work "<path>")'
195 `macro:load's the Scheme source file <path>.
196
197 `(FEATURE syntax-case "<path>")'
198 `macro:load's the Scheme source file <path>.
199
200 `(FEATURE syntactic-closures "<path>")'
201 `macro:load's the Scheme source file <path>.
202
203 Here is an example of a `usercat' catalog. A Program in this directory
204 can invoke the `run' feature with `(require 'run)'.
205
206 ;;; "usercat": SLIB catalog additions for SIMSYNCH. -*-scheme-*-
207
208 (
209 (simsynch . "../synch/simsynch.scm")
210 (run . "../synch/run.scm")
211 (schlep . "schlep.scm")
212 )
213
214 \1f
215 File: slib.info, Node: Catalog Compilation, Next: Built-in Support, Prev: Library Catalogs, Up: The Library System
216
217 Catalog Compilation
218 ===================
219
220 SLIB combines the catalog information which doesn't vary per user into
221 the file `slibcat' in the implementation-vicinity. Therefore `slibcat'
222 needs change only when new software is installed or compiled. Because
223 the actual pathnames of files can differ from installation to
224 installation, SLIB builds a separate catalog for each implementation it
225 is used with.
226
227 The definition of `*SLIB-VERSION*' in SLIB file `require.scm' is
228 checked against the catalog association of `*SLIB-VERSION*' to
229 ascertain when versions have changed. I recommend that the definition
230 of `*SLIB-VERSION*' be changed whenever the library is changed. If
231 multiple implementations of Scheme use SLIB, remember that recompiling
232 one `slibcat' will fix only that implementation's catalog.
233
234 The compilation scripts of Scheme implementations which work with SLIB
235 can automatically trigger catalog compilation by deleting `slibcat' or
236 by invoking a special form of `require':
237
238 - Procedure: require 'new-catalog
239 This will load `mklibcat', which compiles and writes a new
240 `slibcat'.
241
242 Another special form of `require' erases SLIB's catalog, forcing it to
243 be reloaded the next time the catalog is queried.
244
245 - Procedure: require #f
246 Removes SLIB's catalog information. This should be done before
247 saving an executable image so that, when restored, its catalog
248 will be loaded afresh.
249
250 Each file in the table below is descibed in terms of its file-system
251 independent "vicinity" (*note Vicinity::). The entries of a catalog in
252 the table override those of catalogs above it in the table.
253
254 `implementation-vicinity' `slibcat'
255 This file contains the associations for the packages comprising
256 SLIB, the `implcat' and the `sitecat's. The associations in the
257 other catalogs override those of the standard catalog.
258
259 `library-vicinity' `mklibcat.scm'
260 creates `slibcat'.
261
262 `library-vicinity' `sitecat'
263 This file contains the associations specific to an SLIB
264 installation.
265
266 `implementation-vicinity' `implcat'
267 This file contains the associations specific to an implementation
268 of Scheme. Different implementations of Scheme should have
269 different `implementation-vicinity'.
270
271 `implementation-vicinity' `mkimpcat.scm'
272 if present, creates `implcat'.
273
274 `implementation-vicinity' `sitecat'
275 This file contains the associations specific to a Scheme
276 implementation installation.
277
278 `home-vicinity' `homecat'
279 This file contains the associations specific to an SLIB user.
280
281 `user-vicinity' `usercat'
282 This file contains associations effecting only those sessions whose
283 "working directory" is `user-vicinity'.
284
285 \1f
286 File: slib.info, Node: Built-in Support, Next: About this manual, Prev: Catalog Compilation, Up: The Library System
287
288 Built-in Support
289 ================
290
291 The procedures described in these sections are supported by all
292 implementations as part of the `*.init' files or by `require.scm'.
293
294 * Menu:
295
296 * Require:: Module Management
297 * Vicinity:: Pathname Management
298 * Configuration:: Characteristics of Scheme Implementation
299 * Input/Output:: Things not provided by the Scheme specs.
300 * Legacy::
301 * System:: LOADing, EVALing, ERRORing, and EXITing
302
303 \1f
304 File: slib.info, Node: Require, Next: Vicinity, Prev: Built-in Support, Up: Built-in Support
305
306 Require
307 -------
308
309 - Variable: *features*
310 Is a list of symbols denoting features supported in this
311 implementation. *FEATURES* can grow as modules are `require'd.
312 *FEATURES* must be defined by all implementations (*note
313 Porting::).
314
315 Here are features which SLIB (`require.scm') adds to *FEATURES*
316 when appropriate.
317
318 * 'inexact
319
320 * 'rational
321
322 * 'real
323
324 * 'complex
325
326 * 'bignum
327
328 For each item, `(provided? 'FEATURE)' will return `#t' if that
329 feature is available, and `#f' if not.
330
331 - Variable: *modules*
332 Is a list of pathnames denoting files which have been loaded.
333
334 - Variable: *catalog*
335 Is an association list of features (symbols) and pathnames which
336 will supply those features. The pathname can be either a string
337 or a pair. If pathname is a pair then the first element should be
338 a macro feature symbol, `source', or `compiled'. The cdr of the
339 pathname should be either a string or a list.
340
341 In the following functions if the argument FEATURE is not a symbol it
342 is assumed to be a pathname.
343
344 - Function: provided? feature
345 Returns `#t' if FEATURE is a member of `*features*' or `*modules*'
346 or if FEATURE is supported by a file already loaded and `#f'
347 otherwise.
348
349 - Procedure: require feature
350 FEATURE is a symbol. If `(provided? FEATURE)' is true `require'
351 returns. Otherwise, if `(assq FEATURE *catalog*)' is not `#f',
352 the associated files will be loaded and `(provided? FEATURE)' will
353 henceforth return `#t'. An unspecified value is returned. If
354 FEATURE is not found in `*catalog*', then an error is signaled.
355
356 - Procedure: require pathname
357 PATHNAME is a string. If PATHNAME has not already been given as
358 an argument to `require', PATHNAME is loaded. An unspecified
359 value is returned.
360
361 - Procedure: provide feature
362 Assures that FEATURE is contained in `*features*' if FEATURE is a
363 symbol and `*modules*' otherwise.
364
365 - Function: require:feature->path feature
366 Returns `#t' if FEATURE is a member of `*features*' or `*modules*'
367 or if FEATURE is supported by a file already loaded. Returns a
368 path if one was found in `*catalog*' under the feature name, and
369 `#f' otherwise. The path can either be a string suitable as an
370 argument to load or a pair as described above for *catalog*.
371
372 \1f
373 File: slib.info, Node: Vicinity, Next: Configuration, Prev: Require, Up: Built-in Support
374
375 Vicinity
376 --------
377
378 A vicinity is a descriptor for a place in the file system. Vicinities
379 hide from the programmer the concepts of host, volume, directory, and
380 version. Vicinities express only the concept of a file environment
381 where a file name can be resolved to a file in a system independent
382 manner. Vicinities can even be used on "flat" file systems (which have
383 no directory structure) by having the vicinity express constraints on
384 the file name. On most systems a vicinity would be a string. All of
385 these procedures are file system dependent.
386
387 These procedures are provided by all implementations.
388
389 - Function: make-vicinity path
390 Returns the vicinity of PATH for use by `in-vicinity'.
391
392 - Function: program-vicinity
393 Returns the vicinity of the currently loading Scheme code. For an
394 interpreter this would be the directory containing source code.
395 For a compiled system (with multiple files) this would be the
396 directory where the object or executable files are. If no file is
397 currently loading it the result is undefined. *Warning:*
398 `program-vicinity' can return incorrect values if your program
399 escapes back into a `load'.
400
401 - Function: library-vicinity
402 Returns the vicinity of the shared Scheme library.
403
404 - Function: implementation-vicinity
405 Returns the vicinity of the underlying Scheme implementation. This
406 vicinity will likely contain startup code and messages and a
407 compiler.
408
409 - Function: user-vicinity
410 Returns the vicinity of the current directory of the user. On most
411 systems this is `""' (the empty string).
412
413 - Function: home-vicinity
414 Returns the vicinity of the user's "HOME" directory, the directory
415 which typically contains files which customize a computer
416 environment for a user. If scheme is running without a user (eg.
417 a daemon) or if this concept is meaningless for the platform, then
418 `home-vicinity' returns `#f'.
419
420 - Function: in-vicinity vicinity filename
421 Returns a filename suitable for use by `slib:load',
422 `slib:load-source', `slib:load-compiled', `open-input-file',
423 `open-output-file', etc. The returned filename is FILENAME in
424 VICINITY. `in-vicinity' should allow FILENAME to override
425 VICINITY when FILENAME is an absolute pathname and VICINITY is
426 equal to the value of `(user-vicinity)'. The behavior of
427 `in-vicinity' when FILENAME is absolute and VICINITY is not equal
428 to the value of `(user-vicinity)' is unspecified. For most systems
429 `in-vicinity' can be `string-append'.
430
431 - Function: sub-vicinity vicinity name
432 Returns the vicinity of VICINITY restricted to NAME. This is used
433 for large systems where names of files in subsystems could
434 conflict. On systems with directory structure `sub-vicinity' will
435 return a pathname of the subdirectory NAME of VICINITY.
436
437 \1f
438 File: slib.info, Node: Configuration, Next: Input/Output, Prev: Vicinity, Up: Built-in Support
439
440 Configuration
441 -------------
442
443 These constants and procedures describe characteristics of the Scheme
444 and underlying operating system. They are provided by all
445 implementations.
446
447 - Constant: char-code-limit
448 An integer 1 larger that the largest value which can be returned by
449 `char->integer'.
450
451 - Constant: most-positive-fixnum
452 In implementations which support integers of practically unlimited
453 size, MOST-POSITIVE-FIXNUM is a large exact integer within the
454 range of exact integers that may result from computing the length
455 of a list, vector, or string.
456
457 In implementations which do not support integers of practically
458 unlimited size, MOST-POSITIVE-FIXNUM is the largest exact integer
459 that may result from computing the length of a list, vector, or
460 string.
461
462 - Constant: slib:tab
463 The tab character.
464
465 - Constant: slib:form-feed
466 The form-feed character.
467
468 - Function: software-type
469 Returns a symbol denoting the generic operating system type. For
470 instance, `unix', `vms', `macos', `amiga', or `ms-dos'.
471
472 - Function: slib:report-version
473 Displays the versions of SLIB and the underlying Scheme
474 implementation and the name of the operating system. An
475 unspecified value is returned.
476
477 (slib:report-version) => slib "2d1" on scm "5b1" on unix |
478
479 - Function: slib:report
480 Displays the information of `(slib:report-version)' followed by
481 almost all the information neccessary for submitting a problem
482 report. An unspecified value is returned.
483
484 - Function: slib:report #t
485 provides a more verbose listing.
486
487 - Function: slib:report filename
488 Writes the report to file `filename'.
489
490 (slib:report)
491 =>
492 slib "2d1" on scm "5b1" on unix |
493 (implementation-vicinity) is "/home/jaffer/scm/"
494 (library-vicinity) is "/home/jaffer/slib/"
495 (scheme-file-suffix) is ".scm"
496 loaded *features* :
497 trace alist qp sort
498 common-list-functions macro values getopt
499 compiled
500 implementation *features* :
501 bignum complex real rational
502 inexact vicinity ed getenv
503 tmpnam abort transcript with-file
504 ieee-p1178 rev4-report rev4-optional-procedures hash
505 object-hash delay eval dynamic-wind
506 multiarg-apply multiarg/and- logical defmacro
507 string-port source current-time record
508 rev3-procedures rev2-procedures sun-dl string-case
509 array dump char-ready? full-continuation
510 system
511 implementation *catalog* :
512 (i/o-extensions compiled "/home/jaffer/scm/ioext.so")
513 ...
514
515 \1f
516 File: slib.info, Node: Input/Output, Next: Legacy, Prev: Configuration, Up: Built-in Support
517
518 Input/Output
519 ------------
520
521 These procedures are provided by all implementations.
522
523 - Procedure: file-exists? filename
524 Returns `#t' if the specified file exists. Otherwise, returns
525 `#f'. If the underlying implementation does not support this
526 feature then `#f' is always returned.
527
528 - Procedure: delete-file filename
529 Deletes the file specified by FILENAME. If FILENAME can not be
530 deleted, `#f' is returned. Otherwise, `#t' is returned.
531
532 - Procedure: tmpnam
533 Returns a pathname for a file which will likely not be used by any
534 other process. Successive calls to `(tmpnam)' will return
535 different pathnames.
536
537 - Procedure: current-error-port
538 Returns the current port to which diagnostic and error output is
539 directed.
540
541 - Procedure: force-output
542 - Procedure: force-output port
543 Forces any pending output on PORT to be delivered to the output
544 device and returns an unspecified value. The PORT argument may be
545 omitted, in which case it defaults to the value returned by
546 `(current-output-port)'.
547
548 - Procedure: output-port-width
549 - Procedure: output-port-width port
550 Returns the width of PORT, which defaults to
551 `(current-output-port)' if absent. If the width cannot be
552 determined 79 is returned.
553
554 - Procedure: output-port-height
555 - Procedure: output-port-height port
556 Returns the height of PORT, which defaults to
557 `(current-output-port)' if absent. If the height cannot be
558 determined 24 is returned.
559
560 \1f
561 File: slib.info, Node: Legacy, Next: System, Prev: Input/Output, Up: Built-in Support
562
563 Legacy
564 ------
565
566 These procedures are provided by all implementations.
567
568 - Function: identity x
569 IDENTITY returns its argument.
570
571 Example:
572 (identity 3)
573 => 3
574 (identity '(foo bar))
575 => (foo bar)
576 (map identity LST)
577 == (copy-list LST)
578
579 The following procedures were present in Scheme until R4RS (*note
580 Language changes: (r4rs)Notes.). They are provided by all SLIB
581 implementations.
582
583 - Constant: t
584 Derfined as `#t'.
585
586 - Constant: nil
587 Defined as `#f'.
588
589 - Function: last-pair l
590 Returns the last pair in the list L. Example:
591 (last-pair (cons 1 2))
592 => (1 . 2)
593 (last-pair '(1 2))
594 => (2)
595 == (cons 2 '())
596
597 \1f
598 File: slib.info, Node: System, Prev: Legacy, Up: Built-in Support
599
600 System
601 ------
602
603 These procedures are provided by all implementations.
604
605 - Procedure: slib:load-source name
606 Loads a file of Scheme source code from NAME with the default
607 filename extension used in SLIB. For instance if the filename
608 extension used in SLIB is `.scm' then `(slib:load-source "foo")'
609 will load from file `foo.scm'.
610
611 - Procedure: slib:load-compiled name
612 On implementations which support separtely loadable compiled
613 modules, loads a file of compiled code from NAME with the
614 implementation's filename extension for compiled code appended.
615
616 - Procedure: slib:load name
617 Loads a file of Scheme source or compiled code from NAME with the
618 appropriate suffixes appended. If both source and compiled code
619 are present with the appropriate names then the implementation
620 will load just one. It is up to the implementation to choose
621 which one will be loaded.
622
623 If an implementation does not support compiled code then
624 `slib:load' will be identical to `slib:load-source'.
625
626 - Procedure: slib:eval obj
627 `eval' returns the value of OBJ evaluated in the current top level
628 environment. *Note Eval:: provides a more general evaluation
629 facility.
630
631 - Procedure: slib:eval-load filename eval
632 FILENAME should be a string. If filename names an existing file,
633 the Scheme source code expressions and definitions are read from
634 the file and EVAL called with them sequentially. The
635 `slib:eval-load' procedure does not affect the values returned by
636 `current-input-port' and `current-output-port'.
637
638 - Procedure: slib:warn arg1 arg2 ...
639 Outputs a warning message containing the arguments.
640
641 - Procedure: slib:error arg1 arg2 ...
642 Outputs an error message containing the arguments, aborts
643 evaluation of the current form and responds in a system dependent
644 way to the error. Typical responses are to abort the program or
645 to enter a read-eval-print loop.
646
647 - Procedure: slib:exit n
648 - Procedure: slib:exit
649 Exits from the Scheme session returning status N to the system.
650 If N is omitted or `#t', a success status is returned to the
651 system (if possible). If N is `#f' a failure is returned to the
652 system (if possible). If N is an integer, then N is returned to
653 the system (if possible). If the Scheme session cannot exit an
654 unspecified value is returned from `slib:exit'.
655
656 \1f
657 File: slib.info, Node: About this manual, Prev: Built-in Support, Up: The Library System
658
659 About this manual
660 =================
661
662 * Entries that are labeled as Functions are called for their return
663 values. Entries that are labeled as Procedures are called
664 primarily for their side effects.
665
666 * Examples in this text were produced using the `scm' Scheme
667 implementation.
668
669 * At the beginning of each section, there is a line that looks like
670 `(require 'feature)'. Include this line in your code prior to
671 using the package.
672
673 \1f
674 File: slib.info, Node: Scheme Syntax Extension Packages, Next: Textual Conversion Packages, Prev: The Library System, Up: Top
675
676 Scheme Syntax Extension Packages
677 ********************************
678
679 * Menu:
680
681 * Defmacro:: Supported by all implementations
682
683 * R4RS Macros:: 'macro
684 * Macro by Example:: 'macro-by-example
685 * Macros That Work:: 'macros-that-work
686 * Syntactic Closures:: 'syntactic-closures
687 * Syntax-Case Macros:: 'syntax-case
688
689 Syntax extensions (macros) included with SLIB. Also *Note Structures::.
690
691 * Fluid-Let:: 'fluid-let
692 * Yasos:: 'yasos, 'oop, 'collect
693
694 \1f
695 File: slib.info, Node: Defmacro, Next: R4RS Macros, Prev: Scheme Syntax Extension Packages, Up: Scheme Syntax Extension Packages
696
697 Defmacro
698 ========
699
700 Defmacros are supported by all implementations.
701
702 - Function: gentemp
703 Returns a new (interned) symbol each time it is called. The symbol
704 names are implementation-dependent
705 (gentemp) => scm:G0
706 (gentemp) => scm:G1
707
708 - Function: defmacro:eval e
709 Returns the `slib:eval' of expanding all defmacros in scheme
710 expression E.
711
712 - Function: defmacro:load filename
713 FILENAME should be a string. If filename names an existing file,
714 the `defmacro:load' procedure reads Scheme source code expressions
715 and definitions from the file and evaluates them sequentially.
716 These source code expressions and definitions may contain defmacro
717 definitions. The `macro:load' procedure does not affect the values
718 returned by `current-input-port' and `current-output-port'.
719
720 - Function: defmacro? sym
721 Returns `#t' if SYM has been defined by `defmacro', `#f' otherwise.
722
723 - Function: macroexpand-1 form
724 - Function: macroexpand form
725 If FORM is a macro call, `macroexpand-1' will expand the macro
726 call once and return it. A FORM is considered to be a macro call
727 only if it is a cons whose `car' is a symbol for which a
728 `defmacro' has been defined.
729
730 `macroexpand' is similar to `macroexpand-1', but repeatedly
731 expands FORM until it is no longer a macro call.
732
733 - Macro: defmacro name lambda-list form ...
734 When encountered by `defmacro:eval', `defmacro:macroexpand*', or
735 `defmacro:load' defines a new macro which will henceforth be
736 expanded when encountered by `defmacro:eval',
737 `defmacro:macroexpand*', or `defmacro:load'.
738
739 Defmacroexpand
740 --------------
741
742 `(require 'defmacroexpand)'
743
744 - Function: defmacro:expand* e
745 Returns the result of expanding all defmacros in scheme expression
746 E.
747
748 \1f
749 File: slib.info, Node: R4RS Macros, Next: Macro by Example, Prev: Defmacro, Up: Scheme Syntax Extension Packages
750
751 R4RS Macros
752 ===========
753
754 `(require 'macro)' is the appropriate call if you want R4RS
755 high-level macros but don't care about the low level implementation. If
756 an SLIB R4RS macro implementation is already loaded it will be used.
757 Otherwise, one of the R4RS macros implemetations is loaded.
758
759 The SLIB R4RS macro implementations support the following uniform
760 interface:
761
762 - Function: macro:expand sexpression
763 Takes an R4RS expression, macro-expands it, and returns the result
764 of the macro expansion.
765
766 - Function: macro:eval sexpression
767 Takes an R4RS expression, macro-expands it, evals the result of the
768 macro expansion, and returns the result of the evaluation.
769
770 - Procedure: macro:load filename
771 FILENAME should be a string. If filename names an existing file,
772 the `macro:load' procedure reads Scheme source code expressions and
773 definitions from the file and evaluates them sequentially. These
774 source code expressions and definitions may contain macro
775 definitions. The `macro:load' procedure does not affect the
776 values returned by `current-input-port' and `current-output-port'.
777
778 \1f
779 File: slib.info, Node: Macro by Example, Next: Macros That Work, Prev: R4RS Macros, Up: Scheme Syntax Extension Packages
780
781 Macro by Example
782 ================
783
784 `(require 'macro-by-example)'
785
786 A vanilla implementation of `Macro by Example' (Eugene Kohlbecker,
787 R4RS) by Dorai Sitaram, (dorai@cs.rice.edu) using `defmacro'.
788
789 * generating hygienic global `define-syntax' Macro-by-Example macros
790 *cheaply*.
791
792 * can define macros which use `...'.
793
794 * needn't worry about a lexical variable in a macro definition
795 clashing with a variable from the macro use context
796
797 * don't suffer the overhead of redefining the repl if `defmacro'
798 natively supported (most implementations)
799
800
801 Caveat
802 ------
803
804 These macros are not referentially transparent (*note Macros:
805 (r4rs)Macros.). Lexically scoped macros (i.e., `let-syntax' and
806 `letrec-syntax') are not supported. In any case, the problem of
807 referential transparency gains poignancy only when `let-syntax' and
808 `letrec-syntax' are used. So you will not be courting large-scale
809 disaster unless you're using system-function names as local variables
810 with unintuitive bindings that the macro can't use. However, if you
811 must have the full `r4rs' macro functionality, look to the more
812 featureful (but also more expensive) versions of syntax-rules available
813 in slib *Note Macros That Work::, *Note Syntactic Closures::, and *Note
814 Syntax-Case Macros::.
815
816 - Macro: define-syntax keyword transformer-spec
817 The KEYWORD is an identifier, and the TRANSFORMER-SPEC should be
818 an instance of `syntax-rules'.
819
820 The top-level syntactic environment is extended by binding the
821 KEYWORD to the specified transformer.
822
823 (define-syntax let*
824 (syntax-rules ()
825 ((let* () body1 body2 ...)
826 (let () body1 body2 ...))
827 ((let* ((name1 val1) (name2 val2) ...)
828 body1 body2 ...)
829 (let ((name1 val1))
830 (let* (( name2 val2) ...)
831 body1 body2 ...)))))
832
833 - Macro: syntax-rules literals syntax-rule ...
834 LITERALS is a list of identifiers, and each SYNTAX-RULE should be
835 of the form
836
837 `(PATTERN TEMPLATE)'
838
839 where the PATTERN and TEMPLATE are as in the grammar above.
840
841 An instance of `syntax-rules' produces a new macro transformer by
842 specifying a sequence of hygienic rewrite rules. A use of a macro
843 whose keyword is associated with a transformer specified by
844 `syntax-rules' is matched against the patterns contained in the
845 SYNTAX-RULEs, beginning with the leftmost SYNTAX-RULE. When a
846 match is found, the macro use is trancribed hygienically according
847 to the template.
848
849 Each pattern begins with the keyword for the macro. This keyword
850 is not involved in the matching and is not considered a pattern
851 variable or literal identifier.
852
853 \1f
854 File: slib.info, Node: Macros That Work, Next: Syntactic Closures, Prev: Macro by Example, Up: Scheme Syntax Extension Packages
855
856 Macros That Work
857 ================
858
859 `(require 'macros-that-work)'
860
861 `Macros That Work' differs from the other R4RS macro implementations
862 in that it does not expand derived expression types to primitive
863 expression types.
864
865 - Function: macro:expand expression
866 - Function: macwork:expand expression
867 Takes an R4RS expression, macro-expands it, and returns the result
868 of the macro expansion.
869
870 - Function: macro:eval expression
871 - Function: macwork:eval expression
872 `macro:eval' returns the value of EXPRESSION in the current top
873 level environment. EXPRESSION can contain macro definitions.
874 Side effects of EXPRESSION will affect the top level environment.
875
876 - Procedure: macro:load filename
877 - Procedure: macwork:load filename
878 FILENAME should be a string. If filename names an existing file,
879 the `macro:load' procedure reads Scheme source code expressions and
880 definitions from the file and evaluates them sequentially. These
881 source code expressions and definitions may contain macro
882 definitions. The `macro:load' procedure does not affect the
883 values returned by `current-input-port' and `current-output-port'.
884
885 References:
886
887 The `Revised^4 Report on the Algorithmic Language Scheme' Clinger and
888 Rees [editors]. To appear in LISP Pointers. Also available as a
889 technical report from the University of Oregon, MIT AI Lab, and Cornell.
890
891 Macros That Work. Clinger and Rees. POPL '91.
892
893 The supported syntax differs from the R4RS in that vectors are allowed
894 as patterns and as templates and are not allowed as pattern or template
895 data.
896
897 transformer spec ==> (syntax-rules literals rules)
898
899 rules ==> ()
900 | (rule . rules)
901
902 rule ==> (pattern template)
903
904 pattern ==> pattern_var ; a symbol not in literals
905 | symbol ; a symbol in literals
906 | ()
907 | (pattern . pattern)
908 | (ellipsis_pattern)
909 | #(pattern*) ; extends R4RS
910 | #(pattern* ellipsis_pattern) ; extends R4RS
911 | pattern_datum
912
913 template ==> pattern_var
914 | symbol
915 | ()
916 | (template2 . template2)
917 | #(template*) ; extends R4RS
918 | pattern_datum
919
920 template2 ==> template
921 | ellipsis_template
922
923 pattern_datum ==> string ; no vector
924 | character
925 | boolean
926 | number
927
928 ellipsis_pattern ==> pattern ...
929
930 ellipsis_template ==> template ...
931
932 pattern_var ==> symbol ; not in literals
933
934 literals ==> ()
935 | (symbol . literals)
936
937 Definitions
938 -----------
939
940 Scope of an ellipsis
941 Within a pattern or template, the scope of an ellipsis (`...') is
942 the pattern or template that appears to its left.
943
944 Rank of a pattern variable
945 The rank of a pattern variable is the number of ellipses within
946 whose scope it appears in the pattern.
947
948 Rank of a subtemplate
949 The rank of a subtemplate is the number of ellipses within whose
950 scope it appears in the template.
951
952 Template rank of an occurrence of a pattern variable
953 The template rank of an occurrence of a pattern variable within a
954 template is the rank of that occurrence, viewed as a subtemplate.
955
956 Variables bound by a pattern
957 The variables bound by a pattern are the pattern variables that
958 appear within it.
959
960 Referenced variables of a subtemplate
961 The referenced variables of a subtemplate are the pattern
962 variables that appear within it.
963
964 Variables opened by an ellipsis template
965 The variables opened by an ellipsis template are the referenced
966 pattern variables whose rank is greater than the rank of the
967 ellipsis template.
968
969 Restrictions
970 ------------
971
972 No pattern variable appears more than once within a pattern.
973
974 For every occurrence of a pattern variable within a template, the
975 template rank of the occurrence must be greater than or equal to the
976 pattern variable's rank.
977
978 Every ellipsis template must open at least one variable.
979
980 For every ellipsis template, the variables opened by an ellipsis
981 template must all be bound to sequences of the same length.
982
983 The compiled form of a RULE is
984
985 rule ==> (pattern template inserted)
986
987 pattern ==> pattern_var
988 | symbol
989 | ()
990 | (pattern . pattern)
991 | ellipsis_pattern
992 | #(pattern)
993 | pattern_datum
994
995 template ==> pattern_var
996 | symbol
997 | ()
998 | (template2 . template2)
999 | #(pattern)
1000 | pattern_datum
1001
1002 template2 ==> template
1003 | ellipsis_template
1004
1005 pattern_datum ==> string
1006 | character
1007 | boolean
1008 | number
1009
1010 pattern_var ==> #(V symbol rank)
1011
1012 ellipsis_pattern ==> #(E pattern pattern_vars)
1013
1014 ellipsis_template ==> #(E template pattern_vars)
1015
1016 inserted ==> ()
1017 | (symbol . inserted)
1018
1019 pattern_vars ==> ()
1020 | (pattern_var . pattern_vars)
1021
1022 rank ==> exact non-negative integer
1023
1024 where V and E are unforgeable values.
1025
1026 The pattern variables associated with an ellipsis pattern are the
1027 variables bound by the pattern, and the pattern variables associated
1028 with an ellipsis template are the variables opened by the ellipsis
1029 template.
1030
1031 If the template contains a big chunk that contains no pattern
1032 variables or inserted identifiers, then the big chunk will be copied
1033 unnecessarily. That shouldn't matter very often.
1034
1035 \1f
1036 File: slib.info, Node: Syntactic Closures, Next: Syntax-Case Macros, Prev: Macros That Work, Up: Scheme Syntax Extension Packages
1037
1038 Syntactic Closures
1039 ==================
1040
1041 `(require 'syntactic-closures)'
1042
1043 - Function: macro:expand expression
1044 - Function: synclo:expand expression
1045 Returns scheme code with the macros and derived expression types of
1046 EXPRESSION expanded to primitive expression types.
1047
1048 - Function: macro:eval expression
1049 - Function: synclo:eval expression
1050 `macro:eval' returns the value of EXPRESSION in the current top
1051 level environment. EXPRESSION can contain macro definitions.
1052 Side effects of EXPRESSION will affect the top level environment.
1053
1054 - Procedure: macro:load filename
1055 - Procedure: synclo:load filename
1056 FILENAME should be a string. If filename names an existing file,
1057 the `macro:load' procedure reads Scheme source code expressions and
1058 definitions from the file and evaluates them sequentially. These
1059 source code expressions and definitions may contain macro
1060 definitions. The `macro:load' procedure does not affect the
1061 values returned by `current-input-port' and `current-output-port'.
1062
1063 Syntactic Closure Macro Facility
1064 --------------------------------
1065
1066 A Syntactic Closures Macro Facility
1067
1068 by Chris Hanson
1069
1070 9 November 1991
1071
1072 This document describes "syntactic closures", a low-level macro
1073 facility for the Scheme programming language. The facility is an
1074 alternative to the low-level macro facility described in the `Revised^4
1075 Report on Scheme.' This document is an addendum to that report.
1076
1077 The syntactic closures facility extends the BNF rule for TRANSFORMER
1078 SPEC to allow a new keyword that introduces a low-level macro
1079 transformer:
1080 TRANSFORMER SPEC := (transformer EXPRESSION)
1081
1082 Additionally, the following procedures are added:
1083 make-syntactic-closure
1084 capture-syntactic-environment
1085 identifier?
1086 identifier=?
1087
1088 The description of the facility is divided into three parts. The
1089 first part defines basic terminology. The second part describes how
1090 macro transformers are defined. The third part describes the use of
1091 "identifiers", which extend the syntactic closure mechanism to be
1092 compatible with `syntax-rules'.
1093
1094 Terminology
1095 ...........
1096
1097 This section defines the concepts and data types used by the syntactic
1098 closures facility.
1099
1100 * "Forms" are the syntactic entities out of which programs are
1101 recursively constructed. A form is any expression, any
1102 definition, any syntactic keyword, or any syntactic closure. The
1103 variable name that appears in a `set!' special form is also a
1104 form. Examples of forms:
1105 17
1106 #t
1107 car
1108 (+ x 4)
1109 (lambda (x) x)
1110 (define pi 3.14159)
1111 if
1112 define
1113
1114 * An "alias" is an alternate name for a given symbol. It can appear
1115 anywhere in a form that the symbol could be used, and when quoted
1116 it is replaced by the symbol; however, it does not satisfy the
1117 predicate `symbol?'. Macro transformers rarely distinguish
1118 symbols from aliases, referring to both as identifiers.
1119
1120 * A "syntactic" environment maps identifiers to their meanings.
1121 More precisely, it determines whether an identifier is a syntactic
1122 keyword or a variable. If it is a keyword, the meaning is an
1123 interpretation for the form in which that keyword appears. If it
1124 is a variable, the meaning identifies which binding of that
1125 variable is referenced. In short, syntactic environments contain
1126 all of the contextual information necessary for interpreting the
1127 meaning of a particular form.
1128
1129 * A "syntactic closure" consists of a form, a syntactic environment,
1130 and a list of identifiers. All identifiers in the form take their
1131 meaning from the syntactic environment, except those in the given
1132 list. The identifiers in the list are to have their meanings
1133 determined later. A syntactic closure may be used in any context
1134 in which its form could have been used. Since a syntactic closure
1135 is also a form, it may not be used in contexts where a form would
1136 be illegal. For example, a form may not appear as a clause in the
1137 cond special form. A syntactic closure appearing in a quoted
1138 structure is replaced by its form.
1139
1140
1141 Transformer Definition
1142 ......................
1143
1144 This section describes the `transformer' special form and the
1145 procedures `make-syntactic-closure' and `capture-syntactic-environment'.
1146
1147 - Syntax: transformer expression
1148 Syntax: It is an error if this syntax occurs except as a
1149 TRANSFORMER SPEC.
1150
1151 Semantics: The EXPRESSION is evaluated in the standard transformer
1152 environment to yield a macro transformer as described below. This
1153 macro transformer is bound to a macro keyword by the special form
1154 in which the `transformer' expression appears (for example,
1155 `let-syntax').
1156
1157 A "macro transformer" is a procedure that takes two arguments, a
1158 form and a syntactic environment, and returns a new form. The
1159 first argument, the "input form", is the form in which the macro
1160 keyword occurred. The second argument, the "usage environment",
1161 is the syntactic environment in which the input form occurred.
1162 The result of the transformer, the "output form", is automatically
1163 closed in the "transformer environment", which is the syntactic
1164 environment in which the `transformer' expression occurred.
1165
1166 For example, here is a definition of a push macro using
1167 `syntax-rules':
1168 (define-syntax push
1169 (syntax-rules ()
1170 ((push item list)
1171 (set! list (cons item list)))))
1172
1173 Here is an equivalent definition using `transformer':
1174 (define-syntax push
1175 (transformer
1176 (lambda (exp env)
1177 (let ((item
1178 (make-syntactic-closure env '() (cadr exp)))
1179 (list
1180 (make-syntactic-closure env '() (caddr exp))))
1181 `(set! ,list (cons ,item ,list))))))
1182
1183 In this example, the identifiers `set!' and `cons' are closed in
1184 the transformer environment, and thus will not be affected by the
1185 meanings of those identifiers in the usage environment `env'.
1186
1187 Some macros may be non-hygienic by design. For example, the
1188 following defines a loop macro that implicitly binds `exit' to an
1189 escape procedure. The binding of `exit' is intended to capture
1190 free references to `exit' in the body of the loop, so `exit' must
1191 be left free when the body is closed:
1192 (define-syntax loop
1193 (transformer
1194 (lambda (exp env)
1195 (let ((body (cdr exp)))
1196 `(call-with-current-continuation
1197 (lambda (exit)
1198 (let f ()
1199 ,@(map (lambda (exp)
1200 (make-syntactic-closure env '(exit)
1201 exp))
1202 body)
1203 (f))))))))
1204
1205 To assign meanings to the identifiers in a form, use
1206 `make-syntactic-closure' to close the form in a syntactic
1207 environment.
1208
1209 - Function: make-syntactic-closure environment free-names form
1210 ENVIRONMENT must be a syntactic environment, FREE-NAMES must be a
1211 list of identifiers, and FORM must be a form.
1212 `make-syntactic-closure' constructs and returns a syntactic closure
1213 of FORM in ENVIRONMENT, which can be used anywhere that FORM could
1214 have been used. All the identifiers used in FORM, except those
1215 explicitly excepted by FREE-NAMES, obtain their meanings from
1216 ENVIRONMENT.
1217
1218 Here is an example where FREE-NAMES is something other than the
1219 empty list. It is instructive to compare the use of FREE-NAMES in
1220 this example with its use in the `loop' example above: the examples
1221 are similar except for the source of the identifier being left
1222 free.
1223 (define-syntax let1
1224 (transformer
1225 (lambda (exp env)
1226 (let ((id (cadr exp))
1227 (init (caddr exp))
1228 (exp (cadddr exp)))
1229 `((lambda (,id)
1230 ,(make-syntactic-closure env (list id) exp))
1231 ,(make-syntactic-closure env '() init))))))
1232
1233 `let1' is a simplified version of `let' that only binds a single
1234 identifier, and whose body consists of a single expression. When
1235 the body expression is syntactically closed in its original
1236 syntactic environment, the identifier that is to be bound by
1237 `let1' must be left free, so that it can be properly captured by
1238 the `lambda' in the output form.
1239
1240 To obtain a syntactic environment other than the usage
1241 environment, use `capture-syntactic-environment'.
1242
1243 - Function: capture-syntactic-environment procedure
1244 `capture-syntactic-environment' returns a form that will, when
1245 transformed, call PROCEDURE on the current syntactic environment.
1246 PROCEDURE should compute and return a new form to be transformed,
1247 in that same syntactic environment, in place of the form.
1248
1249 An example will make this clear. Suppose we wanted to define a
1250 simple `loop-until' keyword equivalent to
1251 (define-syntax loop-until
1252 (syntax-rules ()
1253 ((loop-until id init test return step)
1254 (letrec ((loop
1255 (lambda (id)
1256 (if test return (loop step)))))
1257 (loop init)))))
1258
1259 The following attempt at defining `loop-until' has a subtle bug:
1260 (define-syntax loop-until
1261 (transformer
1262 (lambda (exp env)
1263 (let ((id (cadr exp))
1264 (init (caddr exp))
1265 (test (cadddr exp))
1266 (return (cadddr (cdr exp)))
1267 (step (cadddr (cddr exp)))
1268 (close
1269 (lambda (exp free)
1270 (make-syntactic-closure env free exp))))
1271 `(letrec ((loop
1272 (lambda (,id)
1273 (if ,(close test (list id))
1274 ,(close return (list id))
1275 (loop ,(close step (list id)))))))
1276 (loop ,(close init '())))))))
1277
1278 This definition appears to take all of the proper precautions to
1279 prevent unintended captures. It carefully closes the
1280 subexpressions in their original syntactic environment and it
1281 leaves the `id' identifier free in the `test', `return', and
1282 `step' expressions, so that it will be captured by the binding
1283 introduced by the `lambda' expression. Unfortunately it uses the
1284 identifiers `if' and `loop' within that `lambda' expression, so if
1285 the user of `loop-until' just happens to use, say, `if' for the
1286 identifier, it will be inadvertently captured.
1287
1288 The syntactic environment that `if' and `loop' want to be exposed
1289 to is the one just outside the `lambda' expression: before the
1290 user's identifier is added to the syntactic environment, but after
1291 the identifier loop has been added.
1292 `capture-syntactic-environment' captures exactly that environment
1293 as follows:
1294 (define-syntax loop-until
1295 (transformer
1296 (lambda (exp env)
1297 (let ((id (cadr exp))
1298 (init (caddr exp))
1299 (test (cadddr exp))
1300 (return (cadddr (cdr exp)))
1301 (step (cadddr (cddr exp)))
1302 (close
1303 (lambda (exp free)
1304 (make-syntactic-closure env free exp))))
1305 `(letrec ((loop
1306 ,(capture-syntactic-environment
1307 (lambda (env)
1308 `(lambda (,id)
1309 (,(make-syntactic-closure env '() `if)
1310 ,(close test (list id))
1311 ,(close return (list id))
1312 (,(make-syntactic-closure env '()
1313 `loop)
1314 ,(close step (list id)))))))))
1315 (loop ,(close init '())))))))
1316
1317 In this case, having captured the desired syntactic environment,
1318 it is convenient to construct syntactic closures of the
1319 identifiers `if' and the `loop' and use them in the body of the
1320 `lambda'.
1321
1322 A common use of `capture-syntactic-environment' is to get the
1323 transformer environment of a macro transformer:
1324 (transformer
1325 (lambda (exp env)
1326 (capture-syntactic-environment
1327 (lambda (transformer-env)
1328 ...))))
1329
1330 Identifiers
1331 ...........
1332
1333 This section describes the procedures that create and manipulate
1334 identifiers. Previous syntactic closure proposals did not have an
1335 identifier data type - they just used symbols. The identifier data
1336 type extends the syntactic closures facility to be compatible with the
1337 high-level `syntax-rules' facility.
1338
1339 As discussed earlier, an identifier is either a symbol or an "alias".
1340 An alias is implemented as a syntactic closure whose "form" is an
1341 identifier:
1342 (make-syntactic-closure env '() 'a)
1343 => an "alias"
1344
1345 Aliases are implemented as syntactic closures because they behave just
1346 like syntactic closures most of the time. The difference is that an
1347 alias may be bound to a new value (for example by `lambda' or
1348 `let-syntax'); other syntactic closures may not be used this way. If
1349 an alias is bound, then within the scope of that binding it is looked
1350 up in the syntactic environment just like any other identifier.
1351
1352 Aliases are used in the implementation of the high-level facility
1353 `syntax-rules'. A macro transformer created by `syntax-rules' uses a
1354 template to generate its output form, substituting subforms of the
1355 input form into the template. In a syntactic closures implementation,
1356 all of the symbols in the template are replaced by aliases closed in
1357 the transformer environment, while the output form itself is closed in
1358 the usage environment. This guarantees that the macro transformation
1359 is hygienic, without requiring the transformer to know the syntactic
1360 roles of the substituted input subforms.
1361
1362 - Function: identifier? object
1363 Returns `#t' if OBJECT is an identifier, otherwise returns `#f'.
1364 Examples:
1365 (identifier? 'a)
1366 => #t
1367 (identifier? (make-syntactic-closure env '() 'a))
1368 => #t
1369 (identifier? "a")
1370 => #f
1371 (identifier? #\a)
1372 => #f
1373 (identifier? 97)
1374 => #f
1375 (identifier? #f)
1376 => #f
1377 (identifier? '(a))
1378 => #f
1379 (identifier? '#(a))
1380 => #f
1381
1382 The predicate `eq?' is used to determine if two identifers are
1383 "the same". Thus `eq?' can be used to compare identifiers exactly
1384 as it would be used to compare symbols. Often, though, it is
1385 useful to know whether two identifiers "mean the same thing". For
1386 example, the `cond' macro uses the symbol `else' to identify the
1387 final clause in the conditional. A macro transformer for `cond'
1388 cannot just look for the symbol `else', because the `cond' form
1389 might be the output of another macro transformer that replaced the
1390 symbol `else' with an alias. Instead the transformer must look
1391 for an identifier that "means the same thing" in the usage
1392 environment as the symbol `else' means in the transformer
1393 environment.
1394
1395 - Function: identifier=? environment1 identifier1 environment2
1396 identifier2
1397 ENVIRONMENT1 and ENVIRONMENT2 must be syntactic environments, and
1398 IDENTIFIER1 and IDENTIFIER2 must be identifiers. `identifier=?'
1399 returns `#t' if the meaning of IDENTIFIER1 in ENVIRONMENT1 is the
1400 same as that of IDENTIFIER2 in ENVIRONMENT2, otherwise it returns
1401 `#f'. Examples:
1402
1403 (let-syntax
1404 ((foo
1405 (transformer
1406 (lambda (form env)
1407 (capture-syntactic-environment
1408 (lambda (transformer-env)
1409 (identifier=? transformer-env 'x env 'x)))))))
1410 (list (foo)
1411 (let ((x 3))
1412 (foo))))
1413 => (#t #f)
1414
1415 (let-syntax ((bar foo))
1416 (let-syntax
1417 ((foo
1418 (transformer
1419 (lambda (form env)
1420 (capture-syntactic-environment
1421 (lambda (transformer-env)
1422 (identifier=? transformer-env 'foo
1423 env (cadr form))))))))
1424 (list (foo foo)
1425 (foobar))))
1426 => (#f #t)
1427
1428 Acknowledgements
1429 ................
1430
1431 The syntactic closures facility was invented by Alan Bawden and
1432 Jonathan Rees. The use of aliases to implement `syntax-rules' was
1433 invented by Alan Bawden (who prefers to call them "synthetic names").
1434 Much of this proposal is derived from an earlier proposal by Alan
1435 Bawden.
1436
1437 \1f
1438 File: slib.info, Node: Syntax-Case Macros, Next: Fluid-Let, Prev: Syntactic Closures, Up: Scheme Syntax Extension Packages
1439
1440 Syntax-Case Macros
1441 ==================
1442
1443 `(require 'syntax-case)'
1444
1445 - Function: macro:expand expression
1446 - Function: syncase:expand expression
1447 Returns scheme code with the macros and derived expression types of
1448 EXPRESSION expanded to primitive expression types.
1449
1450 - Function: macro:eval expression
1451 - Function: syncase:eval expression
1452 `macro:eval' returns the value of EXPRESSION in the current top
1453 level environment. EXPRESSION can contain macro definitions.
1454 Side effects of EXPRESSION will affect the top level environment.
1455
1456 - Procedure: macro:load filename
1457 - Procedure: syncase:load filename
1458 FILENAME should be a string. If filename names an existing file,
1459 the `macro:load' procedure reads Scheme source code expressions and
1460 definitions from the file and evaluates them sequentially. These
1461 source code expressions and definitions may contain macro
1462 definitions. The `macro:load' procedure does not affect the
1463 values returned by `current-input-port' and `current-output-port'.
1464
1465 This is version 2.1 of `syntax-case', the low-level macro facility
1466 proposed and implemented by Robert Hieb and R. Kent Dybvig.
1467
1468 This version is further adapted by Harald Hanche-Olsen
1469 <hanche@imf.unit.no> to make it compatible with, and easily usable
1470 with, SLIB. Mainly, these adaptations consisted of:
1471
1472 * Removing white space from `expand.pp' to save space in the
1473 distribution. This file is not meant for human readers anyway...
1474
1475 * Removed a couple of Chez scheme dependencies.
1476
1477 * Renamed global variables used to minimize the possibility of name
1478 conflicts.
1479
1480 * Adding an SLIB-specific initialization file.
1481
1482 * Removing a couple extra files, most notably the documentation (but
1483 see below).
1484
1485 If you wish, you can see exactly what changes were done by reading the
1486 shell script in the file `syncase.sh'.
1487
1488 The two PostScript files were omitted in order to not burden the SLIB
1489 distribution with them. If you do intend to use `syntax-case',
1490 however, you should get these files and print them out on a PostScript
1491 printer. They are available with the original `syntax-case'
1492 distribution by anonymous FTP in
1493 `cs.indiana.edu:/pub/scheme/syntax-case'.
1494
1495 In order to use syntax-case from an interactive top level, execute:
1496 (require 'syntax-case)
1497 (require 'repl)
1498 (repl:top-level macro:eval)
1499 See the section Repl (*note Repl::) for more information.
1500
1501 To check operation of syntax-case get
1502 `cs.indiana.edu:/pub/scheme/syntax-case', and type
1503 (require 'syntax-case)
1504 (syncase:sanity-check)
1505
1506 Beware that `syntax-case' takes a long time to load - about 20s on a
1507 SPARCstation SLC (with SCM) and about 90s on a Macintosh SE/30 (with
1508 Gambit).
1509
1510 Notes
1511 -----
1512
1513 All R4RS syntactic forms are defined, including `delay'. Along with
1514 `delay' are simple definitions for `make-promise' (into which `delay'
1515 expressions expand) and `force'.
1516
1517 `syntax-rules' and `with-syntax' (described in `TR356') are defined.
1518
1519 `syntax-case' is actually defined as a macro that expands into calls
1520 to the procedure `syntax-dispatch' and the core form `syntax-lambda';
1521 do not redefine these names.
1522
1523 Several other top-level bindings not documented in TR356 are created:
1524 * the "hooks" in `hooks.ss'
1525
1526 * the `build-' procedures in `output.ss'
1527
1528 * `expand-syntax' (the expander)
1529
1530 The syntax of define has been extended to allow `(define ID)', which
1531 assigns ID to some unspecified value.
1532
1533 We have attempted to maintain R4RS compatibility where possible. The
1534 incompatibilities should be confined to `hooks.ss'. Please let us know
1535 if there is some incompatibility that is not flagged as such.
1536
1537 Send bug reports, comments, suggestions, and questions to Kent Dybvig
1538 (dyb@iuvax.cs.indiana.edu).
1539
1540 Note from maintainer
1541 --------------------
1542
1543 Included with the `syntax-case' files was `structure.scm' which
1544 defines a macro `define-structure'. There is no documentation for this
1545 macro and it is not used by any code in SLIB.
1546
1547 \1f
1548 File: slib.info, Node: Fluid-Let, Next: Yasos, Prev: Syntax-Case Macros, Up: Scheme Syntax Extension Packages
1549
1550 Fluid-Let
1551 =========
1552
1553 `(require 'fluid-let)'
1554
1555 - Syntax: fluid-let `(BINDINGS ...)' FORMS...
1556
1557 (fluid-let ((VARIABLE INIT) ...)
1558 EXPRESSION EXPRESSION ...)
1559
1560 The INITs are evaluated in the current environment (in some
1561 unspecified order), the current values of the VARIABLEs are saved, the
1562 results are assigned to the VARIABLEs, the EXPRESSIONs are evaluated
1563 sequentially in the current environment, the VARIABLEs are restored to
1564 their original values, and the value of the last EXPRESSION is returned.
1565
1566 The syntax of this special form is similar to that of `let', but
1567 `fluid-let' temporarily rebinds existing VARIABLEs. Unlike `let',
1568 `fluid-let' creates no new bindings; instead it _assigns_ the values of
1569 each INIT to the binding (determined by the rules of lexical scoping)
1570 of its corresponding VARIABLE.
1571
1572 \1f
1573 File: slib.info, Node: Yasos, Prev: Fluid-Let, Up: Scheme Syntax Extension Packages
1574
1575 Yasos
1576 =====
1577
1578 `(require 'oop)' or `(require 'yasos)'
1579
1580 `Yet Another Scheme Object System' is a simple object system for
1581 Scheme based on the paper by Norman Adams and Jonathan Rees: `Object
1582 Oriented Programming in Scheme', Proceedings of the 1988 ACM Conference
1583 on LISP and Functional Programming, July 1988 [ACM #552880].
1584
1585 Another reference is:
1586
1587 Ken Dickey. Scheming with Objects `AI Expert' Volume 7, Number 10
1588 (October 1992), pp. 24-33.
1589
1590 * Menu:
1591
1592 * Yasos terms:: Definitions and disclaimer.
1593 * Yasos interface:: The Yasos macros and procedures.
1594 * Setters:: Dylan-like setters in Yasos.
1595 * Yasos examples:: Usage of Yasos and setters.
1596
1597 \1f
1598 File: slib.info, Node: Yasos terms, Next: Yasos interface, Prev: Yasos, Up: Yasos
1599
1600 Terms
1601 -----
1602
1603 "Object"
1604 Any Scheme data object.
1605
1606 "Instance"
1607 An instance of the OO system; an "object".
1608
1609 "Operation"
1610 A METHOD.
1611
1612 _Notes:_
1613 The object system supports multiple inheritance. An instance can
1614 inherit from 0 or more ancestors. In the case of multiple
1615 inherited operations with the same identity, the operation used is
1616 that from the first ancestor which contains it (in the ancestor
1617 `let'). An operation may be applied to any Scheme data
1618 object--not just instances. As code which creates instances is
1619 just code, there are no "classes" and no meta-ANYTHING. Method
1620 dispatch is by a procedure call a la CLOS rather than by `send'
1621 syntax a la Smalltalk.
1622
1623 _Disclaimer:_
1624 There are a number of optimizations which can be made. This
1625 implementation is expository (although performance should be quite
1626 reasonable). See the L&FP paper for some suggestions.
1627
1628 \1f
1629 File: slib.info, Node: Yasos interface, Next: Setters, Prev: Yasos terms, Up: Yasos
1630
1631 Interface
1632 ---------
1633
1634 - Syntax: define-operation `('opname self arg ...`)' DEFAULT-BODY
1635 Defines a default behavior for data objects which don't handle the
1636 operation OPNAME. The default behavior (for an empty
1637 DEFAULT-BODY) is to generate an error.
1638
1639 - Syntax: define-predicate opname?
1640 Defines a predicate OPNAME?, usually used for determining the
1641 "type" of an object, such that `(OPNAME? OBJECT)' returns `#t' if
1642 OBJECT has an operation OPNAME? and `#f' otherwise.
1643
1644 - Syntax: object `((NAME SELF ARG ...) BODY)' ...
1645 Returns an object (an instance of the object system) with
1646 operations. Invoking `(NAME OBJECT ARG ...' executes the BODY of
1647 the OBJECT with SELF bound to OBJECT and with argument(s) ARG....
1648
1649 - Syntax: object-with-ancestors `(('ancestor1 init1`)' ...`)'
1650 operation ...
1651 A `let'-like form of `object' for multiple inheritance. It
1652 returns an object inheriting the behaviour of ANCESTOR1 etc. An
1653 operation will be invoked in an ancestor if the object itself does
1654 not provide such a method. In the case of multiple inherited
1655 operations with the same identity, the operation used is the one
1656 found in the first ancestor in the ancestor list.
1657
1658 - Syntax: operate-as component operation self arg ...
1659 Used in an operation definition (of SELF) to invoke the OPERATION
1660 in an ancestor COMPONENT but maintain the object's identity. Also
1661 known as "send-to-super".
1662
1663 - Procedure: print obj port
1664 A default `print' operation is provided which is just `(format
1665 PORT OBJ)' (*note Format::) for non-instances and prints OBJ
1666 preceded by `#<INSTANCE>' for instances.
1667
1668 - Function: size obj
1669 The default method returns the number of elements in OBJ if it is
1670 a vector, string or list, `2' for a pair, `1' for a character and
1671 by default id an error otherwise. Objects such as collections
1672 (*note Collections::) may override the default in an obvious way.
1673
1674 \1f
1675 File: slib.info, Node: Setters, Next: Yasos examples, Prev: Yasos interface, Up: Yasos
1676
1677 Setters
1678 -------
1679
1680 "Setters" implement "generalized locations" for objects associated
1681 with some sort of mutable state. A "getter" operation retrieves a
1682 value from a generalized location and the corresponding setter
1683 operation stores a value into the location. Only the getter is named -
1684 the setter is specified by a procedure call as below. (Dylan uses
1685 special syntax.) Typically, but not necessarily, getters are access
1686 operations to extract values from Yasos objects (*note Yasos::).
1687 Several setters are predefined, corresponding to getters `car', `cdr',
1688 `string-ref' and `vector-ref' e.g., `(setter car)' is equivalent to
1689 `set-car!'.
1690
1691 This implementation of setters is similar to that in Dylan(TM)
1692 (`Dylan: An object-oriented dynamic language', Apple Computer Eastern
1693 Research and Technology). Common LISP provides similar facilities
1694 through `setf'.
1695
1696 - Function: setter getter
1697 Returns the setter for the procedure GETTER. E.g., since
1698 `string-ref' is the getter corresponding to a setter which is
1699 actually `string-set!':
1700 (define foo "foo")
1701 ((setter string-ref) foo 0 #\F) ; set element 0 of foo
1702 foo => "Foo"
1703
1704 - Syntax: set place new-value
1705 If PLACE is a variable name, `set' is equivalent to `set!'.
1706 Otherwise, PLACE must have the form of a procedure call, where the
1707 procedure name refers to a getter and the call indicates an
1708 accessible generalized location, i.e., the call would return a
1709 value. The return value of `set' is usually unspecified unless
1710 used with a setter whose definition guarantees to return a useful
1711 value.
1712 (set (string-ref foo 2) #\O) ; generalized location with getter
1713 foo => "FoO"
1714 (set foo "foo") ; like set!
1715 foo => "foo"
1716
1717 - Procedure: add-setter getter setter
1718 Add procedures GETTER and SETTER to the (inaccessible) list of
1719 valid setter/getter pairs. SETTER implements the store operation
1720 corresponding to the GETTER access operation for the relevant
1721 state. The return value is unspecified.
1722
1723 - Procedure: remove-setter-for getter
1724 Removes the setter corresponding to the specified GETTER from the
1725 list of valid setters. The return value is unspecified.
1726
1727 - Syntax: define-access-operation getter-name
1728 Shorthand for a Yasos `define-operation' defining an operation
1729 GETTER-NAME that objects may support to return the value of some
1730 mutable state. The default operation is to signal an error. The
1731 return value is unspecified.
1732
1733 \1f
1734 File: slib.info, Node: Yasos examples, Prev: Setters, Up: Yasos
1735
1736 Examples
1737 --------
1738
1739 ;;; These definitions for PRINT and SIZE are
1740 ;;; already supplied by
1741 (require 'yasos)
1742
1743 (define-operation (print obj port)
1744 (format port
1745 (if (instance? obj) "#<instance>" "~s")
1746 obj))
1747
1748 (define-operation (size obj)
1749 (cond
1750 ((vector? obj) (vector-length obj))
1751 ((list? obj) (length obj))
1752 ((pair? obj) 2)
1753 ((string? obj) (string-length obj))
1754 ((char? obj) 1)
1755 (else
1756 (error "Operation not supported: size" obj))))
1757
1758 (define-predicate cell?)
1759 (define-operation (fetch obj))
1760 (define-operation (store! obj newValue))
1761
1762 (define (make-cell value)
1763 (object
1764 ((cell? self) #t)
1765 ((fetch self) value)
1766 ((store! self newValue)
1767 (set! value newValue)
1768 newValue)
1769 ((size self) 1)
1770 ((print self port)
1771 (format port "#<Cell: ~s>" (fetch self)))))
1772
1773 (define-operation (discard obj value)
1774 (format #t "Discarding ~s~%" value))
1775
1776 (define (make-filtered-cell value filter)
1777 (object-with-ancestors
1778 ((cell (make-cell value)))
1779 ((store! self newValue)
1780 (if (filter newValue)
1781 (store! cell newValue)
1782 (discard self newValue)))))
1783
1784 (define-predicate array?)
1785 (define-operation (array-ref array index))
1786 (define-operation (array-set! array index value))
1787
1788 (define (make-array num-slots)
1789 (let ((anArray (make-vector num-slots)))
1790 (object
1791 ((array? self) #t)
1792 ((size self) num-slots)
1793 ((array-ref self index)
1794 (vector-ref anArray index))
1795 ((array-set! self index newValue)
1796 (vector-set! anArray index newValue))
1797 ((print self port)
1798 (format port "#<Array ~s>" (size self))))))
1799
1800 (define-operation (position obj))
1801 (define-operation (discarded-value obj))
1802
1803 (define (make-cell-with-history value filter size)
1804 (let ((pos 0) (most-recent-discard #f))
1805 (object-with-ancestors
1806 ((cell (make-filtered-call value filter))
1807 (sequence (make-array size)))
1808 ((array? self) #f)
1809 ((position self) pos)
1810 ((store! self newValue)
1811 (operate-as cell store! self newValue)
1812 (array-set! self pos newValue)
1813 (set! pos (+ pos 1)))
1814 ((discard self value)
1815 (set! most-recent-discard value))
1816 ((discarded-value self) most-recent-discard)
1817 ((print self port)
1818 (format port "#<Cell-with-history ~s>"
1819 (fetch self))))))
1820
1821 (define-access-operation fetch)
1822 (add-setter fetch store!)
1823 (define foo (make-cell 1))
1824 (print foo #f)
1825 => "#<Cell: 1>"
1826 (set (fetch foo) 2)
1827 =>
1828 (print foo #f)
1829 => "#<Cell: 2>"
1830 (fetch foo)
1831 => 2
1832
1833 \1f
1834 File: slib.info, Node: Textual Conversion Packages, Next: Mathematical Packages, Prev: Scheme Syntax Extension Packages, Up: Top
1835
1836 Textual Conversion Packages
1837 ***************************
1838
1839 * Menu:
1840
1841 * Precedence Parsing::
1842 * Format:: Common-Lisp Format
1843 * Standard Formatted I/O:: Posix printf and scanf
1844 * Programs and Arguments::
1845 * HTML::
1846 * HTML Tables:: Databases meet HTML
1847 * HTTP and CGI:: Serve WWW sites
1848 * URI:: Uniform Resource Identifier |
1849 * Printing Scheme:: Nicely
1850 * Time and Date::
1851 * Vector Graphics::
1852 * Schmooz:: Documentation markup for Scheme programs
1853
1854 \1f
1855 File: slib.info, Node: Precedence Parsing, Next: Format, Prev: Textual Conversion Packages, Up: Textual Conversion Packages
1856
1857 Precedence Parsing
1858 ==================
1859
1860 `(require 'precedence-parse)' or `(require 'parse)'
1861
1862 This package implements:
1863
1864 * a Pratt style precedence parser;
1865
1866 * a "tokenizer" which congeals tokens according to assigned classes
1867 of constituent characters;
1868
1869 * procedures giving direct control of parser rulesets;
1870
1871 * procedures for higher level specification of rulesets.
1872
1873 * Menu:
1874
1875 * Precedence Parsing Overview::
1876 * Ruleset Definition and Use::
1877 * Token definition::
1878 * Nud and Led Definition::
1879 * Grammar Rule Definition::
1880
1881 \1f
1882 File: slib.info, Node: Precedence Parsing Overview, Next: Ruleset Definition and Use, Prev: Precedence Parsing, Up: Precedence Parsing
1883
1884 Precedence Parsing Overview
1885 ---------------------------
1886
1887 This package offers improvements over previous parsers.
1888
1889 * Common computer language constructs are concisely specified.
1890
1891 * Grammars can be changed dynamically. Operators can be assigned
1892 different meanings within a lexical context.
1893
1894 * Rulesets don't need compilation. Grammars can be changed
1895 incrementally.
1896
1897 * Operator precedence is specified by integers.
1898
1899 * All possibilities of bad input are handled (1) and return as much
1900 structure as was parsed when the error occured; The symbol `?' is
1901 substituted for missing input.
1902
1903 Here are the higher-level syntax types and an example of each.
1904 Precedence considerations are omitted for clarity. See *Note Grammar
1905 Rule Definition:: for full details.
1906
1907 - Grammar: nofix bye exit
1908 bye
1909 calls the function `exit' with no arguments.
1910
1911 - Grammar: prefix - negate
1912 - 42
1913 Calls the function `negate' with the argument `42'.
1914
1915 - Grammar: infix - difference
1916 x - y
1917 Calls the function `difference' with arguments `x' and `y'.
1918
1919 - Grammar: nary + sum
1920 x + y + z
1921 Calls the function `sum' with arguments `x', `y', and `y'.
1922
1923 - Grammar: postfix ! factorial
1924 5 !
1925 Calls the function `factorial' with the argument `5'.
1926
1927 - Grammar: prestfix set set!
1928 set foo bar
1929 Calls the function `set!' with the arguments `foo' and `bar'.
1930
1931 - Grammar: commentfix /* */
1932 /* almost any text here */
1933 Ignores the comment delimited by `/*' and `*/'.
1934
1935 - Grammar: matchfix { list }
1936 {0, 1, 2}
1937 Calls the function `list' with the arguments `0', `1', and `2'.
1938
1939 - Grammar: inmatchfix ( funcall )
1940 f(x, y)
1941 Calls the function `funcall' with the arguments `f', `x', and `y'.
1942
1943 - Grammar: delim ;
1944 set foo bar;
1945 delimits the extent of the restfix operator `set'.
1946
1947 ---------- Footnotes ----------
1948
1949 (1) How do I know this? I parsed 250kbyte of random input (an e-mail
1950 file) with a non-trivial grammar utilizing all constructs.
1951
1952 \1f
1953 File: slib.info, Node: Ruleset Definition and Use, Next: Token definition, Prev: Precedence Parsing Overview, Up: Precedence Parsing
1954
1955 Ruleset Definition and Use
1956 --------------------------
1957
1958 - Variable: *syn-defs*
1959 A grammar is built by one or more calls to `prec:define-grammar'.
1960 The rules are appended to *SYN-DEFS*. The value of *SYN-DEFS* is
1961 the grammar suitable for passing as an argument to `prec:parse'.
1962
1963 - Constant: *syn-ignore-whitespace*
1964 Is a nearly empty grammar with whitespace characters set to group
1965 0, which means they will not be made into tokens. Most rulesets
1966 will want to start with `*syn-ignore-whitespace*'
1967
1968 In order to start defining a grammar, either
1969
1970 (set! *syn-defs* '())
1971
1972 or
1973
1974 (set! *syn-defs* *syn-ignore-whitespace*)
1975
1976 - Function: prec:define-grammar rule1 ...
1977 Appends RULE1 ... to *SYN-DEFS*. `prec:define-grammar' is used to
1978 define both the character classes and rules for tokens.
1979
1980 Once your grammar is defined, save the value of `*syn-defs*' in a
1981 variable (for use when calling `prec:parse').
1982
1983 (define my-ruleset *syn-defs*)
1984
1985 - Function: prec:parse ruleset delim
1986 - Function: prec:parse ruleset delim port
1987 The RULESET argument must be a list of rules as constructed by
1988 `prec:define-grammar' and extracted from *SYN-DEFS*.
1989
1990 The token DELIM may be a character, symbol, or string. A
1991 character DELIM argument will match only a character token; i.e. a
1992 character for which no token-group is assigned. A symbols or
1993 string will match only a token string; i.e. a token resulting from
1994 a token group.
1995
1996 `prec:parse' reads a RULESET grammar expression delimited by DELIM
1997 from the given input PORT. `prec:parse' returns the next object
1998 parsable from the given input PORT, updating PORT to point to the
1999 first character past the end of the external representation of the
2000 object.
2001
2002 If an end of file is encountered in the input before any
2003 characters are found that can begin an object, then an end of file
2004 object is returned. If a delimiter (such as DELIM) is found
2005 before any characters are found that can begin an object, then
2006 `#f' is returned.
2007
2008 The PORT argument may be omitted, in which case it defaults to the
2009 value returned by `current-input-port'. It is an error to parse
2010 from a closed port.
2011
2012 \1f
2013 File: slib.info, Node: Token definition, Next: Nud and Led Definition, Prev: Ruleset Definition and Use, Up: Precedence Parsing
2014
2015 Token definition
2016 ----------------
2017
2018 - Function: tok:char-group group chars chars-proc
2019 The argument CHARS may be a single character, a list of
2020 characters, or a string. Each character in CHARS is treated as
2021 though `tok:char-group' was called with that character alone.
2022
2023 The argument CHARS-PROC must be a procedure of one argument, a
2024 list of characters. After `tokenize' has finished accumulating
2025 the characters for a token, it calls CHARS-PROC with the list of
2026 characters. The value returned is the token which `tokenize'
2027 returns.
2028
2029 The argument GROUP may be an exact integer or a procedure of one
2030 character argument. The following discussion concerns the
2031 treatment which the tokenizing routine, `tokenize', will accord to
2032 characters on the basis of their groups.
2033
2034 When GROUP is a non-zero integer, characters whose group number is
2035 equal to or exactly one less than GROUP will continue to
2036 accumulate. Any other character causes the accumulation to stop
2037 (until a new token is to be read).
2038
2039 The GROUP of zero is special. These characters are ignored when
2040 parsed pending a token, and stop the accumulation of token
2041 characters when the accumulation has already begun. Whitespace
2042 characters are usually put in group 0.
2043
2044 If GROUP is a procedure, then, when triggerd by the occurence of
2045 an initial (no accumulation) CHARS character, this procedure will
2046 be repeatedly called with each successive character from the input
2047 stream until the GROUP procedure returns a non-false value.
2048
2049 The following convenient constants are provided for use with
2050 `tok:char-group'.
2051
2052 - Constant: tok:decimal-digits
2053 Is the string `"0123456789"'.
2054
2055 - Constant: tok:upper-case
2056 Is the string consisting of all upper-case letters
2057 ("ABCDEFGHIJKLMNOPQRSTUVWXYZ").
2058
2059 - Constant: tok:lower-case
2060 Is the string consisting of all lower-case letters
2061 ("abcdefghijklmnopqrstuvwxyz").
2062
2063 - Constant: tok:whitespaces
2064 Is the string consisting of all characters between 0 and 255 for
2065 which `char-whitespace?' returns true.
2066
2067 \1f
2068 File: slib.info, Node: Nud and Led Definition, Next: Grammar Rule Definition, Prev: Token definition, Up: Precedence Parsing
2069
2070 Nud and Led Definition
2071 ----------------------
2072
2073 This section describes advanced features. You can skip this section
2074 on first reading.
2075
2076 The "Null Denotation" (or "nud") of a token is the procedure and
2077 arguments applying for that token when "Left", an unclaimed parsed
2078 expression is not extant.
2079
2080 The "Left Denotation" (or "led") of a token is the procedure,
2081 arguments, and lbp applying for that token when there is a "Left", an
2082 unclaimed parsed expression.
2083
2084 In his paper,
2085
2086 Pratt, V. R. Top Down Operator Precendence. `SIGACT/SIGPLAN
2087 Symposium on Principles of Programming Languages', Boston, 1973,
2088 pages 41-51
2089
2090 the "left binding power" (or "lbp") was an independent property of
2091 tokens. I think this was done in order to allow tokens with NUDs but
2092 not LEDs to also be used as delimiters, which was a problem for
2093 statically defined syntaxes. It turns out that _dynamically binding_
2094 NUDs and LEDs allows them independence.
2095
2096 For the rule-defining procedures that follow, the variable TK may be a
2097 character, string, or symbol, or a list composed of characters,
2098 strings, and symbols. Each element of TK is treated as though the
2099 procedure were called for each element.
2100
2101 Character TK arguments will match only character tokens; i.e.
2102 characters for which no token-group is assigned. Symbols and strings
2103 will both match token strings; i.e. tokens resulting from token groups.
2104
2105 - Function: prec:make-nud tk sop arg1 ...
2106 Returns a rule specifying that SOP be called when TK is parsed.
2107 If SOP is a procedure, it is called with TK and ARG1 ... as its
2108 arguments; the resulting value is incorporated into the expression
2109 being built. Otherwise, `(list SOP ARG1 ...)' is incorporated.
2110
2111 If no NUD has been defined for a token; then if that token is a string,
2112 it is converted to a symbol and returned; if not a string, the token is
2113 returned.
2114
2115 - Function: prec:make-led tk sop arg1 ...
2116 Returns a rule specifying that SOP be called when TK is parsed and
2117 LEFT has an unclaimed parsed expression. If SOP is a procedure,
2118 it is called with LEFT, TK, and ARG1 ... as its arguments; the
2119 resulting value is incorporated into the expression being built.
2120 Otherwise, LEFT is incorporated.
2121
2122 If no LED has been defined for a token, and LEFT is set, the parser
2123 issues a warning.
2124
2125 \1f
2126 File: slib.info, Node: Grammar Rule Definition, Prev: Nud and Led Definition, Up: Precedence Parsing
2127
2128 Grammar Rule Definition
2129 -----------------------
2130
2131 Here are procedures for defining rules for the syntax types introduced
2132 in *Note Precedence Parsing Overview::.
2133
2134 For the rule-defining procedures that follow, the variable TK may be a
2135 character, string, or symbol, or a list composed of characters,
2136 strings, and symbols. Each element of TK is treated as though the
2137 procedure were called for each element.
2138
2139 For procedures prec:delim, ..., prec:prestfix, if the SOP argument is
2140 `#f', then the token which triggered this rule is converted to a symbol
2141 and returned. A false SOP argument to the procedures prec:commentfix,
2142 prec:matchfix, or prec:inmatchfix has a different meaning.
2143
2144 Character TK arguments will match only character tokens; i.e.
2145 characters for which no token-group is assigned. Symbols and strings
2146 will both match token strings; i.e. tokens resulting from token groups.
2147
2148 - Function: prec:delim tk
2149 Returns a rule specifying that TK should not be returned from
2150 parsing; i.e. TK's function is purely syntactic. The end-of-file
2151 is always treated as a delimiter.
2152
2153 - Function: prec:nofix tk sop
2154 Returns a rule specifying the following actions take place when TK
2155 is parsed:
2156 * If SOP is a procedure, it is called with no arguments; the
2157 resulting value is incorporated into the expression being
2158 built. Otherwise, the list of SOP is incorporated.
2159
2160 - Function: prec:prefix tk sop bp rule1 ...
2161 Returns a rule specifying the following actions take place when TK
2162 is parsed:
2163 * The rules RULE1 ... augment and, in case of conflict, override
2164 rules currently in effect.
2165
2166 * `prec:parse1' is called with binding-power BP.
2167
2168 * If SOP is a procedure, it is called with the expression
2169 returned from `prec:parse1'; the resulting value is
2170 incorporated into the expression being built. Otherwise, the
2171 list of SOP and the expression returned from `prec:parse1' is
2172 incorporated.
2173
2174 * The ruleset in effect before TK was parsed is restored; RULE1
2175 ... are forgotten.
2176
2177 - Function: prec:infix tk sop lbp bp rule1 ...
2178 Returns a rule declaring the left-binding-precedence of the token
2179 TK is LBP and specifying the following actions take place when TK
2180 is parsed:
2181 * The rules RULE1 ... augment and, in case of conflict, override
2182 rules currently in effect.
2183
2184 * One expression is parsed with binding-power LBP. If instead a
2185 delimiter is encountered, a warning is issued.
2186
2187 * If SOP is a procedure, it is applied to the list of LEFT and
2188 the parsed expression; the resulting value is incorporated
2189 into the expression being built. Otherwise, the list of SOP,
2190 the LEFT expression, and the parsed expression is
2191 incorporated.
2192
2193 * The ruleset in effect before TK was parsed is restored; RULE1
2194 ... are forgotten.
2195
2196 - Function: prec:nary tk sop bp
2197 Returns a rule declaring the left-binding-precedence of the token
2198 TK is BP and specifying the following actions take place when TK
2199 is parsed:
2200 * Expressions are parsed with binding-power BP as far as they
2201 are interleaved with the token TK.
2202
2203 * If SOP is a procedure, it is applied to the list of LEFT and
2204 the parsed expressions; the resulting value is incorporated
2205 into the expression being built. Otherwise, the list of SOP,
2206 the LEFT expression, and the parsed expressions is
2207 incorporated.
2208
2209 - Function: prec:postfix tk sop lbp
2210 Returns a rule declaring the left-binding-precedence of the token
2211 TK is LBP and specifying the following actions take place when TK
2212 is parsed:
2213 * If SOP is a procedure, it is called with the LEFT expression;
2214 the resulting value is incorporated into the expression being
2215 built. Otherwise, the list of SOP and the LEFT expression is
2216 incorporated.
2217
2218 - Function: prec:prestfix tk sop bp rule1 ...
2219 Returns a rule specifying the following actions take place when TK
2220 is parsed:
2221 * The rules RULE1 ... augment and, in case of conflict, override
2222 rules currently in effect.
2223
2224 * Expressions are parsed with binding-power BP until a
2225 delimiter is reached.
2226
2227 * If SOP is a procedure, it is applied to the list of parsed
2228 expressions; the resulting value is incorporated into the
2229 expression being built. Otherwise, the list of SOP and the
2230 parsed expressions is incorporated.
2231
2232 * The ruleset in effect before TK was parsed is restored; RULE1
2233 ... are forgotten.
2234
2235 - Function: prec:commentfix tk stp match rule1 ...
2236 Returns rules specifying the following actions take place when TK
2237 is parsed:
2238 * The rules RULE1 ... augment and, in case of conflict, override
2239 rules currently in effect.
2240
2241 * Characters are read until and end-of-file or a sequence of
2242 characters is read which matches the _string_ MATCH.
2243
2244 * If STP is a procedure, it is called with the string of all
2245 that was read between the TK and MATCH (exclusive).
2246
2247 * The ruleset in effect before TK was parsed is restored; RULE1
2248 ... are forgotten.
2249
2250 Parsing of commentfix syntax differs from the others in several
2251 ways. It reads directly from input without tokenizing; It calls
2252 STP but does not return its value; nay any value. I added the STP
2253 argument so that comment text could be echoed.
2254
2255 - Function: prec:matchfix tk sop sep match rule1 ...
2256 Returns a rule specifying the following actions take place when TK
2257 is parsed:
2258 * The rules RULE1 ... augment and, in case of conflict, override
2259 rules currently in effect.
2260
2261 * A rule declaring the token MATCH a delimiter takes effect.
2262
2263 * Expressions are parsed with binding-power `0' until the token
2264 MATCH is reached. If the token SEP does not appear between
2265 each pair of expressions parsed, a warning is issued.
2266
2267 * If SOP is a procedure, it is applied to the list of parsed
2268 expressions; the resulting value is incorporated into the
2269 expression being built. Otherwise, the list of SOP and the
2270 parsed expressions is incorporated.
2271
2272 * The ruleset in effect before TK was parsed is restored; RULE1
2273 ... are forgotten.
2274
2275 - Function: prec:inmatchfix tk sop sep match lbp rule1 ...
2276 Returns a rule declaring the left-binding-precedence of the token
2277 TK is LBP and specifying the following actions take place when TK
2278 is parsed:
2279 * The rules RULE1 ... augment and, in case of conflict, override
2280 rules currently in effect.
2281
2282 * A rule declaring the token MATCH a delimiter takes effect.
2283
2284 * Expressions are parsed with binding-power `0' until the token
2285 MATCH is reached. If the token SEP does not appear between
2286 each pair of expressions parsed, a warning is issued.
2287
2288 * If SOP is a procedure, it is applied to the list of LEFT and
2289 the parsed expressions; the resulting value is incorporated
2290 into the expression being built. Otherwise, the list of SOP,
2291 the LEFT expression, and the parsed expressions is
2292 incorporated.
2293
2294 * The ruleset in effect before TK was parsed is restored; RULE1
2295 ... are forgotten.
2296
2297 \1f
2298 File: slib.info, Node: Format, Next: Standard Formatted I/O, Prev: Precedence Parsing, Up: Textual Conversion Packages
2299
2300 Format (version 3.0)
2301 ====================
2302
2303 `(require 'format)'
2304
2305 * Menu:
2306
2307 * Format Interface::
2308 * Format Specification::
2309
2310 \1f
2311 File: slib.info, Node: Format Interface, Next: Format Specification, Prev: Format, Up: Format
2312
2313 Format Interface
2314 ----------------
2315
2316 - Function: format destination format-string . arguments
2317 An almost complete implementation of Common LISP format description
2318 according to the CL reference book `Common LISP' from Guy L.
2319 Steele, Digital Press. Backward compatible to most of the
2320 available Scheme format implementations.
2321
2322 Returns `#t', `#f' or a string; has side effect of printing
2323 according to FORMAT-STRING. If DESTINATION is `#t', the output is
2324 to the current output port and `#t' is returned. If DESTINATION
2325 is `#f', a formatted string is returned as the result of the call.
2326 NEW: If DESTINATION is a string, DESTINATION is regarded as the
2327 format string; FORMAT-STRING is then the first argument and the
2328 output is returned as a string. If DESTINATION is a number, the
2329 output is to the current error port if available by the
2330 implementation. Otherwise DESTINATION must be an output port and
2331 `#t' is returned.
2332
2333 FORMAT-STRING must be a string. In case of a formatting error
2334 format returns `#f' and prints a message on the current output or
2335 error port. Characters are output as if the string were output by
2336 the `display' function with the exception of those prefixed by a
2337 tilde (~). For a detailed description of the FORMAT-STRING syntax
2338 please consult a Common LISP format reference manual. For a test
2339 suite to verify this format implementation load `formatst.scm'.
2340 Please send bug reports to `lutzeb@cs.tu-berlin.de'.
2341
2342 Note: `format' is not reentrant, i.e. only one `format'-call may
2343 be executed at a time.
2344
2345
2346 \1f
2347 File: slib.info, Node: Format Specification, Prev: Format Interface, Up: Format
2348
2349 Format Specification (Format version 3.0)
2350 -----------------------------------------
2351
2352 Please consult a Common LISP format reference manual for a detailed
2353 description of the format string syntax. For a demonstration of the
2354 implemented directives see `formatst.scm'.
2355
2356 This implementation supports directive parameters and modifiers (`:'
2357 and `@' characters). Multiple parameters must be separated by a comma
2358 (`,'). Parameters can be numerical parameters (positive or negative),
2359 character parameters (prefixed by a quote character (`''), variable
2360 parameters (`v'), number of rest arguments parameter (`#'), empty and
2361 default parameters. Directive characters are case independent. The
2362 general form of a directive is:
2363
2364 DIRECTIVE ::= ~{DIRECTIVE-PARAMETER,}[:][@]DIRECTIVE-CHARACTER
2365
2366 DIRECTIVE-PARAMETER ::= [ [-|+]{0-9}+ | 'CHARACTER | v | # ]
2367
2368 Implemented CL Format Control Directives
2369 ........................................
2370
2371 Documentation syntax: Uppercase characters represent the corresponding
2372 control directive characters. Lowercase characters represent control
2373 directive parameter descriptions.
2374
2375 `~A'
2376 Any (print as `display' does).
2377 `~@A'
2378 left pad.
2379
2380 `~MINCOL,COLINC,MINPAD,PADCHARA'
2381 full padding.
2382
2383 `~S'
2384 S-expression (print as `write' does).
2385 `~@S'
2386 left pad.
2387
2388 `~MINCOL,COLINC,MINPAD,PADCHARS'
2389 full padding.
2390
2391 `~D'
2392 Decimal.
2393 `~@D'
2394 print number sign always.
2395
2396 `~:D'
2397 print comma separated.
2398
2399 `~MINCOL,PADCHAR,COMMACHARD'
2400 padding.
2401
2402 `~X'
2403 Hexadecimal.
2404 `~@X'
2405 print number sign always.
2406
2407 `~:X'
2408 print comma separated.
2409
2410 `~MINCOL,PADCHAR,COMMACHARX'
2411 padding.
2412
2413 `~O'
2414 Octal.
2415 `~@O'
2416 print number sign always.
2417
2418 `~:O'
2419 print comma separated.
2420
2421 `~MINCOL,PADCHAR,COMMACHARO'
2422 padding.
2423
2424 `~B'
2425 Binary.
2426 `~@B'
2427 print number sign always.
2428
2429 `~:B'
2430 print comma separated.
2431
2432 `~MINCOL,PADCHAR,COMMACHARB'
2433 padding.
2434
2435 `~NR'
2436 Radix N.
2437 `~N,MINCOL,PADCHAR,COMMACHARR'
2438 padding.
2439
2440 `~@R'
2441 print a number as a Roman numeral.
2442
2443 `~:@R'
2444 print a number as an "old fashioned" Roman numeral.
2445
2446 `~:R'
2447 print a number as an ordinal English number.
2448
2449 `~R' |
2450 print a number as a cardinal English number.
2451
2452 `~P'
2453 Plural.
2454 `~@P'
2455 prints `y' and `ies'.
2456
2457 `~:P'
2458 as `~P but jumps 1 argument backward.'
2459
2460 `~:@P'
2461 as `~@P but jumps 1 argument backward.'
2462
2463 `~C'
2464 Character.
2465 `~@C'
2466 prints a character as the reader can understand it (i.e. `#\'
2467 prefixing).
2468
2469 `~:C'
2470 prints a character as emacs does (eg. `^C' for ASCII 03).
2471
2472 `~F'
2473 Fixed-format floating-point (prints a flonum like MMM.NNN).
2474 `~WIDTH,DIGITS,SCALE,OVERFLOWCHAR,PADCHARF'
2475
2476 `~@F'
2477 If the number is positive a plus sign is printed.
2478
2479 `~E'
2480 Exponential floating-point (prints a flonum like MMM.NNN`E'EE).
2481 `~WIDTH,DIGITS,EXPONENTDIGITS,SCALE,OVERFLOWCHAR,PADCHAR,EXPONENTCHARE'
2482
2483 `~@E'
2484 If the number is positive a plus sign is printed.
2485
2486 `~G'
2487 General floating-point (prints a flonum either fixed or
2488 exponential).
2489 `~WIDTH,DIGITS,EXPONENTDIGITS,SCALE,OVERFLOWCHAR,PADCHAR,EXPONENTCHARG'
2490
2491 `~@G'
2492 If the number is positive a plus sign is printed.
2493
2494 `~$'
2495 Dollars floating-point (prints a flonum in fixed with signs
2496 separated).
2497 `~DIGITS,SCALE,WIDTH,PADCHAR$'
2498
2499 `~@$'
2500 If the number is positive a plus sign is printed.
2501
2502 `~:@$'
2503 A sign is always printed and appears before the padding.
2504
2505 `~:$'
2506 The sign appears before the padding.
2507
2508 `~%'
2509 Newline.
2510 `~N%'
2511 print N newlines.
2512
2513 `~&'
2514 print newline if not at the beginning of the output line.
2515 `~N&'
2516 prints `~&' and then N-1 newlines.
2517
2518 `~|'
2519 Page Separator.
2520 `~N|'
2521 print N page separators.
2522
2523 `~~'
2524 Tilde.
2525 `~N~'
2526 print N tildes.
2527
2528 `~'<newline>
2529 Continuation Line.
2530 `~:'<newline>
2531 newline is ignored, white space left.
2532
2533 `~@'<newline>
2534 newline is left, white space ignored.
2535
2536 `~T'
2537 Tabulation.
2538 `~@T'
2539 relative tabulation.
2540
2541 `~COLNUM,COLINCT'
2542 full tabulation.
2543
2544 `~?'
2545 Indirection (expects indirect arguments as a list).
2546 `~@?'
2547 extracts indirect arguments from format arguments.
2548
2549 `~(STR~)'
2550 Case conversion (converts by `string-downcase').
2551 `~:(STR~)'
2552 converts by `string-capitalize'.
2553
2554 `~@(STR~)'
2555 converts by `string-capitalize-first'.
2556
2557 `~:@(STR~)'
2558 converts by `string-upcase'.
2559
2560 `~*'
2561 Argument Jumping (jumps 1 argument forward).
2562 `~N*'
2563 jumps N arguments forward.
2564
2565 `~:*'
2566 jumps 1 argument backward.
2567
2568 `~N:*'
2569 jumps N arguments backward.
2570
2571 `~@*'
2572 jumps to the 0th argument.
2573
2574 `~N@*'
2575 jumps to the Nth argument (beginning from 0)
2576
2577 `~[STR0~;STR1~;...~;STRN~]'
2578 Conditional Expression (numerical clause conditional).
2579 `~N['
2580 take argument from N.
2581
2582 `~@['
2583 true test conditional.
2584
2585 `~:['
2586 if-else-then conditional.
2587
2588 `~;'
2589 clause separator.
2590
2591 `~:;'
2592 default clause follows.
2593
2594 `~{STR~}'
2595 Iteration (args come from the next argument (a list)).
2596 `~N{'
2597 at most N iterations.
2598
2599 `~:{'
2600 args from next arg (a list of lists).
2601
2602 `~@{'
2603 args from the rest of arguments.
2604
2605 `~:@{'
2606 args from the rest args (lists).
2607
2608 `~^'
2609 Up and out.
2610 `~N^'
2611 aborts if N = 0
2612
2613 `~N,M^'
2614 aborts if N = M
2615
2616 `~N,M,K^'
2617 aborts if N <= M <= K
2618
2619 Not Implemented CL Format Control Directives
2620 ............................................
2621
2622 `~:A'
2623 print `#f' as an empty list (see below).
2624
2625 `~:S'
2626 print `#f' as an empty list (see below).
2627
2628 `~<~>'
2629 Justification.
2630
2631 `~:^'
2632 (sorry I don't understand its semantics completely)
2633
2634 Extended, Replaced and Additional Control Directives
2635 ....................................................
2636
2637 `~MINCOL,PADCHAR,COMMACHAR,COMMAWIDTHD'
2638
2639 `~MINCOL,PADCHAR,COMMACHAR,COMMAWIDTHX'
2640
2641 `~MINCOL,PADCHAR,COMMACHAR,COMMAWIDTHO'
2642
2643 `~MINCOL,PADCHAR,COMMACHAR,COMMAWIDTHB'
2644
2645 `~N,MINCOL,PADCHAR,COMMACHAR,COMMAWIDTHR'
2646 COMMAWIDTH is the number of characters between two comma
2647 characters.
2648
2649 `~I'
2650 print a R4RS complex number as `~F~@Fi' with passed parameters for
2651 `~F'.
2652
2653 `~Y'
2654 Pretty print formatting of an argument for scheme code lists.
2655
2656 `~K'
2657 Same as `~?.'
2658
2659 `~!'
2660 Flushes the output if format DESTINATION is a port.
2661
2662 `~_'
2663 Print a `#\space' character
2664 `~N_'
2665 print N `#\space' characters.
2666
2667 `~/'
2668 Print a `#\tab' character
2669 `~N/'
2670 print N `#\tab' characters.
2671
2672 `~NC'
2673 Takes N as an integer representation for a character. No arguments
2674 are consumed. N is converted to a character by `integer->char'. N
2675 must be a positive decimal number.
2676
2677 `~:S'
2678 Print out readproof. Prints out internal objects represented as
2679 `#<...>' as strings `"#<...>"' so that the format output can always
2680 be processed by `read'.
2681
2682 `~:A'
2683 Print out readproof. Prints out internal objects represented as
2684 `#<...>' as strings `"#<...>"' so that the format output can always
2685 be processed by `read'.
2686
2687 `~Q'
2688 Prints information and a copyright notice on the format
2689 implementation.
2690 `~:Q'
2691 prints format version.
2692
2693 `~F, ~E, ~G, ~$'
2694 may also print number strings, i.e. passing a number as a string
2695 and format it accordingly.
2696
2697 Configuration Variables
2698 .......................
2699
2700 Format has some configuration variables at the beginning of
2701 `format.scm' to suit the systems and users needs. There should be no
2702 modification necessary for the configuration that comes with SLIB. If
2703 modification is desired the variable should be set after the format
2704 code is loaded. Format detects automatically if the running scheme
2705 system implements floating point numbers and complex numbers.
2706
2707 FORMAT:SYMBOL-CASE-CONV
2708 Symbols are converted by `symbol->string' so the case type of the
2709 printed symbols is implementation dependent.
2710 `format:symbol-case-conv' is a one arg closure which is either
2711 `#f' (no conversion), `string-upcase', `string-downcase' or
2712 `string-capitalize'. (default `#f')
2713
2714 FORMAT:IOBJ-CASE-CONV
2715 As FORMAT:SYMBOL-CASE-CONV but applies for the representation of
2716 implementation internal objects. (default `#f')
2717
2718 FORMAT:EXPCH
2719 The character prefixing the exponent value in `~E' printing.
2720 (default `#\E')
2721
2722 Compatibility With Other Format Implementations
2723 ...............................................
2724
2725 SLIB format 2.x:
2726 See `format.doc'.
2727
2728 SLIB format 1.4:
2729 Downward compatible except for padding support and `~A', `~S',
2730 `~P', `~X' uppercase printing. SLIB format 1.4 uses C-style
2731 `printf' padding support which is completely replaced by the CL
2732 `format' padding style.
2733
2734 MIT C-Scheme 7.1:
2735 Downward compatible except for `~', which is not documented
2736 (ignores all characters inside the format string up to a newline
2737 character). (7.1 implements `~a', `~s', ~NEWLINE, `~~', `~%',
2738 numerical and variable parameters and `:/@' modifiers in the CL
2739 sense).
2740
2741 Elk 1.5/2.0:
2742 Downward compatible except for `~A' and `~S' which print in
2743 uppercase. (Elk implements `~a', `~s', `~~', and `~%' (no
2744 directive parameters or modifiers)).
2745
2746 Scheme->C 01nov91:
2747 Downward compatible except for an optional destination parameter:
2748 S2C accepts a format call without a destination which returns a
2749 formatted string. This is equivalent to a #f destination in S2C.
2750 (S2C implements `~a', `~s', `~c', `~%', and `~~' (no directive
2751 parameters or modifiers)).
2752
2753 This implementation of format is solely useful in the SLIB context
2754 because it requires other components provided by SLIB.
2755
2756 \1f
2757 File: slib.info, Node: Standard Formatted I/O, Next: Programs and Arguments, Prev: Format, Up: Textual Conversion Packages
2758
2759 Standard Formatted I/O
2760 ======================
2761
2762 * Menu:
2763
2764 * Standard Formatted Output:: 'printf
2765 * Standard Formatted Input:: 'scanf
2766
2767 stdio
2768 -----
2769
2770 `(require 'stdio)'
2771
2772 `require's `printf' and `scanf' and additionally defines the symbols:
2773
2774 - Variable: stdin
2775 Defined to be `(current-input-port)'.
2776
2777 - Variable: stdout
2778 Defined to be `(current-output-port)'.
2779
2780 - Variable: stderr
2781 Defined to be `(current-error-port)'.
2782
2783 \1f
2784 File: slib.info, Node: Standard Formatted Output, Next: Standard Formatted Input, Prev: Standard Formatted I/O, Up: Standard Formatted I/O
2785
2786 Standard Formatted Output
2787 -------------------------
2788
2789 `(require 'printf)'
2790
2791 - Procedure: printf format arg1 ...
2792 - Procedure: fprintf port format arg1 ...
2793 - Procedure: sprintf str format arg1 ...
2794 - Procedure: sprintf #f format arg1 ...
2795 - Procedure: sprintf k format arg1 ...
2796 Each function converts, formats, and outputs its ARG1 ...
2797 arguments according to the control string FORMAT argument and
2798 returns the number of characters output.
2799
2800 `printf' sends its output to the port `(current-output-port)'.
2801 `fprintf' sends its output to the port PORT. `sprintf'
2802 `string-set!'s locations of the non-constant string argument STR
2803 to the output characters.
2804
2805 Two extensions of `sprintf' return new strings. If the first
2806 argument is `#f', then the returned string's length is as many
2807 characters as specified by the FORMAT and data; if the first
2808 argument is a non-negative integer K, then the length of the
2809 returned string is also bounded by K.
2810
2811 The string FORMAT contains plain characters which are copied to
2812 the output stream, and conversion specifications, each of which
2813 results in fetching zero or more of the arguments ARG1 .... The
2814 results are undefined if there are an insufficient number of
2815 arguments for the format. If FORMAT is exhausted while some of the
2816 ARG1 ... arguments remain unused, the excess ARG1 ... arguments
2817 are ignored.
2818
2819 The conversion specifications in a format string have the form:
2820
2821 % [ FLAGS ] [ WIDTH ] [ . PRECISION ] [ TYPE ] CONVERSION
2822
2823 An output conversion specifications consist of an initial `%'
2824 character followed in sequence by:
2825
2826 * Zero or more "flag characters" that modify the normal
2827 behavior of the conversion specification.
2828
2829 `-'
2830 Left-justify the result in the field. Normally the
2831 result is right-justified.
2832
2833 `+'
2834 For the signed `%d' and `%i' conversions and all inexact
2835 conversions, prefix a plus sign if the value is positive.
2836
2837 ` '
2838 For the signed `%d' and `%i' conversions, if the result
2839 doesn't start with a plus or minus sign, prefix it with
2840 a space character instead. Since the `+' flag ensures
2841 that the result includes a sign, this flag is ignored if
2842 both are specified.
2843
2844 `#'
2845 For inexact conversions, `#' specifies that the result
2846 should always include a decimal point, even if no digits
2847 follow it. For the `%g' and `%G' conversions, this also
2848 forces trailing zeros after the decimal point to be
2849 printed where they would otherwise be elided.
2850
2851 For the `%o' conversion, force the leading digit to be
2852 `0', as if by increasing the precision. For `%x' or
2853 `%X', prefix a leading `0x' or `0X' (respectively) to
2854 the result. This doesn't do anything useful for the
2855 `%d', `%i', or `%u' conversions. Using this flag
2856 produces output which can be parsed by the `scanf'
2857 functions with the `%i' conversion (*note Standard
2858 Formatted Input::).
2859
2860 `0'
2861 Pad the field with zeros instead of spaces. The zeros
2862 are placed after any indication of sign or base. This
2863 flag is ignored if the `-' flag is also specified, or if
2864 a precision is specified for an exact converson.
2865
2866 * An optional decimal integer specifying the "minimum field
2867 width". If the normal conversion produces fewer characters
2868 than this, the field is padded (with spaces or zeros per the
2869 `0' flag) to the specified width. This is a _minimum_ width;
2870 if the normal conversion produces more characters than this,
2871 the field is _not_ truncated.
2872
2873 Alternatively, if the field width is `*', the next argument
2874 in the argument list (before the actual value to be printed)
2875 is used as the field width. The width value must be an
2876 integer. If the value is negative it is as though the `-'
2877 flag is set (see above) and the absolute value is used as the
2878 field width.
2879
2880 * An optional "precision" to specify the number of digits to be
2881 written for numeric conversions and the maximum field width
2882 for string conversions. The precision is specified by a
2883 period (`.') followed optionally by a decimal integer (which
2884 defaults to zero if omitted).
2885
2886 Alternatively, if the precision is `.*', the next argument in
2887 the argument list (before the actual value to be printed) is
2888 used as the precision. The value must be an integer, and is
2889 ignored if negative. If you specify `*' for both the field
2890 width and precision, the field width argument precedes the
2891 precision argument. The `.*' precision is an enhancement. C
2892 library versions may not accept this syntax.
2893
2894 For the `%f', `%e', and `%E' conversions, the precision
2895 specifies how many digits follow the decimal-point character.
2896 The default precision is `6'. If the precision is
2897 explicitly `0', the decimal point character is suppressed.
2898
2899 For the `%g' and `%G' conversions, the precision specifies how
2900 many significant digits to print. Significant digits are the
2901 first digit before the decimal point, and all the digits
2902 after it. If the precision is `0' or not specified for `%g'
2903 or `%G', it is treated like a value of `1'. If the value
2904 being printed cannot be expressed accurately in the specified
2905 number of digits, the value is rounded to the nearest number
2906 that fits.
2907
2908 For exact conversions, if a precision is supplied it
2909 specifies the minimum number of digits to appear; leading
2910 zeros are produced if necessary. If a precision is not
2911 supplied, the number is printed with as many digits as
2912 necessary. Converting an exact `0' with an explicit
2913 precision of zero produces no characters.
2914
2915 * An optional one of `l', `h' or `L', which is ignored for
2916 numeric conversions. It is an error to specify these
2917 modifiers for non-numeric conversions.
2918
2919 * A character that specifies the conversion to be applied.
2920
2921 Exact Conversions
2922 .................
2923
2924 `d', `i'
2925 Print an integer as a signed decimal number. `%d' and `%i'
2926 are synonymous for output, but are different when used with
2927 `scanf' for input (*note Standard Formatted Input::).
2928
2929 `o'
2930 Print an integer as an unsigned octal number.
2931
2932 `u'
2933 Print an integer as an unsigned decimal number.
2934
2935 `x', `X'
2936 Print an integer as an unsigned hexadecimal number. `%x'
2937 prints using the digits `0123456789abcdef'. `%X' prints
2938 using the digits `0123456789ABCDEF'.
2939
2940 Inexact Conversions
2941 ...................
2942
2943 `f'
2944 Print a floating-point number in fixed-point notation.
2945
2946 `e', `E'
2947 Print a floating-point number in exponential notation. `%e'
2948 prints `e' between mantissa and exponont. `%E' prints `E'
2949 between mantissa and exponont.
2950
2951 `g', `G'
2952 Print a floating-point number in either fixed or exponential
2953 notation, whichever is more appropriate for its magnitude.
2954 Unless an `#' flag has been supplied, trailing zeros after a
2955 decimal point will be stripped off. `%g' prints `e' between
2956 mantissa and exponont. `%G' prints `E' between mantissa and
2957 exponent.
2958
2959 `k', `K'
2960 Print a number like `%g', except that an SI prefix is output
2961 after the number, which is scaled accordingly. `%K' outputs
2962 a space between number and prefix, `%k' does not.
2963
2964 Other Conversions
2965 .................
2966
2967 `c'
2968 Print a single character. The `-' flag is the only one which
2969 can be specified. It is an error to specify a precision.
2970
2971 `s'
2972 Print a string. The `-' flag is the only one which can be
2973 specified. A precision specifies the maximum number of
2974 characters to output; otherwise all characters in the string
2975 are output.
2976
2977 `a', `A'
2978 Print a scheme expression. The `-' flag left-justifies the
2979 output. The `#' flag specifies that strings and characters
2980 should be quoted as by `write' (which can be read using
2981 `read'); otherwise, output is as `display' prints. A
2982 precision specifies the maximum number of characters to
2983 output; otherwise as many characters as needed are output.
2984
2985 _Note:_ `%a' and `%A' are SLIB extensions.
2986
2987 `%'
2988 Print a literal `%' character. No argument is consumed. It
2989 is an error to specifiy flags, field width, precision, or
2990 type modifiers with `%%'.
2991
2992 \1f
2993 File: slib.info, Node: Standard Formatted Input, Prev: Standard Formatted Output, Up: Standard Formatted I/O
2994
2995 Standard Formatted Input
2996 ------------------------
2997
2998 `(require 'scanf)'
2999
3000 - Function: scanf-read-list format
3001 - Function: scanf-read-list format port
3002 - Function: scanf-read-list format string
3003
3004 - Macro: scanf format arg1 ...
3005 - Macro: fscanf port format arg1 ...
3006 - Macro: sscanf str format arg1 ...
3007 Each function reads characters, interpreting them according to the
3008 control string FORMAT argument.
3009
3010 `scanf-read-list' returns a list of the items specified as far as
3011 the input matches FORMAT. `scanf', `fscanf', and `sscanf' return
3012 the number of items successfully matched and stored. `scanf',
3013 `fscanf', and `sscanf' also set the location corresponding to ARG1
3014 ... using the methods:
3015
3016 symbol
3017 `set!'
3018
3019 car expression
3020 `set-car!'
3021
3022 cdr expression
3023 `set-cdr!'
3024
3025 vector-ref expression
3026 `vector-set!'
3027
3028 substring expression
3029 `substring-move-left!'
3030
3031 The argument to a `substring' expression in ARG1 ... must be a
3032 non-constant string. Characters will be stored starting at the
3033 position specified by the second argument to `substring'. The
3034 number of characters stored will be limited by either the position
3035 specified by the third argument to `substring' or the length of the
3036 matched string, whichever is less.
3037
3038 The control string, FORMAT, contains conversion specifications and
3039 other characters used to direct interpretation of input sequences.
3040 The control string contains:
3041
3042 * White-space characters (blanks, tabs, newlines, or formfeeds)
3043 that cause input to be read (and discarded) up to the next
3044 non-white-space character.
3045
3046 * An ordinary character (not `%') that must match the next
3047 character of the input stream.
3048
3049 * Conversion specifications, consisting of the character `%', an
3050 optional assignment suppressing character `*', an optional
3051 numerical maximum-field width, an optional `l', `h' or `L'
3052 which is ignored, and a conversion code.
3053
3054
3055 Unless the specification contains the `n' conversion character
3056 (described below), a conversion specification directs the
3057 conversion of the next input field. The result of a conversion
3058 specification is returned in the position of the corresponding
3059 argument points, unless `*' indicates assignment suppression.
3060 Assignment suppression provides a way to describe an input field
3061 to be skipped. An input field is defined as a string of
3062 characters; it extends to the next inappropriate character or
3063 until the field width, if specified, is exhausted.
3064
3065 _Note:_ This specification of format strings differs from the
3066 `ANSI C' and `POSIX' specifications. In SLIB, white space
3067 before an input field is not skipped unless white space
3068 appears before the conversion specification in the format
3069 string. In order to write format strings which work
3070 identically with `ANSI C' and SLIB, prepend whitespace to all
3071 conversion specifications except `[' and `c'.
3072
3073 The conversion code indicates the interpretation of the input
3074 field; For a suppressed field, no value is returned. The
3075 following conversion codes are legal:
3076
3077 `%'
3078 A single % is expected in the input at this point; no value
3079 is returned.
3080
3081 `d', `D'
3082 A decimal integer is expected.
3083
3084 `u', `U'
3085 An unsigned decimal integer is expected.
3086
3087 `o', `O'
3088 An octal integer is expected.
3089
3090 `x', `X'
3091 A hexadecimal integer is expected.
3092
3093 `i'
3094 An integer is expected. Returns the value of the next input
3095 item, interpreted according to C conventions; a leading `0'
3096 implies octal, a leading `0x' implies hexadecimal; otherwise,
3097 decimal is assumed.
3098
3099 `n'
3100 Returns the total number of bytes (including white space)
3101 read by `scanf'. No input is consumed by `%n'.
3102
3103 `f', `F', `e', `E', `g', `G'
3104 A floating-point number is expected. The input format for
3105 floating-point numbers is an optionally signed string of
3106 digits, possibly containing a radix character `.', followed
3107 by an optional exponent field consisting of an `E' or an `e',
3108 followed by an optional `+', `-', or space, followed by an
3109 integer.
3110
3111 `c', `C'
3112 WIDTH characters are expected. The normal
3113 skip-over-white-space is suppressed in this case; to read the
3114 next non-space character, use `%1s'. If a field width is
3115 given, a string is returned; up to the indicated number of
3116 characters is read.
3117
3118 `s', `S'
3119 A character string is expected The input field is terminated
3120 by a white-space character. `scanf' cannot read a null
3121 string.
3122
3123 `['
3124 Indicates string data and the normal
3125 skip-over-leading-white-space is suppressed. The left
3126 bracket is followed by a set of characters, called the
3127 scanset, and a right bracket; the input field is the maximal
3128 sequence of input characters consisting entirely of
3129 characters in the scanset. `^', when it appears as the first
3130 character in the scanset, serves as a complement operator and
3131 redefines the scanset as the set of all characters not
3132 contained in the remainder of the scanset string.
3133 Construction of the scanset follows certain conventions. A
3134 range of characters may be represented by the construct
3135 first-last, enabling `[0123456789]' to be expressed `[0-9]'.
3136 Using this convention, first must be lexically less than or
3137 equal to last; otherwise, the dash stands for itself. The
3138 dash also stands for itself when it is the first or the last
3139 character in the scanset. To include the right square
3140 bracket as an element of the scanset, it must appear as the
3141 first character (possibly preceded by a `^') of the scanset,
3142 in which case it will not be interpreted syntactically as the
3143 closing bracket. At least one character must match for this
3144 conversion to succeed.
3145
3146 The `scanf' functions terminate their conversions at end-of-file,
3147 at the end of the control string, or when an input character
3148 conflicts with the control string. In the latter case, the
3149 offending character is left unread in the input stream.
3150
3151 \1f
3152 File: slib.info, Node: Programs and Arguments, Next: HTML, Prev: Standard Formatted I/O, Up: Textual Conversion Packages
3153
3154 Program and Arguments
3155 =====================
3156
3157 * Menu:
3158
3159 * Getopt:: Command Line option parsing
3160 * Command Line:: A command line reader for Scheme shells
3161 * Parameter lists:: 'parameters
3162 * Getopt Parameter lists:: 'getopt-parameters
3163 * Filenames:: 'glob or 'filename
3164 * Batch:: 'batch
3165
3166 \1f
3167 File: slib.info, Node: Getopt, Next: Command Line, Prev: Programs and Arguments, Up: Programs and Arguments
3168
3169 Getopt
3170 ------
3171
3172 `(require 'getopt)'
3173
3174 This routine implements Posix command line argument parsing. Notice
3175 that returning values through global variables means that `getopt' is
3176 _not_ reentrant.
3177
3178 - Variable: *optind*
3179 Is the index of the current element of the command line. It is
3180 initially one. In order to parse a new command line or reparse an
3181 old one, *OPTING* must be reset.
3182
3183 - Variable: *optarg*
3184 Is set by getopt to the (string) option-argument of the current
3185 option.
3186
3187 - Procedure: getopt argc argv optstring
3188 Returns the next option letter in ARGV (starting from `(vector-ref
3189 argv *optind*)') that matches a letter in OPTSTRING. ARGV is a
3190 vector or list of strings, the 0th of which getopt usually
3191 ignores. ARGC is the argument count, usually the length of ARGV.
3192 OPTSTRING is a string of recognized option characters; if a
3193 character is followed by a colon, the option takes an argument
3194 which may be immediately following it in the string or in the next
3195 element of ARGV.
3196
3197 *OPTIND* is the index of the next element of the ARGV vector to be
3198 processed. It is initialized to 1 by `getopt.scm', and `getopt'
3199 updates it when it finishes with each element of ARGV.
3200
3201 `getopt' returns the next option character from ARGV that matches
3202 a character in OPTSTRING, if there is one that matches. If the
3203 option takes an argument, `getopt' sets the variable *OPTARG* to
3204 the option-argument as follows:
3205
3206 * If the option was the last character in the string pointed to
3207 by an element of ARGV, then *OPTARG* contains the next
3208 element of ARGV, and *OPTIND* is incremented by 2. If the
3209 resulting value of *OPTIND* is greater than or equal to ARGC,
3210 this indicates a missing option argument, and `getopt'
3211 returns an error indication.
3212
3213 * Otherwise, *OPTARG* is set to the string following the option
3214 character in that element of ARGV, and *OPTIND* is
3215 incremented by 1.
3216
3217 If, when `getopt' is called, the string `(vector-ref argv
3218 *optind*)' either does not begin with the character `#\-' or is
3219 just `"-"', `getopt' returns `#f' without changing *OPTIND*. If
3220 `(vector-ref argv *optind*)' is the string `"--"', `getopt'
3221 returns `#f' after incrementing *OPTIND*.
3222
3223 If `getopt' encounters an option character that is not contained in
3224 OPTSTRING, it returns the question-mark `#\?' character. If it
3225 detects a missing option argument, it returns the colon character
3226 `#\:' if the first character of OPTSTRING was a colon, or a
3227 question-mark character otherwise. In either case, `getopt' sets
3228 the variable GETOPT:OPT to the option character that caused the
3229 error.
3230
3231 The special option `"--"' can be used to delimit the end of the
3232 options; `#f' is returned, and `"--"' is skipped.
3233
3234 RETURN VALUE
3235
3236 `getopt' returns the next option character specified on the command
3237 line. A colon `#\:' is returned if `getopt' detects a missing
3238 argument and the first character of OPTSTRING was a colon `#\:'.
3239
3240 A question-mark `#\?' is returned if `getopt' encounters an option
3241 character not in OPTSTRING or detects a missing argument and the
3242 first character of OPTSTRING was not a colon `#\:'.
3243
3244 Otherwise, `getopt' returns `#f' when all command line options
3245 have been parsed.
3246
3247 Example:
3248 #! /usr/local/bin/scm
3249 ;;;This code is SCM specific.
3250 (define argv (program-arguments))
3251 (require 'getopt)
3252
3253 (define opts ":a:b:cd")
3254 (let loop ((opt (getopt (length argv) argv opts)))
3255 (case opt
3256 ((#\a) (print "option a: " *optarg*))
3257 ((#\b) (print "option b: " *optarg*))
3258 ((#\c) (print "option c"))
3259 ((#\d) (print "option d"))
3260 ((#\?) (print "error" getopt:opt))
3261 ((#\:) (print "missing arg" getopt:opt))
3262 ((#f) (if (< *optind* (length argv))
3263 (print "argv[" *optind* "]="
3264 (list-ref argv *optind*)))
3265 (set! *optind* (+ *optind* 1))))
3266 (if (< *optind* (length argv))
3267 (loop (getopt (length argv) argv opts))))
3268
3269 (slib:exit)
3270
3271 Getopt-
3272 -------
3273
3274 - Function: getopt- argc argv optstring
3275 The procedure `getopt--' is an extended version of `getopt' which
3276 parses "long option names" of the form `--hold-the-onions' and
3277 `--verbosity-level=extreme'. `Getopt--' behaves as `getopt'
3278 except for non-empty options beginning with `--'.
3279
3280 Options beginning with `--' are returned as strings rather than
3281 characters. If a value is assigned (using `=') to a long option,
3282 `*optarg*' is set to the value. The `=' and value are not
3283 returned as part of the option string.
3284
3285 No information is passed to `getopt--' concerning which long
3286 options should be accepted or whether such options can take
3287 arguments. If a long option did not have an argument, `*optarg'
3288 will be set to `#f'. The caller is responsible for detecting and
3289 reporting errors.
3290
3291 (define opts ":-:b:")
3292 (define argc 5)
3293 (define argv '("foo" "-b9" "--f1" "--2=" "--g3=35234.342" "--"))
3294 (define *optind* 1)
3295 (define *optarg* #f)
3296 (require 'qp)
3297 (do ((i 5 (+ -1 i)))
3298 ((zero? i))
3299 (define opt (getopt-- argc argv opts))
3300 (print *optind* opt *optarg*)))
3301 -|
3302 2 #\b "9"
3303 3 "f1" #f
3304 4 "2" ""
3305 5 "g3" "35234.342"
3306 5 #f "35234.342"
3307
3308 \1f
3309 File: slib.info, Node: Command Line, Next: Parameter lists, Prev: Getopt, Up: Programs and Arguments
3310
3311 Command Line
3312 ------------
3313
3314 `(require 'read-command)'
3315
3316 - Function: read-command port
3317 - Function: read-command
3318 `read-command' converts a "command line" into a list of strings
3319 suitable for parsing by `getopt'. The syntax of command lines
3320 supported resembles that of popular "shell"s. `read-command'
3321 updates PORT to point to the first character past the command
3322 delimiter.
3323
3324 If an end of file is encountered in the input before any
3325 characters are found that can begin an object or comment, then an
3326 end of file object is returned.
3327
3328 The PORT argument may be omitted, in which case it defaults to the
3329 value returned by `current-input-port'.
3330
3331 The fields into which the command line is split are delimited by
3332 whitespace as defined by `char-whitespace?'. The end of a command
3333 is delimited by end-of-file or unescaped semicolon (<;>) or
3334 <newline>. Any character can be literally included in a field by
3335 escaping it with a backslach (<\>).
3336
3337 The initial character and types of fields recognized are:
3338 `\'
3339 The next character has is taken literally and not interpreted
3340 as a field delimiter. If <\> is the last character before a
3341 <newline>, that <newline> is just ignored. Processing
3342 continues from the characters after the <newline> as though
3343 the backslash and <newline> were not there.
3344
3345 `"'
3346 The characters up to the next unescaped <"> are taken
3347 literally, according to [R4RS] rules for literal strings
3348 (*note Strings: (r4rs)Strings.).
3349
3350 `(', `%''
3351 One scheme expression is `read' starting with this character.
3352 The `read' expression is evaluated, converted to a string
3353 (using `display'), and replaces the expression in the returned
3354 field.
3355
3356 `;'
3357 Semicolon delimits a command. Using semicolons more than one
3358 command can appear on a line. Escaped semicolons and
3359 semicolons inside strings do not delimit commands.
3360
3361 The comment field differs from the previous fields in that it must
3362 be the first character of a command or appear after whitespace in
3363 order to be recognized. <#> can be part of fields if these
3364 conditions are not met. For instance, `ab#c' is just the field
3365 ab#c.
3366
3367 `#'
3368 Introduces a comment. The comment continues to the end of
3369 the line on which the semicolon appears. Comments are
3370 treated as whitespace by `read-dommand-line' and backslashes
3371 before <newline>s in comments are also ignored.
3372
3373 - Function: read-options-file filename
3374 `read-options-file' converts an "options file" into a list of
3375 strings suitable for parsing by `getopt'. The syntax of options
3376 files is the same as the syntax for command lines, except that
3377 <newline>s do not terminate reading (only <;> or end of file).
3378
3379 If an end of file is encountered before any characters are found
3380 that can begin an object or comment, then an end of file object is
3381 returned.
3382
3383 \1f
3384 File: slib.info, Node: Parameter lists, Next: Getopt Parameter lists, Prev: Command Line, Up: Programs and Arguments
3385
3386 Parameter lists
3387 ---------------
3388
3389 `(require 'parameters)'
3390
3391 Arguments to procedures in scheme are distinguished from each other by
3392 their position in the procedure call. This can be confusing when a
3393 procedure takes many arguments, many of which are not often used.
3394
3395 A "parameter-list" is a way of passing named information to a
3396 procedure. Procedures are also defined to set unused parameters to
3397 default values, check parameters, and combine parameter lists.
3398
3399 A PARAMETER has the form `(parameter-name value1 ...)'. This format
3400 allows for more than one value per parameter-name.
3401
3402 A PARAMETER-LIST is a list of PARAMETERs, each with a different
3403 PARAMETER-NAME.
3404
3405 - Function: make-parameter-list parameter-names
3406 Returns an empty parameter-list with slots for PARAMETER-NAMES.
3407
3408 - Function: parameter-list-ref parameter-list parameter-name
3409 PARAMETER-NAME must name a valid slot of PARAMETER-LIST.
3410 `parameter-list-ref' returns the value of parameter PARAMETER-NAME
3411 of PARAMETER-LIST.
3412
3413 - Function: remove-parameter parameter-name parameter-list
3414 Removes the parameter PARAMETER-NAME from PARAMETER-LIST.
3415 `remove-parameter' does not alter the argument PARAMETER-LIST.
3416
3417 If there are more than one PARAMETER-NAME parameters, an error is
3418 signaled.
3419
3420 - Procedure: adjoin-parameters! parameter-list parameter1 ...
3421 Returns PARAMETER-LIST with PARAMETER1 ... merged in.
3422
3423 - Procedure: parameter-list-expand expanders parameter-list
3424 EXPANDERS is a list of procedures whose order matches the order of
3425 the PARAMETER-NAMEs in the call to `make-parameter-list' which
3426 created PARAMETER-LIST. For each non-false element of EXPANDERS
3427 that procedure is mapped over the corresponding parameter value
3428 and the returned parameter lists are merged into PARAMETER-LIST.
3429
3430 This process is repeated until PARAMETER-LIST stops growing. The
3431 value returned from `parameter-list-expand' is unspecified.
3432
3433 - Function: fill-empty-parameters defaulters parameter-list
3434 DEFAULTERS is a list of procedures whose order matches the order
3435 of the PARAMETER-NAMEs in the call to `make-parameter-list' which
3436 created PARAMETER-LIST. `fill-empty-parameters' returns a new
3437 parameter-list with each empty parameter replaced with the list
3438 returned by calling the corresponding DEFAULTER with
3439 PARAMETER-LIST as its argument.
3440
3441 - Function: check-parameters checks parameter-list
3442 CHECKS is a list of procedures whose order matches the order of
3443 the PARAMETER-NAMEs in the call to `make-parameter-list' which
3444 created PARAMETER-LIST.
3445
3446 `check-parameters' returns PARAMETER-LIST if each CHECK of the
3447 corresponding PARAMETER-LIST returns non-false. If some CHECK
3448 returns `#f' a warning is signaled. |
3449
3450 In the following procedures ARITIES is a list of symbols. The elements
3451 of `arities' can be:
3452
3453 `single'
3454 Requires a single parameter.
3455
3456 `optional'
3457 A single parameter or no parameter is acceptable.
3458
3459 `boolean'
3460 A single boolean parameter or zero parameters is acceptable.
3461
3462 `nary'
3463 Any number of parameters are acceptable.
3464
3465 `nary1'
3466 One or more of parameters are acceptable.
3467
3468 - Function: parameter-list->arglist positions arities parameter-list |
3469 Returns PARAMETER-LIST converted to an argument list. Parameters
3470 of ARITY type `single' and `boolean' are converted to the single
3471 value associated with them. The other ARITY types are converted
3472 to lists of the value(s). |
3473
3474 POSITIONS is a list of positive integers whose order matches the
3475 order of the PARAMETER-NAMEs in the call to `make-parameter-list'
3476 which created PARAMETER-LIST. The integers specify in which
3477 argument position the corresponding parameter should appear.
3478
3479 \1f
3480 File: slib.info, Node: Getopt Parameter lists, Next: Filenames, Prev: Parameter lists, Up: Programs and Arguments
3481
3482 Getopt Parameter lists
3483 ----------------------
3484
3485 `(require 'getopt-parameters)'
3486
3487 - Function: getopt->parameter-list argc argv optnames arities types
3488 aliases desc ... |
3489 Returns ARGV converted to a parameter-list. OPTNAMES are the
3490 parameter-names. ARITIES and TYPES are lists of symbols |
3491 corresponding to OPTNAMES. |
3492 |
3493 ALIASES is a list of lists of strings or integers paired with |
3494 elements of OPTNAMES. Each one-character string will be treated |
3495 as a single `-' option by `getopt'. Longer strings will be |
3496 treated as long-named options (*note getopt-: Getopt.). |
3497 |
3498 If the ALIASES association list has only strings as its `car's, |
3499 then all the option-arguments after an option (and before the next |
3500 option) are adjoined to that option. |
3501 |
3502 If the ALIASES association list has integers, then each (string) |
3503 option will take at most one option-argument. Unoptioned |
3504 arguments are collected in a list. A `-1' alias will take the |
3505 last argument in this list; `+1' will take the first argument in |
3506 the list. The aliases -2 then +2; -3 then +3; ... are tried so |
3507 long as a positive or negative consecutive alias is found and |
3508 arguments remain in the list. Finally a `0' alias, if found, |
3509 absorbs any remaining arguments. |
3510 |
3511 In all cases, if unclaimed arguments remain after processing, a |
3512 warning is signaled and #f is returned. |
3513
3514 - Function: getopt->arglist argc argv optnames positions arities types
3515 defaulters checks aliases desc ... |
3516 Like `getopt->parameter-list', but converts ARGV to an
3517 argument-list as specified by OPTNAMES, POSITIONS, ARITIES, TYPES,
3518 DEFAULTERS, CHECKS, and ALIASES. If the options supplied violate |
3519 the ARITIES or CHECKS constraints, then a warning is signaled and |
3520 #f is returned. |
3521
3522 These `getopt' functions can be used with SLIB relational databases.
3523 For an example, *Note make-command-server: Database Utilities.
3524
3525 If errors are encountered while processing options, directions for using
3526 the options (and argument strings DESC ...) are printed to |
3527 `current-error-port'. |
3528
3529 (begin
3530 (set! *optind* 1)
3531 (getopt->parameter-list
3532 2
3533 '("cmd" "-?")
3534 '(flag number symbols symbols string flag2 flag3 num2 num3)
3535 '(boolean optional nary1 nary single boolean boolean nary nary)
3536 '(boolean integer symbol symbol string boolean boolean integer integer)
3537 '(("flag" flag)
3538 ("f" flag)
3539 ("Flag" flag2)
3540 ("B" flag3)
3541 ("optional" number)
3542 ("o" number)
3543 ("nary1" symbols)
3544 ("N" symbols)
3545 ("nary" symbols)
3546 ("n" symbols)
3547 ("single" string)
3548 ("s" string)
3549 ("a" num2)
3550 ("Abs" num3))))
3551 -|
3552 Usage: cmd [OPTION ARGUMENT ...] ...
3553
3554 -f, --flag
3555 -o, --optional=<number>
3556 -n, --nary=<symbols> ...
3557 -N, --nary1=<symbols> ...
3558 -s, --single=<string>
3559 --Flag
3560 -B
3561 -a <num2> ...
3562 --Abs=<num3> ...
3563
3564 ERROR: getopt->parameter-list "unrecognized option" "-?"
3565
3566 \1f
3567 File: slib.info, Node: Filenames, Next: Batch, Prev: Getopt Parameter lists, Up: Programs and Arguments
3568
3569 Filenames
3570 ---------
3571
3572 `(require 'filename)' or `(require 'glob)'
3573
3574 - Function: filename:match?? pattern
3575 - Function: filename:match-ci?? pattern
3576 Returns a predicate which returns a non-false value if its string
3577 argument matches (the string) PATTERN, false otherwise. Filename
3578 matching is like "glob" expansion described the bash manpage,
3579 except that names beginning with `.' are matched and `/'
3580 characters are not treated specially.
3581
3582 These functions interpret the following characters specially in
3583 PATTERN strings:
3584 `*'
3585 Matches any string, including the null string.
3586
3587 `?'
3588 Matches any single character.
3589
3590 `[...]'
3591 Matches any one of the enclosed characters. A pair of
3592 characters separated by a minus sign (-) denotes a range; any
3593 character lexically between those two characters, inclusive,
3594 is matched. If the first character following the `[' is a
3595 `!' or a `^' then any character not enclosed is matched. A
3596 `-' or `]' may be matched by including it as the first or
3597 last character in the set.
3598
3599
3600 - Function: filename:substitute?? pattern template
3601 - Function: filename:substitute-ci?? pattern template
3602 Returns a function transforming a single string argument according
3603 to glob patterns PATTERN and TEMPLATE. PATTERN and TEMPLATE must
3604 have the same number of wildcard specifications, which need not be
3605 identical. PATTERN and TEMPLATE may have a different number of
3606 literal sections. If an argument to the function matches PATTERN
3607 in the sense of `filename:match??' then it returns a copy of
3608 TEMPLATE in which each wildcard specification is replaced by the
3609 part of the argument matched by the corresponding wildcard
3610 specification in PATTERN. A `*' wildcard matches the longest
3611 leftmost string possible. If the argument does not match PATTERN
3612 then false is returned.
3613
3614 TEMPLATE may be a function accepting the same number of string
3615 arguments as there are wildcard specifications in PATTERN. In the
3616 case of a match the result of applying TEMPLATE to a list of the
3617 substrings matched by wildcard specifications will be returned,
3618 otherwise TEMPLATE will not be called and `#f' will be returned.
3619
3620 ((filename:substitute?? "scm_[0-9]*.html" "scm5c4_??.htm")
3621 "scm_10.html")
3622 => "scm5c4_10.htm"
3623 ((filename:substitute?? "??" "beg?mid?end") "AZ")
3624 => "begAmidZend"
3625 ((filename:substitute?? "*na*" "?NA?") "banana")
3626 => "banaNA"
3627 ((filename:substitute?? "?*?" (lambda (s1 s2 s3) (string-append s3 s1))) "ABZ")
3628 => "ZA"
3629
3630 - Function: replace-suffix str old new
3631 STR can be a string or a list of strings. Returns a new string
3632 (or strings) similar to `str' but with the suffix string OLD
3633 removed and the suffix string NEW appended. If the end of STR
3634 does not match OLD, an error is signaled.
3635
3636 (replace-suffix "/usr/local/lib/slib/batch.scm" ".scm" ".c")
3637 => "/usr/local/lib/slib/batch.c"
3638
3639 \1f
3640 File: slib.info, Node: Batch, Prev: Filenames, Up: Programs and Arguments
3641
3642 Batch
3643 -----
3644
3645 `(require 'batch)'
3646
3647 The batch procedures provide a way to write and execute portable scripts
3648 for a variety of operating systems. Each `batch:' procedure takes as
3649 its first argument a parameter-list (*note Parameter lists::). This
3650 parameter-list argument PARMS contains named associations. Batch
3651 currently uses 2 of these:
3652
3653 `batch-port'
3654 The port on which to write lines of the batch file.
3655
3656 `batch-dialect'
3657 The syntax of batch file to generate. Currently supported are:
3658 * unix
3659
3660 * dos
3661
3662 * vms
3663
3664 * amigados
3665
3666 * system
3667
3668 * *unknown*
3669
3670 `batch.scm' uses 2 enhanced relational tables (*note Database
3671 Utilities::) to store information linking the names of
3672 `operating-system's to `batch-dialect'es.
3673
3674 - Function: batch:initialize! database
3675 Defines `operating-system' and `batch-dialect' tables and adds the
3676 domain `operating-system' to the enhanced relational database
3677 DATABASE.
3678
3679 - Variable: batch:platform
3680 Is batch's best guess as to which operating-system it is running
3681 under. `batch:platform' is set to `(software-type)' (*note
3682 Configuration::) unless `(software-type)' is `unix', in which case
3683 finer distinctions are made.
3684
3685 - Function: batch:call-with-output-script parms file proc
3686 PROC should be a procedure of one argument. If FILE is an
3687 output-port, `batch:call-with-output-script' writes an appropriate
3688 header to FILE and then calls PROC with FILE as the only argument.
3689 If FILE is a string, `batch:call-with-output-script' opens a
3690 output-file of name FILE, writes an appropriate header to FILE,
3691 and then calls PROC with the newly opened port as the only
3692 argument. Otherwise, `batch:call-with-output-script' acts as if
3693 it was called with the result of `(current-output-port)' as its
3694 third argument.
3695
3696 The rest of the `batch:' procedures write (or execute if
3697 `batch-dialect' is `system') commands to the batch port which has been
3698 added to PARMS or `(copy-tree PARMS)' by the code:
3699
3700 (adjoin-parameters! PARMS (list 'batch-port PORT))
3701
3702 - Function: batch:command parms string1 string2 ...
3703 Calls `batch:try-command' (below) with arguments, but signals an
3704 error if `batch:try-command' returns `#f'.
3705
3706 These functions return a non-false value if the command was successfully
3707 translated into the batch dialect and `#f' if not. In the case of the
3708 `system' dialect, the value is non-false if the operation suceeded.
3709
3710 - Function: batch:try-command parms string1 string2 ...
3711 Writes a command to the `batch-port' in PARMS which executes the
3712 program named STRING1 with arguments STRING2 ....
3713
3714 - Function: batch:try-chopped-command parms arg1 arg2 ... list
3715 breaks the last argument LIST into chunks small enough so that the
3716 command:
3717
3718 ARG1 ARG2 ... CHUNK
3719
3720 fits withing the platform's maximum command-line length.
3721
3722 `batch:try-chopped-command' calls `batch:try-command' with the
3723 command and returns non-false only if the commands all fit and
3724 `batch:try-command' of each command line returned non-false.
3725
3726 - Function: batch:run-script parms string1 string2 ...
3727 Writes a command to the `batch-port' in PARMS which executes the
3728 batch script named STRING1 with arguments STRING2 ....
3729
3730 _Note:_ `batch:run-script' and `batch:try-command' are not the
3731 same for some operating systems (VMS).
3732
3733 - Function: batch:comment parms line1 ...
3734 Writes comment lines LINE1 ... to the `batch-port' in PARMS.
3735
3736 - Function: batch:lines->file parms file line1 ...
3737 Writes commands to the `batch-port' in PARMS which create a file
3738 named FILE with contents LINE1 ....
3739
3740 - Function: batch:delete-file parms file
3741 Writes a command to the `batch-port' in PARMS which deletes the
3742 file named FILE.
3743
3744 - Function: batch:rename-file parms old-name new-name
3745 Writes a command to the `batch-port' in PARMS which renames the
3746 file OLD-NAME to NEW-NAME.
3747
3748 In addition, batch provides some small utilities very useful for writing
3749 scripts:
3750
3751 - Function: truncate-up-to path char
3752 - Function: truncate-up-to path string
3753 - Function: truncate-up-to path charlist
3754 PATH can be a string or a list of strings. Returns PATH sans any
3755 prefixes ending with a character of the second argument. This can
3756 be used to derive a filename moved locally from elsewhere.
3757
3758 (truncate-up-to "/usr/local/lib/slib/batch.scm" "/")
3759 => "batch.scm"
3760
3761 - Function: string-join joiner string1 ...
3762 Returns a new string consisting of all the strings STRING1 ... in
3763 order appended together with the string JOINER between each
3764 adjacent pair.
3765
3766 - Function: must-be-first list1 list2
3767 Returns a new list consisting of the elements of LIST2 ordered so
3768 that if some elements of LIST1 are `equal?' to elements of LIST2,
3769 then those elements will appear first and in the order of LIST1.
3770
3771 - Function: must-be-last list1 list2
3772 Returns a new list consisting of the elements of LIST1 ordered so
3773 that if some elements of LIST2 are `equal?' to elements of LIST1,
3774 then those elements will appear last and in the order of LIST2.
3775
3776 - Function: os->batch-dialect osname
3777 Returns its best guess for the `batch-dialect' to be used for the
3778 operating-system named OSNAME. `os->batch-dialect' uses the
3779 tables added to DATABASE by `batch:initialize!'.
3780
3781 Here is an example of the use of most of batch's procedures:
3782
3783 (require 'database-utilities)
3784 (require 'parameters)
3785 (require 'batch)
3786 (require 'glob)
3787
3788 (define batch (create-database #f 'alist-table))
3789 (batch:initialize! batch)
3790
3791 (define my-parameters
3792 (list (list 'batch-dialect (os->batch-dialect batch:platform))
3793 (list 'platform batch:platform)
3794 (list 'batch-port (current-output-port)))) ;gets filled in later
3795
3796 (batch:call-with-output-script
3797 my-parameters
3798 "my-batch"
3799 (lambda (batch-port)
3800 (adjoin-parameters! my-parameters (list 'batch-port batch-port))
3801 (and
3802 (batch:comment my-parameters
3803 "================ Write file with C program.")
3804 (batch:rename-file my-parameters "hello.c" "hello.c~")
3805 (batch:lines->file my-parameters "hello.c"
3806 "#include <stdio.h>"
3807 "int main(int argc, char **argv)"
3808 "{"
3809 " printf(\"hello world\\n\");"
3810 " return 0;"
3811 "}" )
3812 (batch:command my-parameters "cc" "-c" "hello.c")
3813 (batch:command my-parameters "cc" "-o" "hello"
3814 (replace-suffix "hello.c" ".c" ".o"))
3815 (batch:command my-parameters "hello")
3816 (batch:delete-file my-parameters "hello")
3817 (batch:delete-file my-parameters "hello.c")
3818 (batch:delete-file my-parameters "hello.o")
3819 (batch:delete-file my-parameters "my-batch")
3820 )))
3821
3822 Produces the file `my-batch':
3823
3824 #!/bin/sh
3825 # "my-batch" script created by SLIB/batch Sun Oct 31 18:24:10 1999
3826 # ================ Write file with C program.
3827 mv -f hello.c hello.c~
3828 rm -f hello.c
3829 echo '#include <stdio.h>'>>hello.c
3830 echo 'int main(int argc, char **argv)'>>hello.c
3831 echo '{'>>hello.c
3832 echo ' printf("hello world\n");'>>hello.c
3833 echo ' return 0;'>>hello.c
3834 echo '}'>>hello.c
3835 cc -c hello.c
3836 cc -o hello hello.o
3837 hello
3838 rm -f hello
3839 rm -f hello.c
3840 rm -f hello.o
3841 rm -f my-batch
3842
3843 When run, `my-batch' prints:
3844
3845 bash$ my-batch
3846 mv: hello.c: No such file or directory
3847 hello world
3848
3849 \1f
3850 File: slib.info, Node: HTML, Next: HTML Tables, Prev: Programs and Arguments, Up: Textual Conversion Packages
3851
3852 HTML
3853 ====
3854
3855 `(require 'html-form)'
3856
3857 - Function: html:atval txt
3858 Returns a string with character substitutions appropriate to send
3859 TXT as an "attribute-value".
3860
3861 - Function: html:plain txt
3862 Returns a string with character substitutions appropriate to send
3863 TXT as an "plain-text".
3864
3865 - Function: html:meta name content |
3866 Returns a tag of meta-information suitable for passing as the |
3867 third argument to `html:head'. The tag produced is `<META |
3868 NAME="NAME" CONTENT="CONTENT">'. The string or symbol NAME can be |
3869 `author', `copyright', `keywords', `description', `date', |
3870 `robots', .... |
3871 |
3872 - Function: html:http-equiv name content |
3873 Returns a tag of HTTP information suitable for passing as the |
3874 third argument to `html:head'. The tag produced is `<META |
3875 HTTP-EQUIV="NAME" CONTENT="CONTENT">'. The string or symbol NAME |
3876 can be `Expires', `PICS-Label', `Content-Type', `Refresh', .... |
3877 |
3878 - Function: html:meta-refresh delay uri |
3879 - Function: html:meta-refresh delay |
3880 Returns a tag suitable for passing as the third argument to |
3881 `html:head'. If URI argument is supplied, then DELAY seconds after |
3882 displaying the page with this tag, Netscape or IE browsers will |
3883 fetch and display URI. Otherwise, DELAY seconds after displaying |
3884 the page with this tag, Netscape or IE browsers will fetch and |
3885 redisplay this page. |
3886 |
3887 - Function: html:head title backlink tags ...
3888 - Function: html:head title backlink
3889 - Function: html:head title
3890 Returns header string for an HTML page named TITLE. If BACKLINK |
3891 is a string, it is used verbatim between the `H1' tags; otherwise |
3892 TITLE is used. If string arguments TAGS ... are supplied, then |
3893 they are included verbatim within the <HEAD> section. |
3894
3895 - Function: html:body body ...
3896 Returns HTML string to end a page.
3897
3898 - Function: html:pre line1 line ...
3899 Returns the strings LINE1, LINES as "PRE"formmated plain text
3900 (rendered in fixed-width font). Newlines are inserted between
3901 LINE1, LINES. HTML tags (`<tag>') within LINES will be visible
3902 verbatim.
3903
3904 - Function: html:comment line1 line ...
3905 Returns the strings LINE1 as HTML comments.
3906
3907 HTML Forms
3908 ==========
3909
3910 - Function: html:form method action body ... |
3911 The symbol METHOD is either `get', `head', `post', `put', or
3912 `delete'. The strings BODY form the body of the form. |
3913 `html:form' returns the HTML "form".
3914
3915 - Function: html:hidden name value |
3916 Returns HTML string which will cause NAME=VALUE in form. |
3917 |
3918 - Function: html:checkbox pname default |
3919 Returns HTML string for check box. |
3920 |
3921 - Function: html:text pname default size ... |
3922 Returns HTML string for one-line text box. |
3923 |
3924 - Function: html:text-area pname default-list |
3925 Returns HTML string for multi-line text box. |
3926 |
3927 - Function: html:select pname arity default-list foreign-values |
3928 Returns HTML string for pull-down menu selector. |
3929 |
3930 - Function: html:buttons pname arity default-list foreign-values |
3931 Returns HTML string for any-of selector. |
3932 |
3933 - Function: form:submit submit-label command |
3934 - Function: form:submit submit-label |
3935 The string or symbol SUBMIT-LABEL appears on the button which |
3936 submits the form. If the optional second argument COMMAND is |
3937 given, then `*command*=COMMAND' and `*button*=SUBMIT-LABEL' are |
3938 set in the query. Otherwise, `*command*=SUBMIT-LABEL' is set in |
3939 the query. |
3940 |
3941 - Function: form:image submit-label image-src |
3942 The IMAGE-SRC appears on the button which submits the form. |
3943 |
3944 - Function: form:reset |
3945 Returns a string which generates a "reset" button. |
3946 |
3947 - Function: form:element pname arity default-list foreign-values |
3948 Returns a string which generates an INPUT element for the field |
3949 named PNAME. The element appears in the created form with its |
3950 representation determined by its ARITY and domain. For domains |
3951 which are foreign-keys: |
3952 |
3953 `single' |
3954 select menu |
3955 |
3956 `optional' |
3957 select menu |
3958 |
3959 `nary' |
3960 check boxes |
3961 |
3962 `nary1' |
3963 check boxes |
3964 |
3965 If the foreign-key table has a field named `visible-name', then |
3966 the contents of that field are the names visible to the user for |
3967 those choices. Otherwise, the foreign-key itself is visible. |
3968 |
3969 For other types of domains: |
3970 |
3971 `single' |
3972 text area |
3973 |
3974 `optional' |
3975 text area |
3976 |
3977 `boolean' |
3978 check box |
3979 |
3980 `nary' |
3981 text area |
3982 |
3983 `nary1' |
3984 text area |
3985 |
3986 - Function: form:delimited pname doc aliat arity default-list |
3987 foreign-values |
3988 Returns a HTML string for a form element embedded in a line of a |
3989 delimited list. Apply map `form:delimited' to the list returned by |
3990 `command->p-specs'. |
3991 |
3992 - Function: command->p-specs rdb command-table command |
3993 The symbol COMMAND-TABLE names a command table in the RDB
3994 relational database. The symbol COMMAND names a key in |
3995 COMMAND-TABLE. |
3996
3997 `command->p-specs' returns a list of lists of PNAME, DOC, ALIAT, |
3998 ARITY, DEFAULT-LIST, and FOREIGN-VALUES. The returned list has |
3999 one element for each parameter of command COMMAND. |
4000
4001 This example demonstrates how to create a HTML-form for the `build'
4002 command.
4003
4004 (require (in-vicinity (implementation-vicinity) "build.scm"))
4005 (call-with-output-file "buildscm.html"
4006 (lambda (port)
4007 (display
4008 (string-append
4009 (html:head 'commands)
4010 (html:body
4011 (sprintf #f "<H2>%s:</H2><BLOCKQUOTE>%s</BLOCKQUOTE>\\n" |
4012 (html:plain 'build) |
4013 (html:plain ((comtab 'get 'documentation) 'build))) |
4014 (html:form |
4015 'post |
4016 (or "http://localhost:8081/buildscm" "/cgi-bin/build.cgi") |
4017 (apply html:delimited-list |
4018 (apply map form:delimited |
4019 (command->p-specs build '*commands* 'build))) |
4020 (form:submit 'build) |
4021 (form:reset)))) |
4022 port)))
4023
4024 \1f
4025 File: slib.info, Node: HTML Tables, Next: HTTP and CGI, Prev: HTML, Up: Textual Conversion Packages
4026
4027 HTML Tables
4028 ===========
4029
4030 `(require 'db->html)'
4031
4032 - Function: html:table options row ... |
4033 |
4034 - Function: html:caption caption align |
4035 - Function: html:caption caption |
4036 ALIGN can be `top' or `bottom'. |
4037
4038 - Function: html:heading columns
4039 Outputs a heading row for the currently-started table.
4040
4041 - Function: html:href-heading columns uris |
4042 Outputs a heading row with column-names COLUMNS linked to URIs |
4043 URIS. |
4044
4045 - Function: html:linked-row-converter k foreigns |
4046 The positive integer K is the primary-key-limit (number of
4047 primary-keys) of the table. FOREIGNS is a list of the filenames of
4048 foreign-key field pages and #f for non foreign-key fields.
4049
4050 `html:linked-row-converter' returns a procedure taking a row for |
4051 its single argument. This returned procedure returns the html |
4052 string for that table row. |
4053
4054 - Function: table-name->filename table-name
4055 Returns the symbol TABLE-NAME converted to a filename.
4056
4057 - Function: table->linked-html caption db table-name match-key1 ... |
4058 Returns HTML string for DB table TABLE-NAME. Every foreign-key |
4059 value is linked to the page (of the table) defining that key. |
4060
4061 The optional MATCH-KEY1 ... arguments restrict actions to a subset
4062 of the table. *Note match-key: Table Operations.
4063
4064 - Function: table->linked-page db table-name index-filename arg ... |
4065 Returns a complete HTML page. The string INDEX-FILENAME names the
4066 page which refers to this one.
4067
4068 The optional ARGS ... arguments restrict actions to a subset of
4069 the table. *Note match-key: Table Operations.
4070
4071 - Function: catalog->html db caption arg ...
4072 Returns HTML string for the catalog table of DB.
4073
4074 HTML editing tables |
4075 ------------------- |
4076 |
4077 A client can modify one row of an editable table at a time. For any |
4078 change submitted, these routines check if that row has been modified |
4079 during the time the user has been editing the form. If so, an error |
4080 page results. |
4081 |
4082 The behavior of edited rows is: |
4083 |
4084 * If no fields are changed, then no change is made to the table. |
4085 |
4086 * If the primary keys equal null-keys (parameter defaults), and no |
4087 other user has modified that row, then that row is deleted. |
4088 |
4089 * If only primary keys are changed, there are non-key fields, and no |
4090 row with the new keys is in the table, then the old row is deleted |
4091 and one with the new keys is inserted. |
4092 |
4093 * If only non-key fields are changed, and that row has not been |
4094 modified by another user, then the row is changed to reflect the |
4095 fields. |
4096 |
4097 * If both keys and non-key fields are changed, and no row with the |
4098 new keys is in the table, then a row is created with the new keys |
4099 and fields. |
4100 |
4101 * If fields are changed, all fields are primary keys, and no row with |
4102 the new keys is in the table, then a row is created with the new |
4103 keys. |
4104 |
4105 After any change to the table, a `sync-database' of the database is |
4106 performed. |
4107 |
4108 - Function: command:modify-table table-name null-keys update delete |
4109 retrieve |
4110 - Function: command:modify-table table-name null-keys update delete |
4111 - Function: command:modify-table table-name null-keys update |
4112 - Function: command:modify-table table-name null-keys |
4113 Returns procedure (of DB) which returns procedure to modify row of |
4114 TABLE-NAME. NULL-KEYS is the list of "null" keys which indicate |
4115 that the row is to be deleted. Optional arguments UPDATE, DELETE, |
4116 and RETRIEVE default to the `row:update', `row:delete', and |
4117 `row:retrieve' of TABLE-NAME in DB. |
4118 |
4119 - Function: command:make-editable-table rdb table-name arg ... |
4120 Given TABLE-NAME in RDB, creates parameter and `*command*' tables |
4121 for editing one row of TABLE-NAME at a time. |
4122 `command:make-editable-table' returns a procedure taking a row |
4123 argument which returns the HTML string for editing that row. |
4124 |
4125 Optional ARGS are expressions (lists) added to the call to |
4126 `command:modify-table'. |
4127 |
4128 The domain name of a column determines the expected arity of the |
4129 data stored in that column. Domain names ending in: |
4130 |
4131 `*' |
4132 have arity `nary'; |
4133 |
4134 `+' |
4135 have arity `nary1'. |
4136 |
4137 - Function: html:editable-row-converter k names edit-point |
4138 edit-converter |
4139 The positive integer K is the primary-key-limit (number of |
4140 primary-keys) of the table. NAMES is a list of the field-names. |
4141 EDIT-POINT is the list of primary-keys denoting the row to edit |
4142 (or #f). EDIT-CONVERTER is the procedure called with K, NAMES, |
4143 and the row to edit. |
4144 |
4145 `html:editable-row-converter' returns a procedure taking a row for |
4146 its single argument. This returned procedure returns the html |
4147 string for that table row. |
4148 |
4149 Each HTML table constructed using `html:editable-row-converter' |
4150 has first K fields (typically the primary key fields) of each row |
4151 linked to a text encoding of these fields (the result of calling |
4152 `row->anchor'). The page so referenced typically allows the user |
4153 to edit fields of that row. |
4154
4155 HTML databases
4156 --------------
4157
4158 - Function: db->html-files db dir index-filename caption |
4159 DB must be a relational database. DIR must be #f or a non-empty
4160 string naming an existing sub-directory of the current directory.
4161
4162 `db->html-files' creates an html page for each table in the |
4163 database DB in the sub-directory named DIR, or the current |
4164 directory if DIR is #f. The top level page with the catalog of |
4165 tables (captioned CAPTION) is written to a file named |
4166 INDEX-FILENAME. |
4167
4168 - Function: db->html-directory db dir index-filename |
4169 - Function: db->html-directory db dir |
4170 DB must be a relational database. DIR must be a non-empty string
4171 naming an existing sub-directory of the current directory or one
4172 to be created. The optional string INDEX-FILENAME names the
4173 filename of the top page, which defaults to `index.html'.
4174
4175 `db->html-directory' creates sub-directory DIR if neccessary, and |
4176 calls `(db->html-files DB DIR INDEX-FILENAME DIR)'. The `file:' |
4177 URI of INDEX-FILENAME is returned. |
4178
4179 - Function: db->netscape db dir index-filename
4180 - Function: db->netscape db dir
4181 `db->netscape' is just like `db->html-directory', but calls |
4182 `browse-url-netscape' with the uri for the top page after the |
4183 pages are created.
4184
4185 \1f
4186 File: slib.info, Node: HTTP and CGI, Next: URI, Prev: HTML Tables, Up: Textual Conversion Packages
4187 |
4188 HTTP and CGI
4189 ============
4190
4191 `(require 'http)' or `(require 'cgi)'
4192 |
4193 - Function: http:header alist
4194 Returns a string containing lines for each element of ALIST; the
4195 `car' of which is followed by `: ', then the `cdr'.
4196
4197 - Function: http:content alist body ...
4198 Returns the concatenation of strings BODY with the `(http:header
4199 ALIST)' and the `Content-Length' prepended.
4200
4201 - Variable: *http:byline*
4202 String appearing at the bottom of error pages.
4203
4204 - Function: http:error-page status-code reason-phrase html-string ...
4205 STATUS-CODE and REASON-PHRASE should be an integer and string as
4206 specified in `RFC 2068'. The returned page (string) will show the
4207 STATUS-CODE and REASON-PHRASE and any additional HTML-STRINGS ...;
4208 with *HTTP:BYLINE* or SLIB's default at the bottom.
4209
4210 - Function: http:forwarding-page title delay uri html-string ... |
4211 The string or symbol TITLE is the page title. DELAY is a |
4212 non-negative integer. The HTML-STRINGS ... are typically used to |
4213 explain to the user why this page is being forwarded. |
4214 |
4215 `http:forwarding-page' returns an HTML string for a page which |
4216 automatically forwards to URI after DELAY seconds. The returned |
4217 page (string) contains any HTML-STRINGS ... followed by a manual |
4218 link to URI, in case the browser does not forward automatically. |
4219 |
4220 - Function: http:serve-query serve-proc input-port output-port
4221 reads the "URI" and "query-string" from INPUT-PORT. If the query
4222 is a valid `"POST"' or `"GET"' query, then `http:serve-query' calls
4223 SERVE-PROC with three arguments, the REQUEST-LINE, QUERY-STRING,
4224 and HEADER-ALIST. Otherwise, `http:serve-query' calls SERVE-PROC
4225 with the REQUEST-LINE, #f, and HEADER-ALIST.
4226
4227 If SERVE-PROC returns a string, it is sent to OUTPUT-PORT. If
4228 SERVE-PROC returns a list, then an error page with number 525 and
4229 strings from the list. If SERVE-PROC returns #f, then a `Bad
4230 Request' (400) page is sent to OUTPUT-PORT.
4231
4232 Otherwise, `http:serve-query' replies (to OUTPUT-PORT) with
4233 appropriate HTML describing the problem.
4234
4235 This example services HTTP queries from PORT-NUMBER:
4236
4237 (define socket (make-stream-socket AF_INET 0))
4238 (and (socket:bind socket port-number) ; AF_INET INADDR_ANY
4239 (socket:listen socket 10) ; Queue up to 10 requests.
4240 (dynamic-wind
4241 (lambda () #f)
4242 (lambda ()
4243 (do ((port (socket:accept socket) (socket:accept socket)))
4244 (#f)
4245 (let ((iport (duplicate-port port "r"))
4246 (oport (duplicate-port port "w")))
4247 (http:serve-query build:serve iport oport)
4248 (close-port iport)
4249 (close-port oport))
4250 (close-port port)))
4251 (lambda () (close-port socket))))
4252
4253 - Function: cgi:serve-query serve-proc
4254 reads the "URI" and "query-string" from `(current-input-port)'.
4255 If the query is a valid `"POST"' or `"GET"' query, then
4256 `cgi:serve-query' calls SERVE-PROC with three arguments, the
4257 REQUEST-LINE, QUERY-STRING, and HEADER-ALIST. Otherwise,
4258 `cgi:serve-query' calls SERVE-PROC with the REQUEST-LINE, #f, and
4259 HEADER-ALIST.
4260
4261 If SERVE-PROC returns a string, it is sent to
4262 `(current-input-port)'. If SERVE-PROC returns a list, then an
4263 error page with number 525 and strings from the list. If
4264 SERVE-PROC returns #f, then a `Bad Request' (400) page is sent to
4265 `(current-input-port)'.
4266
4267 Otherwise, `cgi:serve-query' replies (to `(current-input-port)')
4268 with appropriate HTML describing the problem.
4269
4270 - Function: make-query-alist-command-server rdb command-table |
4271 - Function: make-query-alist-command-server rdb command-table #t |
4272 Returns a procedure of one argument. When that procedure is called
4273 with a QUERY-ALIST (as returned by `uri:decode-query', the value |
4274 of the `*command*' association will be the command invoked in |
4275 COMMAND-TABLE. If `*command*' is not in the QUERY-ALIST then the |
4276 value of `*suggest*' is tried. If neither name is in the |
4277 QUERY-ALIST, then the literal value `*default*' is tried in |
4278 COMMAND-TABLE. |
4279 |
4280 If optional third argument is non-false, then the command is called |
4281 with just the parameter-list; otherwise, command is called with the |
4282 arguments described in its table. |
4283 |
4284 \1f
4285 File: slib.info, Node: URI, Next: Printing Scheme, Prev: HTTP and CGI, Up: Textual Conversion Packages
4286 |
4287 URI |
4288 === |
4289 |
4290 `(require 'uri)' |
4291 |
4292 Implements "Uniform Resource Identifiers" (URI) as described in RFC |
4293 2396. |
4294 |
4295 - Function: make-uri |
4296 - Function: make-uri fragment |
4297 - Function: make-uri query fragment |
4298 - Function: make-uri path query fragment |
4299 - Function: make-uri authority path query fragment |
4300 - Function: make-uri scheme authority path query fragment |
4301 Returns a Uniform Resource Identifier string from component |
4302 arguments. |
4303 |
4304 - Function: html:anchor name |
4305 Returns a string which defines this location in the (HTML) file as |
4306 NAME. The hypertext `<A HREF="#NAME">' will link to this point. |
4307 |
4308 (html:anchor "(section 7)") |
4309 => |
4310 "<A NAME=\"(section%207)\"></A>" |
4311 |
4312 - Function: html:link uri highlighted |
4313 Returns a string which links the HIGHLIGHTED text to URI. |
4314 |
4315 (html:link (make-uri "(section 7)") "section 7") |
4316 => |
4317 "<A HREF=\"#(section%207)\">section 7</A>" |
4318 |
4319 - Function: html:base uri |
4320 Returns a string specifying the "base" URI of a document, for |
4321 inclusion in the HEAD of the document (*note head: HTML.). |
4322 |
4323 - Function: html:isindex prompt |
4324 Returns a string specifying the search PROMPT of a document, for |
4325 inclusion in the HEAD of the document (*note head: HTML.). |
4326 |
4327 - Function: uri->tree uri-reference base-tree ... |
4328 Returns a list of 5 elements corresponding to the parts (SCHEME |
4329 AUTHORITY PATH QUERY FRAGMENT) of string URI-REFERENCE. Elements |
4330 corresponding to absent parts are #f. |
4331 |
4332 The PATH is a list of strings. If the first string is empty, then |
4333 the path is absolute; otherwise relative. |
4334 |
4335 If the AUTHORITY component is a "Server-based Naming Authority", |
4336 then it is a list of the USERINFO, HOST, and PORT strings (or #f). |
4337 For other types of AUTHORITY components the AUTHORITY will be a |
4338 string. |
4339 |
4340 (uri->tree "http://www.ics.uci.edu/pub/ietf/uri/#Related") |
4341 => |
4342 (http "www.ics.uci.edu" ("" "pub" "ietf" "uri" "") #f "Related") |
4343 |
4344 `uric:' prefixes indicate procedures dealing with URI-components. |
4345 |
4346 - Function: uric:encode uri-component allows |
4347 Returns a copy of the string URI-COMPONENT in which all "unsafe" |
4348 octets (as defined in RFC 2396) have been `%' "escaped". |
4349 `uric:decode' decodes strings encoded by `uric:encode'. |
4350 |
4351 - Function: uric:decode uri-component |
4352 Returns a copy of the string URI-COMPONENT in which each `%' |
4353 escaped characters in URI-COMPONENT is replaced with the character |
4354 it encodes. This routine is useful for showing URI contents on |
4355 error pages. |
4356
4357 \1f
4358 File: slib.info, Node: Printing Scheme, Next: Time and Date, Prev: URI, Up: Textual Conversion Packages
4359 |
4360 Printing Scheme
4361 ===============
4362
4363 * Menu:
4364
4365 * Generic-Write:: 'generic-write
4366 * Object-To-String:: 'object->string
4367 * Pretty-Print:: 'pretty-print, 'pprint-file
4368
4369 \1f
4370 File: slib.info, Node: Generic-Write, Next: Object-To-String, Prev: Printing Scheme, Up: Printing Scheme
4371
4372 Generic-Write
4373 -------------
4374
4375 `(require 'generic-write)'
4376
4377 `generic-write' is a procedure that transforms a Scheme data value
4378 (or Scheme program expression) into its textual representation and
4379 prints it. The interface to the procedure is sufficiently general to
4380 easily implement other useful formatting procedures such as pretty
4381 printing, output to a string and truncated output.
4382
4383 - Procedure: generic-write obj display? width output
4384 OBJ
4385 Scheme data value to transform.
4386
4387 DISPLAY?
4388 Boolean, controls whether characters and strings are quoted.
4389
4390 WIDTH
4391 Extended boolean, selects format:
4392 #f
4393 single line format
4394
4395 integer > 0
4396 pretty-print (value = max nb of chars per line)
4397
4398 OUTPUT
4399 Procedure of 1 argument of string type, called repeatedly with
4400 successive substrings of the textual representation. This
4401 procedure can return `#f' to stop the transformation.
4402
4403 The value returned by `generic-write' is undefined.
4404
4405 Examples:
4406 (write obj) == (generic-write obj #f #f DISPLAY-STRING)
4407 (display obj) == (generic-write obj #t #f DISPLAY-STRING)
4408
4409 where
4410 DISPLAY-STRING ==
4411 (lambda (s) (for-each write-char (string->list s)) #t)
4412
4413 \1f
4414 File: slib.info, Node: Object-To-String, Next: Pretty-Print, Prev: Generic-Write, Up: Printing Scheme
4415
4416 Object-To-String
4417 ----------------
4418
4419 `(require 'object->string)'
4420
4421 - Function: object->string obj
4422 Returns the textual representation of OBJ as a string.
4423
4424 - Function: object->limited-string obj limit
4425 Returns the textual representation of OBJ as a string of length at
4426 most LIMIT.
4427
4428 \1f
4429 File: slib.info, Node: Pretty-Print, Prev: Object-To-String, Up: Printing Scheme
4430
4431 Pretty-Print
4432 ------------
4433
4434 `(require 'pretty-print)'
4435
4436 - Procedure: pretty-print obj
4437 - Procedure: pretty-print obj port
4438 `pretty-print's OBJ on PORT. If PORT is not specified,
4439 `current-output-port' is used.
4440
4441 Example:
4442 (pretty-print '((1 2 3 4 5) (6 7 8 9 10) (11 12 13 14 15)
4443 (16 17 18 19 20) (21 22 23 24 25)))
4444 -| ((1 2 3 4 5)
4445 -| (6 7 8 9 10)
4446 -| (11 12 13 14 15)
4447 -| (16 17 18 19 20)
4448 -| (21 22 23 24 25))
4449
4450 - Procedure: pretty-print->string obj |
4451 - Procedure: pretty-print->string obj width |
4452 Returns the string of OBJ `pretty-print'ed in WIDTH columns. If |
4453 WIDTH is not specified, `(output-port-width)' is used. |
4454 |
4455 Example: |
4456 (pretty-print->string '((1 2 3 4 5) (6 7 8 9 10) (11 12 13 14 15) |
4457 (16 17 18 19 20) (21 22 23 24 25))) |
4458 => |
4459 "((1 2 3 4 5) |
4460 (6 7 8 9 10) |
4461 (11 12 13 14 15) |
4462 (16 17 18 19 20) |
4463 (21 22 23 24 25)) |
4464 " |
4465 (pretty-print->string '((1 2 3 4 5) (6 7 8 9 10) (11 12 13 14 15) |
4466 (16 17 18 19 20) (21 22 23 24 25)) |
4467 16) |
4468 => |
4469 "((1 2 3 4 5) |
4470 (6 7 8 9 10) |
4471 (11 |
4472 12 |
4473 13 |
4474 14 |
4475 15) |
4476 (16 |
4477 17 |
4478 18 |
4479 19 |
4480 20) |
4481 (21 |
4482 22 |
4483 23 |
4484 24 |
4485 25)) |
4486 " |
4487 |
4488 `(require 'pprint-file)'
4489
4490 - Procedure: pprint-file infile
4491 - Procedure: pprint-file infile outfile
4492 Pretty-prints all the code in INFILE. If OUTFILE is specified,
4493 the output goes to OUTFILE, otherwise it goes to
4494 `(current-output-port)'.
4495
4496 - Function: pprint-filter-file infile proc outfile
4497 - Function: pprint-filter-file infile proc
4498 INFILE is a port or a string naming an existing file. Scheme
4499 source code expressions and definitions are read from the port (or
4500 file) and PROC is applied to them sequentially.
4501
4502 OUTFILE is a port or a string. If no OUTFILE is specified then
4503 `current-output-port' is assumed. These expanded expressions are
4504 then `pretty-print'ed to this port.
4505
4506 Whitepsace and comments (introduced by `;') which are not part of
4507 scheme expressions are reproduced in the output. This procedure
4508 does not affect the values returned by `current-input-port' and
4509 `current-output-port'.
4510
4511 `pprint-filter-file' can be used to pre-compile macro-expansion and
4512 thus can reduce loading time. The following will write into
4513 `exp-code.scm' the result of expanding all defmacros in `code.scm'.
4514 (require 'pprint-file)
4515 (require 'defmacroexpand)
4516 (defmacro:load "my-macros.scm")
4517 (pprint-filter-file "code.scm" defmacro:expand* "exp-code.scm")
4518
4519 \1f
4520 File: slib.info, Node: Time and Date, Next: Vector Graphics, Prev: Printing Scheme, Up: Textual Conversion Packages
4521
4522 Time and Date
4523 =============
4524
4525 * Menu:
4526
4527 * Time Zone::
4528 * Posix Time:: 'posix-time
4529 * Common-Lisp Time:: 'common-lisp-time
4530
4531 If `(provided? 'current-time)':
4532
4533 The procedures `current-time', `difftime', and `offset-time' deal with
4534 a "calendar time" datatype which may or may not be disjoint from other
4535 Scheme datatypes.
4536
4537 - Function: current-time
4538 Returns the time since 00:00:00 GMT, January 1, 1970, measured in
4539 seconds. Note that the reference time is different from the
4540 reference time for `get-universal-time' in *Note Common-Lisp
4541 Time::.
4542
4543 - Function: difftime caltime1 caltime0
4544 Returns the difference (number of seconds) between twe calendar
4545 times: CALTIME1 - CALTIME0. CALTIME0 may also be a number.
4546
4547 - Function: offset-time caltime offset
4548 Returns the calendar time of CALTIME offset by OFFSET number of
4549 seconds `(+ caltime offset)'.
4550
4551 \1f
4552 File: slib.info, Node: Time Zone, Next: Posix Time, Prev: Time and Date, Up: Time and Date
4553
4554 Time Zone
4555 ---------
4556
4557 (require 'time-zone)
4558
4559 - Data Format: TZ-string
4560 POSIX standards specify several formats for encoding time-zone
4561 rules.
4562
4563 :<pathname>
4564 If the first character of <pathname> is `/', then <pathname>
4565 specifies the absolute pathname of a tzfile(5) format
4566 time-zone file. Otherwise, <pathname> is interpreted as a
4567 pathname within TZFILE:VICINITY (/usr/lib/zoneinfo/) naming a
4568 tzfile(5) format time-zone file.
4569
4570 <std><offset>
4571 The string <std> consists of 3 or more alphabetic characters.
4572 <offset> specifies the time difference from GMT. The <offset>
4573 is positive if the local time zone is west of the Prime
4574 Meridian and negative if it is east. <offset> can be the
4575 number of hours or hours and minutes (and optionally seconds)
4576 separated by `:'. For example, `-4:30'.
4577
4578 <std><offset><dst>
4579 <dst> is the at least 3 alphabetic characters naming the local
4580 daylight-savings-time.
4581
4582 <std><offset><dst><doffset>
4583 <doffset> specifies the offset from the Prime Meridian when
4584 daylight-savings-time is in effect.
4585
4586 The non-tzfile formats can optionally be followed by transition
4587 times specifying the day and time when a zone changes from
4588 standard to daylight-savings and back again.
4589
4590 ,<date>/<time>,<date>/<time>
4591 The <time>s are specified like the <offset>s above, except
4592 that leading `+' and `-' are not allowed.
4593
4594 Each <date> has one of the formats:
4595
4596 J<day>
4597 specifies the Julian day with <day> between 1 and 365.
4598 February 29 is never counted and cannot be referenced.
4599
4600 <day>
4601 This specifies the Julian day with n between 0 and 365.
4602 February 29 is counted in leap years and can be
4603 specified.
4604
4605 M<month>.<week>.<day>
4606 This specifies day <day> (0 <= <day> <= 6) of week
4607 <week> (1 <= <week> <= 5) of month <month> (1 <= <month>
4608 <= 12). Week 1 is the first week in which day d occurs
4609 and week 5 is the last week in which day <day> occurs.
4610 Day 0 is a Sunday.
4611
4612
4613 - Data Type: time-zone
4614 is a datatype encoding how many hours from Greenwich Mean Time the
4615 local time is, and the "Daylight Savings Time" rules for changing
4616 it.
4617
4618 - Function: time-zone TZ-string
4619 Creates and returns a time-zone object specified by the string
4620 TZ-STRING. If `time-zone' cannot interpret TZ-STRING, `#f' is
4621 returned.
4622
4623 - Function: tz:params caltime tz
4624 TZ is a time-zone object. `tz:params' returns a list of three
4625 items:
4626 0. An integer. 0 if standard time is in effect for timezone TZ
4627 at CALTIME; 1 if daylight savings time is in effect for
4628 timezone TZ at CALTIME.
4629
4630 1. The number of seconds west of the Prime Meridian timezone TZ
4631 is at CALTIME.
4632
4633 2. The name for timezone TZ at CALTIME.
4634
4635 `tz:params' is unaffected by the default timezone; inquiries can be
4636 made of any timezone at any calendar time.
4637
4638
4639 The rest of these procedures and variables are provided for POSIX
4640 compatability. Because of shared state they are not thread-safe.
4641
4642 - Function: tzset
4643 Returns the default time-zone.
4644
4645 - Function: tzset tz
4646 Sets (and returns) the default time-zone to TZ.
4647
4648 - Function: tzset TZ-string
4649 Sets (and returns) the default time-zone to that specified by
4650 TZ-STRING.
4651
4652 `tzset' also sets the variables *TIMEZONE*, DAYLIGHT?, and TZNAME.
4653 This function is automatically called by the time conversion
4654 procedures which depend on the time zone (*note Time and Date::).
4655
4656 - Variable: *timezone*
4657 Contains the difference, in seconds, between Greenwich Mean Time
4658 and local standard time (for example, in the U.S. Eastern time
4659 zone (EST), timezone is 5*60*60). `*timezone*' is initialized by
4660 `tzset'.
4661
4662 - Variable: daylight?
4663 is `#t' if the default timezone has rules for "Daylight Savings
4664 Time". _Note:_ DAYLIGHT? does not tell you when Daylight Savings
4665 Time is in effect, just that the default zone sometimes has
4666 Daylight Savings Time.
4667
4668 - Variable: tzname
4669 is a vector of strings. Index 0 has the abbreviation for the
4670 standard timezone; If DAYLIGHT?, then index 1 has the abbreviation
4671 for the Daylight Savings timezone.
4672
4673 \1f
4674 File: slib.info, Node: Posix Time, Next: Common-Lisp Time, Prev: Time Zone, Up: Time and Date
4675
4676 Posix Time
4677 ----------
4678
4679 (require 'posix-time)
4680
4681 - Data Type: Calendar-Time
4682 is a datatype encapsulating time.
4683
4684 - Data Type: Coordinated Universal Time
4685 (abbreviated "UTC") is a vector of integers representing time:
4686
4687 0. seconds (0 - 61)
4688
4689 1. minutes (0 - 59)
4690
4691 2. hours since midnight (0 - 23)
4692
4693 3. day of month (1 - 31)
4694
4695 4. month (0 - 11). Note difference from
4696 `decode-universal-time'.
4697
4698 5. the number of years since 1900. Note difference from
4699 `decode-universal-time'.
4700
4701 6. day of week (0 - 6)
4702
4703 7. day of year (0 - 365)
4704
4705 8. 1 for daylight savings, 0 for regular time
4706
4707 - Function: gmtime caltime
4708 Converts the calendar time CALTIME to UTC and returns it.
4709
4710 - Function: localtime caltime tz
4711 Returns CALTIME converted to UTC relative to timezone TZ.
4712
4713 - Function: localtime caltime
4714 converts the calendar time CALTIME to a vector of integers
4715 expressed relative to the user's time zone. `localtime' sets the
4716 variable *TIMEZONE* with the difference between Coordinated
4717 Universal Time (UTC) and local standard time in seconds (*note
4718 tzset: Time Zone.).
4719
4720
4721 - Function: gmktime univtime
4722 Converts a vector of integers in GMT Coordinated Universal Time
4723 (UTC) format to a calendar time.
4724
4725 - Function: mktime univtime
4726 Converts a vector of integers in local Coordinated Universal Time
4727 (UTC) format to a calendar time.
4728
4729 - Function: mktime univtime tz
4730 Converts a vector of integers in Coordinated Universal Time (UTC)
4731 format (relative to time-zone TZ) to calendar time.
4732
4733 - Function: asctime univtime
4734 Converts the vector of integers CALTIME in Coordinated Universal
4735 Time (UTC) format into a string of the form `"Wed Jun 30 21:49:08
4736 1993"'.
4737
4738 - Function: gtime caltime
4739 - Function: ctime caltime
4740 - Function: ctime caltime tz
4741 Equivalent to `(asctime (gmtime CALTIME))', `(asctime (localtime
4742 CALTIME))', and `(asctime (localtime CALTIME TZ))', respectively.
4743
4744 \1f
4745 File: slib.info, Node: Common-Lisp Time, Prev: Posix Time, Up: Time and Date
4746
4747 Common-Lisp Time
4748 ----------------
4749
4750 - Function: get-decoded-time
4751 Equivalent to `(decode-universal-time (get-universal-time))'.
4752
4753 - Function: get-universal-time
4754 Returns the current time as "Universal Time", number of seconds
4755 since 00:00:00 Jan 1, 1900 GMT. Note that the reference time is
4756 different from `current-time'.
4757
4758 - Function: decode-universal-time univtime
4759 Converts UNIVTIME to "Decoded Time" format. Nine values are
4760 returned:
4761 0. seconds (0 - 61)
4762
4763 1. minutes (0 - 59)
4764
4765 2. hours since midnight
4766
4767 3. day of month
4768
4769 4. month (1 - 12). Note difference from `gmtime' and
4770 `localtime'.
4771
4772 5. year (A.D.). Note difference from `gmtime' and `localtime'.
4773
4774 6. day of week (0 - 6)
4775
4776 7. #t for daylight savings, #f otherwise
4777
4778 8. hours west of GMT (-24 - +24)
4779
4780 Notice that the values returned by `decode-universal-time' do not
4781 match the arguments to `encode-universal-time'.
4782
4783 - Function: encode-universal-time second minute hour date month year
4784 - Function: encode-universal-time second minute hour date month year
4785 time-zone
4786 Converts the arguments in Decoded Time format to Universal Time
4787 format. If TIME-ZONE is not specified, the returned time is
4788 adjusted for daylight saving time. Otherwise, no adjustment is
4789 performed.
4790
4791 Notice that the values returned by `decode-universal-time' do not
4792 match the arguments to `encode-universal-time'.
4793
4794 \1f
4795 File: slib.info, Node: Vector Graphics, Next: Schmooz, Prev: Time and Date, Up: Textual Conversion Packages
4796
4797 Vector Graphics
4798 ===============
4799
4800 * Menu:
4801
4802 * Tektronix Graphics Support::
4803
4804 \1f
4805 File: slib.info, Node: Tektronix Graphics Support, Prev: Vector Graphics, Up: Vector Graphics
4806
4807 Tektronix Graphics Support
4808 --------------------------
4809
4810 _Note:_ The Tektronix graphics support files need more work, and are
4811 not complete.
4812
4813 Tektronix 4000 Series Graphics
4814 ..............................
4815
4816 The Tektronix 4000 series graphics protocol gives the user a 1024 by
4817 1024 square drawing area. The origin is in the lower left corner of the
4818 screen. Increasing y is up and increasing x is to the right.
4819
4820 The graphics control codes are sent over the current-output-port and
4821 can be mixed with regular text and ANSI or other terminal control
4822 sequences.
4823
4824 - Procedure: tek40:init
4825
4826 - Procedure: tek40:graphics
4827
4828 - Procedure: tek40:text
4829
4830 - Procedure: tek40:linetype linetype
4831
4832 - Procedure: tek40:move x y
4833
4834 - Procedure: tek40:draw x y
4835
4836 - Procedure: tek40:put-text x y str
4837
4838 - Procedure: tek40:reset
4839
4840 Tektronix 4100 Series Graphics
4841 ..............................
4842
4843 The graphics control codes are sent over the current-output-port and
4844 can be mixed with regular text and ANSI or other terminal control
4845 sequences.
4846
4847 - Procedure: tek41:init
4848
4849 - Procedure: tek41:reset
4850
4851 - Procedure: tek41:graphics
4852
4853 - Procedure: tek41:move x y
4854
4855 - Procedure: tek41:draw x y
4856
4857 - Procedure: tek41:point x y number
4858
4859 - Procedure: tek41:encode-x-y x y
4860
4861 - Procedure: tek41:encode-int number
4862
4863 \1f
4864 File: slib.info, Node: Schmooz, Prev: Vector Graphics, Up: Textual Conversion Packages
4865
4866 Schmooz
4867 =======
4868
4869 "Schmooz" is a simple, lightweight markup language for interspersing
4870 Texinfo documentation with Scheme source code. Schmooz does not create
4871 the top level Texinfo file; it creates `txi' files which can be
4872 imported into the documentation using the Texinfo command `@include'.
4873
4874 `(require 'schmooz)' defines the function `schmooz', which is used to
4875 process files. Files containing schmooz documentation should not
4876 contain `(require 'schmooz)'.
4877
4878 - Procedure: schmooz filenamescm ...
4879 FILENAMEscm should be a string ending with `scm' naming an
4880 existing file containing Scheme source code. `schmooz' extracts
4881 top-level comments containing schmooz commands from FILENAMEscm
4882 and writes the converted Texinfo source to a file named
4883 FILENAMEtxi.
4884
4885 - Procedure: schmooz filenametexi ...
4886 - Procedure: schmooz filenametex ...
4887 - Procedure: schmooz filenametxi ...
4888 FILENAME should be a string naming an existing file containing
4889 Texinfo source code. For every occurrence of the string `@include
4890 FILENAMEtxi' within that file, `schmooz' calls itself with the
4891 argument `FILENAMEscm'.
4892
4893 Schmooz comments are distinguished (from non-schmooz comments) by
4894 their first line, which must start with an at-sign (@) preceded by one
4895 or more semicolons (;). A schmooz comment ends at the first subsequent
4896 line which does _not_ start with a semicolon. Currently schmooz
4897 comments are recognized only at top level.
4898
4899 Schmooz comments are copied to the Texinfo output file with the
4900 leading contiguous semicolons removed. Certain character sequences
4901 starting with at-sign are treated specially. Others are copied
4902 unchanged.
4903
4904 A schmooz comment starting with `@body' must be followed by a Scheme
4905 definition. All comments between the `@body' line and the definition
4906 will be included in a Texinfo definition, either a `@defun' or a
4907 `@defvar', depending on whether a procedure or a variable is being
4908 defined.
4909
4910 Within the text of that schmooz comment, at-sign followed by `0' will
4911 be replaced by `@code{procedure-name}' if the following definition is
4912 of a procedure; or `@var{variable}' if defining a variable.
4913
4914 An at-sign followed by a non-zero digit will expand to the variable
4915 citation of that numbered argument: `@var{argument-name}'.
4916
4917 If more than one definition follows a `@body' comment line without an
4918 intervening blank or comment line, then those definitions will be
4919 included in the same Texinfo definition using `@defvarx' or `@defunx',
4920 depending on whether the first definition is of a variable or of a
4921 procedure.
4922
4923 Schmooz can figure out whether a definition is of a procedure if it
4924 is of the form:
4925
4926 `(define (<identifier> <arg> ...) <expression>)'
4927
4928 or if the left hand side of the definition is some form ending in a
4929 lambda expression. Obviously, it can be fooled. In order to force
4930 recognition of a procedure definition, start the documentation with
4931 `@args' instead of `@body'. `@args' should be followed by the argument
4932 list of the function being defined, which may be enclosed in
4933 parentheses and delimited by whitespace, (as in Scheme), enclosed in
4934 braces and separated by commas, (as in Texinfo), or consist of the
4935 remainder of the line, separated by whitespace.
4936
4937 For example:
4938
4939 ;;@args arg1 args ...
4940 ;;@0 takes argument @1 and any number of @2
4941 (define myfun (some-function-returning-magic))
4942
4943 Will result in:
4944
4945 @defun myfun arg1 args @dots{}
4946
4947 @code{myfun} takes argument @var{arg1} and any number of @var{args}
4948 @end defun
4949
4950 `@args' may also be useful for indicating optional arguments by name.
4951 If `@args' occurs inside a schmooz comment section, rather than at the
4952 beginning, then it will generate a `@defunx' line with the arguments
4953 supplied.
4954
4955 If the first at-sign in a schmooz comment is immediately followed by
4956 whitespace, then the comment will be expanded to whatever follows that
4957 whitespace. If the at-sign is followed by a non-whitespace character
4958 then the at-sign will be included as the first character of the
4959 expansion. This feature is intended to make it easy to include Texinfo
4960 directives in schmooz comments.
4961
4962 \1f
4963 File: slib.info, Node: Mathematical Packages, Next: Database Packages, Prev: Textual Conversion Packages, Up: Top
4964
4965 Mathematical Packages
4966 *********************
4967
4968 * Menu:
4969
4970 * Bit-Twiddling:: 'logical
4971 * Modular Arithmetic:: 'modular
4972 * Prime Numbers:: 'factor
4973 * Random Numbers:: 'random
4974 * Fast Fourier Transform:: 'fft
4975 * Cyclic Checksum:: 'make-crc
4976 * Plotting:: 'charplot
4977 * Root Finding:: 'root
4978 * Minimizing:: 'minimize
4979 * Commutative Rings:: 'commutative-ring
4980 * Determinant:: 'determinant
4981
4982 \1f
4983 File: slib.info, Node: Bit-Twiddling, Next: Modular Arithmetic, Prev: Mathematical Packages, Up: Mathematical Packages
4984
4985 Bit-Twiddling
4986 =============
4987
4988 `(require 'logical)'
4989
4990 The bit-twiddling functions are made available through the use of the
4991 `logical' package. `logical' is loaded by inserting `(require
4992 'logical)' before the code that uses these functions. These functions
4993 behave as though operating on integers in two's-complement
4994 representation.
4995
4996 Bitwise Operations
4997 ------------------
4998
4999 - Function: logand n1 n1
5000 Returns the integer which is the bit-wise AND of the two integer
5001 arguments.
5002
5003 Example:
5004 (number->string (logand #b1100 #b1010) 2)
5005 => "1000"
5006
5007 - Function: logior n1 n2
5008 Returns the integer which is the bit-wise OR of the two integer
5009 arguments.
5010
5011 Example:
5012 (number->string (logior #b1100 #b1010) 2)
5013 => "1110"
5014
5015 - Function: logxor n1 n2
5016 Returns the integer which is the bit-wise XOR of the two integer
5017 arguments.
5018
5019 Example:
5020 (number->string (logxor #b1100 #b1010) 2)
5021 => "110"
5022
5023 - Function: lognot n
5024 Returns the integer which is the 2s-complement of the integer
5025 argument.
5026
5027 Example:
5028 (number->string (lognot #b10000000) 2)
5029 => "-10000001"
5030 (number->string (lognot #b0) 2)
5031 => "-1"
5032
5033 - Function: bitwise-if mask n0 n1
5034 Returns an integer composed of some bits from integer N0 and some
5035 from integer N1. A bit of the result is taken from N0 if the
5036 corresponding bit of integer MASK is 1 and from N1 if that bit of
5037 MASK is 0.
5038
5039 - Function: logtest j k
5040 (logtest j k) == (not (zero? (logand j k)))
5041
5042 (logtest #b0100 #b1011) => #f
5043 (logtest #b0100 #b0111) => #t
5044
5045 - Function: logcount n
5046 Returns the number of bits in integer N. If integer is positive,
5047 the 1-bits in its binary representation are counted. If negative,
5048 the 0-bits in its two's-complement binary representation are
5049 counted. If 0, 0 is returned.
5050
5051 Example:
5052 (logcount #b10101010)
5053 => 4
5054 (logcount 0)
5055 => 0
5056 (logcount -2)
5057 => 1
5058
5059 Bit Within Word
5060 ---------------
5061
5062 - Function: logbit? index j
5063 (logbit? index j) == (logtest (integer-expt 2 index) j)
5064
5065 (logbit? 0 #b1101) => #t
5066 (logbit? 1 #b1101) => #f
5067 (logbit? 2 #b1101) => #t
5068 (logbit? 3 #b1101) => #t
5069 (logbit? 4 #b1101) => #f
5070
5071 - Function: copy-bit index from bit
5072 Returns an integer the same as FROM except in the INDEXth bit,
5073 which is 1 if BIT is `#t' and 0 if BIT is `#f'.
5074
5075 Example:
5076 (number->string (copy-bit 0 0 #t) 2) => "1"
5077 (number->string (copy-bit 2 0 #t) 2) => "100"
5078 (number->string (copy-bit 2 #b1111 #f) 2) => "1011"
5079
5080 Fields of Bits
5081 --------------
5082
5083 - Function: bit-field n start end
5084 Returns the integer composed of the START (inclusive) through END
5085 (exclusive) bits of N. The STARTth bit becomes the 0-th bit in
5086 the result.
5087
5088 This function was called `bit-extract' in previous versions of
5089 SLIB.
5090
5091 Example:
5092 (number->string (bit-field #b1101101010 0 4) 2)
5093 => "1010"
5094 (number->string (bit-field #b1101101010 4 9) 2)
5095 => "10110"
5096
5097 - Function: copy-bit-field to start end from
5098 Returns an integer the same as TO except possibly in the START
5099 (inclusive) through END (exclusive) bits, which are the same as
5100 those of FROM. The 0-th bit of FROM becomes the STARTth bit of
5101 the result.
5102
5103 Example:
5104 (number->string (copy-bit-field #b1101101010 0 4 0) 2)
5105 => "1101100000"
5106 (number->string (copy-bit-field #b1101101010 0 4 -1) 2)
5107 => "1101101111"
5108
5109 - Function: ash int count
5110 Returns an integer equivalent to `(inexact->exact (floor (* INT
5111 (expt 2 COUNT))))'.
5112
5113 Example:
5114 (number->string (ash #b1 3) 2)
5115 => "1000"
5116 (number->string (ash #b1010 -1) 2)
5117 => "101"
5118
5119 - Function: integer-length n
5120 Returns the number of bits neccessary to represent N.
5121
5122 Example:
5123 (integer-length #b10101010)
5124 => 8
5125 (integer-length 0)
5126 => 0
5127 (integer-length #b1111)
5128 => 4
5129
5130 - Function: integer-expt n k
5131 Returns N raised to the non-negative integer exponent K.
5132
5133 Example:
5134 (integer-expt 2 5)
5135 => 32
5136 (integer-expt -3 3)
5137 => -27
5138
5139 \1f
5140 File: slib.info, Node: Modular Arithmetic, Next: Prime Numbers, Prev: Bit-Twiddling, Up: Mathematical Packages
5141
5142 Modular Arithmetic
5143 ==================
5144
5145 `(require 'modular)'
5146
5147 - Function: extended-euclid n1 n2
5148 Returns a list of 3 integers `(d x y)' such that d = gcd(N1, N2) =
5149 N1 * x + N2 * y.
5150
5151 - Function: symmetric:modulus n
5152 Returns `(quotient (+ -1 n) -2)' for positive odd integer N.
5153
5154 - Function: modulus->integer modulus
5155 Returns the non-negative integer characteristic of the ring formed
5156 when MODULUS is used with `modular:' procedures.
5157
5158 - Function: modular:normalize modulus n
5159 Returns the integer `(modulo N (modulus->integer MODULUS))' in the
5160 representation specified by MODULUS.
5161
5162 The rest of these functions assume normalized arguments; That is, the
5163 arguments are constrained by the following table:
5164
5165 For all of these functions, if the first argument (MODULUS) is:
5166 `positive?'
5167 Work as before. The result is between 0 and MODULUS.
5168
5169 `zero?'
5170 The arguments are treated as integers. An integer is returned.
5171
5172 `negative?'
5173 The arguments and result are treated as members of the integers
5174 modulo `(+ 1 (* -2 MODULUS))', but with "symmetric"
5175 representation; i.e. `(<= (- MODULUS) N MODULUS)'.
5176
5177 If all the arguments are fixnums the computation will use only fixnums.
5178
5179 - Function: modular:invertable? modulus k
5180 Returns `#t' if there exists an integer n such that K * n == 1 mod
5181 MODULUS, and `#f' otherwise.
5182
5183 - Function: modular:invert modulus k2
5184 Returns an integer n such that 1 = (n * K2) mod MODULUS. If K2
5185 has no inverse mod MODULUS an error is signaled.
5186
5187 - Function: modular:negate modulus k2
5188 Returns (-K2) mod MODULUS.
5189
5190 - Function: modular:+ modulus k2 k3
5191 Returns (K2 + K3) mod MODULUS.
5192
5193 - Function: modular:- modulus k2 k3
5194 Returns (K2 - K3) mod MODULUS.
5195
5196 - Function: modular:* modulus k2 k3
5197 Returns (K2 * K3) mod MODULUS.
5198
5199 The Scheme code for `modular:*' with negative MODULUS is not
5200 completed for fixnum-only implementations.
5201
5202 - Function: modular:expt modulus k2 k3
5203 Returns (K2 ^ K3) mod MODULUS.
5204
5205 \1f
5206 File: slib.info, Node: Prime Numbers, Next: Random Numbers, Prev: Modular Arithmetic, Up: Mathematical Packages
5207
5208 Prime Numbers
5209 =============
5210
5211 `(require 'factor)'
5212
5213 - Variable: prime:prngs
5214 PRIME:PRNGS is the random-state (*note Random Numbers::) used by
5215 these procedures. If you call these procedures from more than one
5216 thread (or from interrupt), `random' may complain about reentrant
5217 calls.
5218 _Note:_ The prime test and generation procedures implement (or use)
5219 the Solovay-Strassen primality test. See
5220
5221 * Robert Solovay and Volker Strassen, `A Fast Monte-Carlo Test for
5222 Primality', SIAM Journal on Computing, 1977, pp 84-85.
5223
5224 - Function: jacobi-symbol p q
5225 Returns the value (+1, -1, or 0) of the Jacobi-Symbol of exact
5226 non-negative integer P and exact positive odd integer Q.
5227
5228 - Variable: prime:trials
5229 PRIME:TRIALS the maxinum number of iterations of Solovay-Strassen
5230 that will be done to test a number for primality.
5231
5232 - Function: prime? n
5233 Returns `#f' if N is composite; `#t' if N is prime. There is a
5234 slight chance `(expt 2 (- prime:trials))' that a composite will
5235 return `#t'.
5236
5237 - Function: primes< start count
5238 Returns a list of the first COUNT prime numbers less than START.
5239 If there are fewer than COUNT prime numbers less than START, then
5240 the returned list will have fewer than START elements.
5241
5242 - Function: primes> start count
5243 Returns a list of the first COUNT prime numbers greater than START.
5244
5245 - Function: factor k
5246 Returns a list of the prime factors of K. The order of the
5247 factors is unspecified. In order to obtain a sorted list do
5248 `(sort! (factor K) <)'.
5249
5250 \1f
5251 File: slib.info, Node: Random Numbers, Next: Fast Fourier Transform, Prev: Prime Numbers, Up: Mathematical Packages
5252
5253 Random Numbers
5254 ==============
5255
5256 `(require 'random)'
5257
5258 A pseudo-random number generator is only as good as the tests it
5259 passes. George Marsaglia of Florida State University developed a
5260 battery of tests named "DIEHARD"
5261 (<http://stat.fsu.edu/~geo/diehard.html>). `diehard.c' has a bug which
5262 the patch
5263 <http://swissnet.ai.mit.edu/ftpdir/users/jaffer/diehard.c.pat> corrects.
5264
5265 SLIB's new PRNG generates 8 bits at a time. With the degenerate seed
5266 `0', the numbers generated pass DIEHARD; but when bits are combined
5267 from sequential bytes, tests fail. With the seed
5268 `http://swissnet.ai.mit.edu/~jaffer/SLIB.html', all of those tests pass.
5269
5270 - Function: random n
5271 - Function: random n state
5272 Accepts a positive integer or real N and returns a number of the
5273 same type between zero (inclusive) and N (exclusive). The values
5274 returned by `random' are uniformly distributed from 0 to N.
5275
5276 The optional argument STATE must be of the type returned by
5277 `(seed->random-state)' or `(make-random-state)'. It defaults to
5278 the value of the variable `*random-state*'. This object is used
5279 to maintain the state of the pseudo-random-number generator and is
5280 altered as a side effect of calls to `random'.
5281
5282 - Variable: *random-state*
5283 Holds a data structure that encodes the internal state of the
5284 random-number generator that `random' uses by default. The nature
5285 of this data structure is implementation-dependent. It may be
5286 printed out and successfully read back in, but may or may not
5287 function correctly as a random-number state object in another
5288 implementation.
5289
5290 - Function: copy-random-state state
5291 Returns a new copy of argument STATE.
5292
5293 - Function: copy-random-state
5294 Returns a new copy of `*random-state*'.
5295
5296 - Function: seed->random-state seed
5297 Returns a new object of type suitable for use as the value of the
5298 variable `*random-state*' or as a second argument to `random'.
5299 The number or string SEED is used to initialize the state. If
5300 `seed->random-state' is called twice with arguments which are
5301 `equal?', then the returned data structures will be `equal?'.
5302 Calling `seed->random-state' with unequal arguments will nearly
5303 always return unequal states.
5304
5305 - Function: make-random-state
5306 - Function: make-random-state obj
5307 Returns a new object of type suitable for use as the value of the
5308 variable `*random-state*' or as a second argument to `random'. If
5309 the optional argument OBJ is given, it should be a printable
5310 Scheme object; the first 50 characters of its printed
5311 representation will be used as the seed. Otherwise the value of
5312 `*random-state*' is used as the seed.
5313
5314 If inexact numbers are supported by the Scheme implementation,
5315 `randinex.scm' will be loaded as well. `randinex.scm' contains
5316 procedures for generating inexact distributions.
5317
5318 - Function: random:uniform
5319 - Function: random:uniform state
5320 Returns an uniformly distributed inexact real random number in the
5321 range between 0 and 1.
5322
5323 - Function: random:exp
5324 - Function: random:exp state
5325 Returns an inexact real in an exponential distribution with mean
5326 1. For an exponential distribution with mean U use
5327 `(* U (random:exp))'.
5328
5329 - Function: random:normal
5330 - Function: random:normal state
5331 Returns an inexact real in a normal distribution with mean 0 and
5332 standard deviation 1. For a normal distribution with mean M and
5333 standard deviation D use `(+ M (* D (random:normal)))'.
5334
5335 - Function: random:normal-vector! vect
5336 - Function: random:normal-vector! vect state
5337 Fills VECT with inexact real random numbers which are independent
5338 and standard normally distributed (i.e., with mean 0 and variance
5339 1).
5340
5341 - Function: random:hollow-sphere! vect
5342 - Function: random:hollow-sphere! vect state
5343 Fills VECT with inexact real random numbers the sum of whose
5344 squares is equal to 1.0. Thinking of VECT as coordinates in space
5345 of dimension n = `(vector-length VECT)', the coordinates are
5346 uniformly distributed over the surface of the unit n-shere.
5347
5348 - Function: random:solid-sphere! vect
5349 - Function: random:solid-sphere! vect state
5350 Fills VECT with inexact real random numbers the sum of whose
5351 squares is less than 1.0. Thinking of VECT as coordinates in
5352 space of dimension N = `(vector-length VECT)', the coordinates are
5353 uniformly distributed within the unit N-shere. The sum of the
5354 squares of the numbers is returned.
5355
5356 \1f
5357 File: slib.info, Node: Fast Fourier Transform, Next: Cyclic Checksum, Prev: Random Numbers, Up: Mathematical Packages
5358
5359 Fast Fourier Transform
5360 ======================
5361
5362 `(require 'fft)'
5363
5364 - Function: fft array
5365 ARRAY is an array of `(expt 2 n)' numbers. `fft' returns an array
5366 of complex numbers comprising the "Discrete Fourier Transform" of
5367 ARRAY.
5368
5369 - Function: fft-1 array
5370 `fft-1' returns an array of complex numbers comprising the inverse
5371 Discrete Fourier Transform of ARRAY.
5372
5373 `(fft-1 (fft ARRAY))' will return an array of values close to ARRAY.
5374
5375 (fft '#(1 0+i -1 0-i 1 0+i -1 0-i)) =>
5376
5377 #(0.0 0.0 0.0+628.0783185208527e-18i 0.0
5378 0.0 0.0 8.0-628.0783185208527e-18i 0.0)
5379
5380 (fft-1 '#(0 0 0 0 0 0 8 0)) =>
5381
5382 #(1.0 -61.23031769111886e-18+1.0i -1.0 61.23031769111886e-18-1.0i
5383 1.0 -61.23031769111886e-18+1.0i -1.0 61.23031769111886e-18-1.0i)
5384
5385 \1f
5386 File: slib.info, Node: Cyclic Checksum, Next: Plotting, Prev: Fast Fourier Transform, Up: Mathematical Packages
5387
5388 Cyclic Checksum
5389 ===============
5390
5391 `(require 'make-crc)'
5392
5393 - Function: make-port-crc
5394 - Function: make-port-crc degree |
5395 Returns an expression for a procedure of one argument, a port.
5396 This procedure reads characters from the port until the end of
5397 file and returns the integer checksum of the bytes read.
5398
5399 The integer DEGREE, if given, specifies the degree of the
5400 polynomial being computed - which is also the number of bits
5401 computed in the checksums. The default value is 32.
5402
5403 - Function: make-port-crc generator |
5404 The integer GENERATOR specifies the polynomial being computed. |
5405 The power of 2 generating each 1 bit is the exponent of a term of |
5406 the polynomial. The value of GENERATOR must be larger than 127. |
5407 |
5408 - Function: make-port-crc degree generator |
5409 The integer GENERATOR specifies the polynomial being computed.
5410 The power of 2 generating each 1 bit is the exponent of a term of
5411 the polynomial. The bit at position DEGREE is implicit and should
5412 not be part of GENERATOR. This allows systems with numbers
5413 limited to 32 bits to calculate 32 bit checksums. The default
5414 value of GENERATOR when DEGREE is 32 (its default) is:
5415
5416 (make-port-crc 32 #b00000100110000010001110110110111)
5417
5418 Creates a procedure to calculate the P1003.2/D11.2 (POSIX.2) 32-bit
5419 checksum from the polynomial:
5420
5421 32 26 23 22 16 12 11
5422 ( x + x + x + x + x + x + x +
5423
5424 10 8 7 5 4 2 1
5425 x + x + x + x + x + x + x + 1 ) mod 2
5426
5427 (require 'make-crc)
5428 (define crc32 (slib:eval (make-port-crc)))
5429 (define (file-check-sum file) (call-with-input-file file crc32))
5430 (file-check-sum (in-vicinity (library-vicinity) "ratize.scm"))
5431
5432 => 157103930 |
5433
5434 \1f
5435 File: slib.info, Node: Plotting, Next: Root Finding, Prev: Cyclic Checksum, Up: Mathematical Packages
5436
5437 Plotting on Character Devices
5438 =============================
5439
5440 `(require 'charplot)'
5441
5442 The plotting procedure is made available through the use of the
5443 `charplot' package. `charplot' is loaded by inserting `(require
5444 'charplot)' before the code that uses this procedure.
5445
5446 - Variable: charplot:height
5447 The number of rows to make the plot vertically.
5448
5449 - Variable: charplot:width
5450 The number of columns to make the plot horizontally.
5451
5452 - Procedure: plot! coords x-label y-label
5453 COORDS is a list of pairs of x and y coordinates. X-LABEL and
5454 Y-LABEL are strings with which to label the x and y axes.
5455
5456 Example:
5457 (require 'charplot)
5458 (set! charplot:height 19)
5459 (set! charplot:width 45)
5460
5461 (define (make-points n)
5462 (if (zero? n)
5463 '()
5464 (cons (cons (/ n 6) (sin (/ n 6))) (make-points (1- n)))))
5465
5466 (plot! (make-points 37) "x" "Sin(x)")
5467 -|
5468 Sin(x) ______________________________________________
5469 1.25|- |
5470 | |
5471 1|- **** |
5472 | ** ** |
5473 0.75|- * * |
5474 | * * |
5475 0.5|- * * |
5476 | * |
5477 0.25|- * |
5478 | * * |
5479 0|-------------------*--------------------------|
5480 | * |
5481 -0.25|- * * |
5482 | * * |
5483 -0.5|- * |
5484 | * * |
5485 -0.75|- * * |
5486 | ** ** |
5487 -1|- **** |
5488 |____________:_____._____:_____._____:_________|
5489 x 2 4 6
5490
5491 - Procedure: plot-function! func x1 x2
5492 - Procedure: plot-function! func x1 x2 npts
5493 Plots the function of one argument FUNC over the range X1 to X2.
5494 If the optional integer argument NPTS is supplied, it specifies
5495 the number of points to evaluate FUNC at.
5496
5497 \1f
5498 File: slib.info, Node: Root Finding, Next: Minimizing, Prev: Plotting, Up: Mathematical Packages
5499
5500 Root Finding
5501 ============
5502
5503 `(require 'root)'
5504
5505 - Function: newtown:find-integer-root f df/dx x0
5506 Given integer valued procedure F, its derivative (with respect to
5507 its argument) DF/DX, and initial integer value X0 for which
5508 DF/DX(X0) is non-zero, returns an integer X for which F(X) is
5509 closer to zero than either of the integers adjacent to X; or
5510 returns `#f' if such an integer can't be found.
5511
5512 To find the closest integer to a given integers square root:
5513
5514 (define (integer-sqrt y)
5515 (newton:find-integer-root
5516 (lambda (x) (- (* x x) y))
5517 (lambda (x) (* 2 x))
5518 (ash 1 (quotient (integer-length y) 2))))
5519
5520 (integer-sqrt 15) => 4
5521
5522 - Function: integer-sqrt y
5523 Given a non-negative integer Y, returns the rounded square-root of
5524 Y.
5525
5526 - Function: newton:find-root f df/dx x0 prec
5527 Given real valued procedures F, DF/DX of one (real) argument,
5528 initial real value X0 for which DF/DX(X0) is non-zero, and
5529 positive real number PREC, returns a real X for which `abs'(F(X))
5530 is less than PREC; or returns `#f' if such a real can't be found.
5531
5532 If PREC is instead a negative integer, `newton:find-root' returns
5533 the result of -PREC iterations.
5534
5535 H. J. Orchard, `The Laguerre Method for Finding the Zeros of
5536 Polynomials', IEEE Transactions on Circuits and Systems, Vol. 36, No.
5537 11, November 1989, pp 1377-1381.
5538
5539 There are 2 errors in Orchard's Table II. Line k=2 for starting
5540 value of 1000+j0 should have Z_k of 1.0475 + j4.1036 and line k=2
5541 for starting value of 0+j1000 should have Z_k of 1.0988 + j4.0833.
5542
5543 - Function: laguerre:find-root f df/dz ddf/dz^2 z0 prec
5544 Given complex valued procedure F of one (complex) argument, its
5545 derivative (with respect to its argument) DF/DX, its second
5546 derivative DDF/DZ^2, initial complex value Z0, and positive real
5547 number PREC, returns a complex number Z for which
5548 `magnitude'(F(Z)) is less than PREC; or returns `#f' if such a
5549 number can't be found.
5550
5551 If PREC is instead a negative integer, `laguerre:find-root'
5552 returns the result of -PREC iterations.
5553
5554 - Function: laguerre:find-polynomial-root deg f df/dz ddf/dz^2 z0 prec
5555 Given polynomial procedure F of integer degree DEG of one
5556 argument, its derivative (with respect to its argument) DF/DX, its
5557 second derivative DDF/DZ^2, initial complex value Z0, and positive
5558 real number PREC, returns a complex number Z for which
5559 `magnitude'(F(Z)) is less than PREC; or returns `#f' if such a
5560 number can't be found.
5561
5562 If PREC is instead a negative integer,
5563 `laguerre:find-polynomial-root' returns the result of -PREC
5564 iterations.
5565
5566 - Function: secant:find-root f x0 x1 prec
5567 - Function: secant:find-bracketed-root f x0 x1 prec
5568 Given a real valued procedure F and two real valued starting
5569 points X0 and X1, returns a real X for which `(abs (f x))' is less
5570 than PREC; or returns `#f' if such a real can't be found.
5571
5572 If X0 and X1 are chosen such that they bracket a root, that is
5573 (or (< (f x0) 0 (f x1))
5574 (< (f x1) 0 (f x0)))
5575 then the root returned will be between X0 and X1, and F will not
5576 be passed an argument outside of that interval.
5577
5578 `secant:find-bracketed-root' will return `#f' unless X0 and X1
5579 bracket a root.
5580
5581 The secant method is used until a bracketing interval is found, at
5582 which point a modified regula falsi method is used.
5583
5584 If PREC is instead a negative integer, `secant:find-root' returns
5585 the result of -PREC iterations.
5586
5587 If PREC is a procedure it should accept 5 arguments: X0 F0 X1 F1
5588 and COUNT, where F0 will be `(f x0)', F1 `(f x1)', and COUNT the
5589 number of iterations performed so far. PREC should return
5590 non-false if the iteration should be stopped.
5591
5592 \1f
5593 File: slib.info, Node: Minimizing, Next: Commutative Rings, Prev: Root Finding, Up: Mathematical Packages
5594
5595 Minimizing
5596 ==========
5597
5598 `(require 'minimize)'
5599
5600 The Golden Section Search (1) algorithm finds minima of functions which
5601 are expensive to compute or for which derivatives are not available.
5602 Although optimum for the general case, convergence is slow, requiring
5603 nearly 100 iterations for the example (x^3-2x-5).
5604
5605 If the derivative is available, Newton-Raphson is probably a better
5606 choice. If the function is inexpensive to compute, consider
5607 approximating the derivative.
5608
5609 - Function: golden-section-search f x0 x1 prec
5610 X_0 are X_1 real numbers. The (single argument) procedure F is
5611 unimodal over the open interval (X_0, X_1). That is, there is
5612 exactly one point in the interval for which the derivative of F is
5613 zero.
5614
5615 `golden-section-search' returns a pair (X . F(X)) where F(X) is
5616 the minimum. The PREC parameter is the stop criterion. If PREC
5617 is a positive number, then the iteration continues until X is
5618 within PREC from the true value. If PREC is a negative integer,
5619 then the procedure will iterate -PREC times or until convergence.
5620 If PREC is a procedure of seven arguments, X0, X1, A, B, FA, FB,
5621 and COUNT, then the iterations will stop when the procedure
5622 returns `#t'.
5623
5624 Analytically, the minimum of x^3-2x-5 is 0.816497.
5625 (define func (lambda (x) (+ (* x (+ (* x x) -2)) -5)))
5626 (golden-section-search func 0 1 (/ 10000))
5627 ==> (816.4883855245578e-3 . -6.0886621077391165)
5628 (golden-section-search func 0 1 -5)
5629 ==> (819.6601125010515e-3 . -6.088637561916407)
5630 (golden-section-search func 0 1
5631 (lambda (a b c d e f g ) (= g 500)))
5632 ==> (816.4965933140557e-3 . -6.088662107903635)
5633
5634 ---------- Footnotes ----------
5635
5636 (1) David Kahaner, Cleve Moler, and Stephen Nash `Numerical Methods
5637 and Software' Prentice-Hall, 1989, ISBN 0-13-627258-4
5638
5639 \1f
5640 File: slib.info, Node: Commutative Rings, Next: Determinant, Prev: Minimizing, Up: Mathematical Packages
5641
5642 Commutative Rings
5643 =================
5644
5645 Scheme provides a consistent and capable set of numeric functions.
5646 Inexacts implement a field; integers a commutative ring (and Euclidean
5647 domain). This package allows one to use basic Scheme numeric functions
5648 with symbols and non-numeric elements of commutative rings.
5649
5650 `(require 'commutative-ring)'
5651
5652 The "commutative-ring" package makes the procedures `+', `-', `*',
5653 `/', and `^' "careful" in the sense that any non-numeric arguments they
5654 do not reduce appear in the expression output. In order to see what
5655 working with this package is like, self-set all the single letter
5656 identifiers (to their corresponding symbols).
5657
5658 (define a 'a)
5659 ...
5660 (define z 'z)
5661
5662 Or just `(require 'self-set)'. Now try some sample expressions:
5663
5664 (+ (+ a b) (- a b)) => (* a 2)
5665 (* (+ a b) (+ a b)) => (^ (+ a b) 2)
5666 (* (+ a b) (- a b)) => (* (+ a b) (- a b))
5667 (* (- a b) (- a b)) => (^ (- a b) 2)
5668 (* (- a b) (+ a b)) => (* (+ a b) (- a b))
5669 (/ (+ a b) (+ c d)) => (/ (+ a b) (+ c d))
5670 (^ (+ a b) 3) => (^ (+ a b) 3)
5671 (^ (+ a 2) 3) => (^ (+ 2 a) 3)
5672
5673 Associative rules have been applied and repeated addition and
5674 multiplication converted to multiplication and exponentiation.
5675
5676 We can enable distributive rules, thus expanding to sum of products
5677 form:
5678 (set! *ruleset* (combined-rulesets distribute* distribute/))
5679
5680 (* (+ a b) (+ a b)) => (+ (* 2 a b) (^ a 2) (^ b 2))
5681 (* (+ a b) (- a b)) => (- (^ a 2) (^ b 2))
5682 (* (- a b) (- a b)) => (- (+ (^ a 2) (^ b 2)) (* 2 a b))
5683 (* (- a b) (+ a b)) => (- (^ a 2) (^ b 2))
5684 (/ (+ a b) (+ c d)) => (+ (/ a (+ c d)) (/ b (+ c d)))
5685 (/ (+ a b) (- c d)) => (+ (/ a (- c d)) (/ b (- c d)))
5686 (/ (- a b) (- c d)) => (- (/ a (- c d)) (/ b (- c d)))
5687 (/ (- a b) (+ c d)) => (- (/ a (+ c d)) (/ b (+ c d)))
5688 (^ (+ a b) 3) => (+ (* 3 a (^ b 2)) (* 3 b (^ a 2)) (^ a 3) (^ b 3))
5689 (^ (+ a 2) 3) => (+ 8 (* a 12) (* (^ a 2) 6) (^ a 3))
5690
5691 Use of this package is not restricted to simple arithmetic
5692 expressions:
5693
5694 (require 'determinant)
5695
5696 (determinant '((a b c) (d e f) (g h i))) =>
5697 (- (+ (* a e i) (* b f g) (* c d h)) (* a f h) (* b d i) (* c e g))
5698
5699 Currently, only `+', `-', `*', `/', and `^' support non-numeric
5700 elements. Expressions with `-' are converted to equivalent expressions
5701 without `-', so behavior for `-' is not defined separately. `/'
5702 expressions are handled similarly.
5703
5704 This list might be extended to include `quotient', `modulo',
5705 `remainder', `lcm', and `gcd'; but these work only for the more
5706 restrictive Euclidean (Unique Factorization) Domain.
5707
5708 Rules and Rulesets
5709 ==================
5710
5711 The "commutative-ring" package allows control of ring properties
5712 through the use of "rulesets".
5713
5714 - Variable: *ruleset*
5715 Contains the set of rules currently in effect. Rules defined by
5716 `cring:define-rule' are stored within the value of *ruleset* at the
5717 time `cring:define-rule' is called. If *RULESET* is `#f', then no
5718 rules apply.
5719
5720 - Function: make-ruleset rule1 ...
5721 - Function: make-ruleset name rule1 ...
5722 Returns a new ruleset containing the rules formed by applying
5723 `cring:define-rule' to each 4-element list argument RULE. If the
5724 first argument to `make-ruleset' is a symbol, then the database
5725 table created for the new ruleset will be named NAME. Calling
5726 `make-ruleset' with no rule arguments creates an empty ruleset.
5727
5728 - Function: combined-rulesets ruleset1 ...
5729 - Function: combined-rulesets name ruleset1 ...
5730 Returns a new ruleset containing the rules contained in each
5731 ruleset argument RULESET. If the first argument to
5732 `combined-ruleset' is a symbol, then the database table created for
5733 the new ruleset will be named NAME. Calling `combined-ruleset'
5734 with no ruleset arguments creates an empty ruleset.
5735
5736 Two rulesets are defined by this package.
5737
5738 - Constant: distribute*
5739 Contain the ruleset to distribute multiplication over addition and
5740 subtraction.
5741
5742 - Constant: distribute/
5743 Contain the ruleset to distribute division over addition and
5744 subtraction.
5745
5746 Take care when using both DISTRIBUTE* and DISTRIBUTE/
5747 simultaneously. It is possible to put `/' into an infinite loop.
5748
5749 You can specify how sum and product expressions containing non-numeric
5750 elements simplify by specifying the rules for `+' or `*' for cases
5751 where expressions involving objects reduce to numbers or to expressions
5752 involving different non-numeric elements.
5753
5754 - Function: cring:define-rule op sub-op1 sub-op2 reduction
5755 Defines a rule for the case when the operation represented by
5756 symbol OP is applied to lists whose `car's are SUB-OP1 and
5757 SUB-OP2, respectively. The argument REDUCTION is a procedure
5758 accepting 2 arguments which will be lists whose `car's are SUB-OP1
5759 and SUB-OP2.
5760
5761 - Function: cring:define-rule op sub-op1 'identity reduction
5762 Defines a rule for the case when the operation represented by
5763 symbol OP is applied to a list whose `car' is SUB-OP1, and some
5764 other argument. REDUCTION will be called with the list whose
5765 `car' is SUB-OP1 and some other argument.
5766
5767 If REDUCTION returns `#f', the reduction has failed and other
5768 reductions will be tried. If REDUCTION returns a non-false value,
5769 that value will replace the two arguments in arithmetic (`+', `-',
5770 and `*') calculations involving non-numeric elements.
5771
5772 The operations `+' and `*' are assumed commutative; hence both
5773 orders of arguments to REDUCTION will be tried if necessary.
5774
5775 The following rule is the definition for distributing `*' over `+'.
5776
5777 (cring:define-rule
5778 '* '+ 'identity
5779 (lambda (exp1 exp2)
5780 (apply + (map (lambda (trm) (* trm exp2)) (cdr exp1))))))
5781
5782 How to Create a Commutative Ring
5783 ================================
5784
5785 The first step in creating your commutative ring is to write
5786 procedures to create elements of the ring. A non-numeric element of
5787 the ring must be represented as a list whose first element is a symbol
5788 or string. This first element identifies the type of the object. A
5789 convenient and clear convention is to make the type-identifying element
5790 be the same symbol whose top-level value is the procedure to create it.
5791
5792 (define (n . list1)
5793 (cond ((and (= 2 (length list1))
5794 (eq? (car list1) (cadr list1)))
5795 0)
5796 ((not (term< (first list1) (last1 list1)))
5797 (apply n (reverse list1)))
5798 (else (cons 'n list1))))
5799
5800 (define (s x y) (n x y))
5801
5802 (define (m . list1)
5803 (cond ((neq? (first list1) (term_min list1))
5804 (apply m (cyclicrotate list1)))
5805 ((term< (last1 list1) (cadr list1))
5806 (apply m (reverse (cyclicrotate list1))))
5807 (else (cons 'm list1))))
5808
5809 Define a procedure to multiply 2 non-numeric elements of the ring.
5810 Other multiplicatons are handled automatically. Objects for which rules
5811 have _not_ been defined are not changed.
5812
5813 (define (n*n ni nj)
5814 (let ((list1 (cdr ni)) (list2 (cdr nj)))
5815 (cond ((null? (intersection list1 list2)) #f)
5816 ((and (eq? (last1 list1) (first list2))
5817 (neq? (first list1) (last1 list2)))
5818 (apply n (splice list1 list2)))
5819 ((and (eq? (first list1) (first list2))
5820 (neq? (last1 list1) (last1 list2)))
5821 (apply n (splice (reverse list1) list2)))
5822 ((and (eq? (last1 list1) (last1 list2))
5823 (neq? (first list1) (first list2)))
5824 (apply n (splice list1 (reverse list2))))
5825 ((and (eq? (last1 list1) (first list2))
5826 (eq? (first list1) (last1 list2)))
5827 (apply m (cyclicsplice list1 list2)))
5828 ((and (eq? (first list1) (first list2))
5829 (eq? (last1 list1) (last1 list2)))
5830 (apply m (cyclicsplice (reverse list1) list2)))
5831 (else #f))))
5832
5833 Test the procedures to see if they work.
5834
5835 ;;; where cyclicrotate(list) is cyclic rotation of the list one step
5836 ;;; by putting the first element at the end
5837 (define (cyclicrotate list1)
5838 (append (rest list1) (list (first list1))))
5839 ;;; and where term_min(list) is the element of the list which is
5840 ;;; first in the term ordering.
5841 (define (term_min list1)
5842 (car (sort list1 term<)))
5843 (define (term< sym1 sym2)
5844 (string<? (symbol->string sym1) (symbol->string sym2)))
5845 (define first car)
5846 (define rest cdr)
5847 (define (last1 list1) (car (last-pair list1)))
5848 (define (neq? obj1 obj2) (not (eq? obj1 obj2)))
5849 ;;; where splice is the concatenation of list1 and list2 except that their
5850 ;;; common element is not repeated.
5851 (define (splice list1 list2)
5852 (cond ((eq? (last1 list1) (first list2))
5853 (append list1 (cdr list2)))
5854 (else (error 'splice list1 list2))))
5855 ;;; where cyclicsplice is the result of leaving off the last element of
5856 ;;; splice(list1,list2).
5857 (define (cyclicsplice list1 list2)
5858 (cond ((and (eq? (last1 list1) (first list2))
5859 (eq? (first list1) (last1 list2)))
5860 (butlast (splice list1 list2) 1))
5861 (else (error 'cyclicsplice list1 list2))))
5862
5863 (N*N (S a b) (S a b)) => (m a b)
5864
5865 Then register the rule for multiplying type N objects by type N
5866 objects.
5867
5868 (cring:define-rule '* 'N 'N N*N))
5869
5870 Now we are ready to compute!
5871
5872 (define (t)
5873 (define detM
5874 (+ (* (S g b)
5875 (+ (* (S f d)
5876 (- (* (S a f) (S d g)) (* (S a g) (S d f))))
5877 (* (S f f)
5878 (- (* (S a g) (S d d)) (* (S a d) (S d g))))
5879 (* (S f g)
5880 (- (* (S a d) (S d f)) (* (S a f) (S d d))))))
5881 (* (S g d)
5882 (+ (* (S f b)
5883 (- (* (S a g) (S d f)) (* (S a f) (S d g))))
5884 (* (S f f)
5885 (- (* (S a b) (S d g)) (* (S a g) (S d b))))
5886 (* (S f g)
5887 (- (* (S a f) (S d b)) (* (S a b) (S d f))))))
5888 (* (S g f)
5889 (+ (* (S f b)
5890 (- (* (S a d) (S d g)) (* (S a g) (S d d))))
5891 (* (S f d)
5892 (- (* (S a g) (S d b)) (* (S a b) (S d g))))
5893 (* (S f g)
5894 (- (* (S a b) (S d d)) (* (S a d) (S d b))))))
5895 (* (S g g)
5896 (+ (* (S f b)
5897 (- (* (S a f) (S d d)) (* (S a d) (S d f))))
5898 (* (S f d)
5899 (- (* (S a b) (S d f)) (* (S a f) (S d b))))
5900 (* (S f f)
5901 (- (* (S a d) (S d b)) (* (S a b) (S d d))))))))
5902 (* (S b e) (S c a) (S e c)
5903 detM
5904 ))
5905 (pretty-print (t))
5906 -|
5907 (- (+ (m a c e b d f g)
5908 (m a c e b d g f)
5909 (m a c e b f d g)
5910 (m a c e b f g d)
5911 (m a c e b g d f)
5912 (m a c e b g f d))
5913 (* 2 (m a b e c) (m d f g))
5914 (* (m a c e b d) (m f g))
5915 (* (m a c e b f) (m d g))
5916 (* (m a c e b g) (m d f)))
5917
5918 \1f
5919 File: slib.info, Node: Determinant, Prev: Commutative Rings, Up: Mathematical Packages
5920
5921 Determinant
5922 ===========
5923
5924 - Function: determinant square-matrix |
5925 Returns the determinant of SQUARE-MATRIX. |
5926 |
5927 (require 'determinant)
5928 (determinant '((1 2) (3 4))) => -2
5929 (determinant '((1 2 3) (4 5 6) (7 8 9))) => 0
5930 (determinant '((1 2 3 4) (5 6 7 8) (9 10 11 12))) => 0
5931
5932 \1f
5933 File: slib.info, Node: Database Packages, Next: Other Packages, Prev: Mathematical Packages, Up: Top
5934
5935 Database Packages
5936 *****************
5937
5938 * Menu:
5939
5940 * Base Table::
5941 * Relational Database:: 'relational-database
5942 * Weight-Balanced Trees:: 'wt-tree
5943
5944 \1f
5945 File: slib.info, Node: Base Table, Next: Relational Database, Prev: Database Packages, Up: Database Packages
5946
5947 Base Table
5948 ==========
5949
5950 A base table implementation using Scheme association lists is
5951 available as the value of the identifier `alist-table' after doing:
5952
5953 `(require 'alist-table)'
5954
5955 Association list base tables are suitable for small databases and
5956 support all Scheme types when temporary and readable/writeable Scheme
5957 types when saved. I hope support for other base table implementations
5958 will be added in the future.
5959
5960 This rest of this section documents the interface for a base table
5961 implementation from which the *Note Relational Database:: package
5962 constructs a Relational system. It will be of interest primarily to
5963 those wishing to port or write new base-table implementations.
5964
5965 All of these functions are accessed through a single procedure by
5966 calling that procedure with the symbol name of the operation. A
5967 procedure will be returned if that operation is supported and `#f'
5968 otherwise. For example:
5969
5970 (require 'alist-table)
5971 (define open-base (alist-table 'make-base))
5972 make-base => *a procedure*
5973 (define foo (alist-table 'foo))
5974 foo => #f
5975
5976 - Function: make-base filename key-dimension column-types
5977 Returns a new, open, low-level database (collection of tables)
5978 associated with FILENAME. This returned database has an empty
5979 table associated with CATALOG-ID. The positive integer
5980 KEY-DIMENSION is the number of keys composed to make a PRIMARY-KEY
5981 for the catalog table. The list of symbols COLUMN-TYPES describes
5982 the types of each column for that table. If the database cannot
5983 be created as specified, `#f' is returned.
5984
5985 Calling the `close-base' method on this database and possibly other
5986 operations will cause FILENAME to be written to. If FILENAME is
5987 `#f' a temporary, non-disk based database will be created if such
5988 can be supported by the base table implelentation.
5989
5990 - Function: open-base filename mutable
5991 Returns an open low-level database associated with FILENAME. If
5992 MUTABLE? is `#t', this database will have methods capable of
5993 effecting change to the database. If MUTABLE? is `#f', only
5994 methods for inquiring the database will be available. If the
5995 database cannot be opened as specified `#f' is returned.
5996
5997 Calling the `close-base' (and possibly other) method on a MUTABLE?
5998 database will cause FILENAME to be written to.
5999
6000 - Function: write-base lldb filename
6001 Causes the low-level database LLDB to be written to FILENAME. If
6002 the write is successful, also causes LLDB to henceforth be
6003 associated with FILENAME. Calling the `close-database' (and
6004 possibly other) method on LLDB may cause FILENAME to be written
6005 to. If FILENAME is `#f' this database will be changed to a
6006 temporary, non-disk based database if such can be supported by the
6007 underlying base table implelentation. If the operations completed
6008 successfully, `#t' is returned. Otherwise, `#f' is returned.
6009
6010 - Function: sync-base lldb
6011 Causes the file associated with the low-level database LLDB to be
6012 updated to reflect its current state. If the associated filename
6013 is `#f', no action is taken and `#f' is returned. If this
6014 operation completes successfully, `#t' is returned. Otherwise,
6015 `#f' is returned.
6016
6017 - Function: close-base lldb
6018 Causes the low-level database LLDB to be written to its associated
6019 file (if any). If the write is successful, subsequent operations
6020 to LLDB will signal an error. If the operations complete
6021 successfully, `#t' is returned. Otherwise, `#f' is returned.
6022
6023 - Function: make-table lldb key-dimension column-types
6024 Returns the BASE-ID for a new base table, otherwise returns `#f'.
6025 The base table can then be opened using `(open-table LLDB
6026 BASE-ID)'. The positive integer KEY-DIMENSION is the number of
6027 keys composed to make a PRIMARY-KEY for this table. The list of
6028 symbols COLUMN-TYPES describes the types of each column.
6029
6030 - Constant: catalog-id
6031 A constant BASE-ID suitable for passing as a parameter to
6032 `open-table'. CATALOG-ID will be used as the base table for the
6033 system catalog.
6034
6035 - Function: open-table lldb base-id key-dimension column-types
6036 Returns a HANDLE for an existing base table in the low-level
6037 database LLDB if that table exists and can be opened in the mode
6038 indicated by MUTABLE?, otherwise returns `#f'.
6039
6040 As with `make-table', the positive integer KEY-DIMENSION is the
6041 number of keys composed to make a PRIMARY-KEY for this table. The
6042 list of symbols COLUMN-TYPES describes the types of each column.
6043
6044 - Function: kill-table lldb base-id key-dimension column-types
6045 Returns `#t' if the base table associated with BASE-ID was removed
6046 from the low level database LLDB, and `#f' otherwise.
6047
6048 - Function: make-keyifier-1 type
6049 Returns a procedure which accepts a single argument which must be
6050 of type TYPE. This returned procedure returns an object suitable
6051 for being a KEY argument in the functions whose descriptions
6052 follow.
6053
6054 Any 2 arguments of the supported type passed to the returned
6055 function which are not `equal?' must result in returned values
6056 which are not `equal?'.
6057
6058 - Function: make-list-keyifier key-dimension types
6059 The list of symbols TYPES must have at least KEY-DIMENSION
6060 elements. Returns a procedure which accepts a list of length
6061 KEY-DIMENSION and whose types must corresopond to the types named
6062 by TYPES. This returned procedure combines the elements of its
6063 list argument into an object suitable for being a KEY argument in
6064 the functions whose descriptions follow.
6065
6066 Any 2 lists of supported types (which must at least include
6067 symbols and non-negative integers) passed to the returned function
6068 which are not `equal?' must result in returned values which are not
6069 `equal?'.
6070
6071 - Function: make-key-extractor key-dimension types column-number
6072 Returns a procedure which accepts objects produced by application
6073 of the result of `(make-list-keyifier KEY-DIMENSION TYPES)'. This
6074 procedure returns a KEY which is `equal?' to the COLUMN-NUMBERth
6075 element of the list which was passed to create COMBINED-KEY. The
6076 list TYPES must have at least KEY-DIMENSION elements.
6077
6078 - Function: make-key->list key-dimension types
6079 Returns a procedure which accepts objects produced by application
6080 of the result of `(make-list-keyifier KEY-DIMENSION TYPES)'. This
6081 procedure returns a list of KEYs which are elementwise `equal?' to
6082 the list which was passed to create COMBINED-KEY.
6083
6084 In the following functions, the KEY argument can always be assumed to
6085 be the value returned by a call to a _keyify_ routine.
6086
6087 In contrast, a MATCH-KEYS argument is a list of length equal to the
6088 number of primary keys. The MATCH-KEYS restrict the actions of the
6089 table command to those records whose primary keys all satisfy the
6090 corresponding element of the MATCH-KEYS list. The elements and their
6091 actions are:
6092
6093 `#f'
6094 The false value matches any key in the corresponding position.
6095
6096 an object of type procedure
6097 This procedure must take a single argument, the key in the
6098 corresponding position. Any key for which the procedure
6099 returns a non-false value is a match; Any key for which the
6100 procedure returns a `#f' is not.
6101
6102 other values
6103 Any other value matches only those keys `equal?' to it.
6104
6105 The KEY-DIMENSION and COLUMN-TYPES arguments are needed to decode the
6106 combined-keys for matching with MATCH-KEYS.
6107
6108 - Function: for-each-key handle procedure key-dimension column-types
6109 match-keys
6110 Calls PROCEDURE once with each KEY in the table opened in HANDLE
6111 which satisfy MATCH-KEYS in an unspecified order. An unspecified
6112 value is returned.
6113
6114 - Function: map-key handle procedure key-dimension column-types
6115 match-keys
6116 Returns a list of the values returned by calling PROCEDURE once
6117 with each KEY in the table opened in HANDLE which satisfy
6118 MATCH-KEYS in an unspecified order.
6119
6120 - Function: ordered-for-each-key handle procedure key-dimension
6121 column-types match-keys
6122 Calls PROCEDURE once with each KEY in the table opened in HANDLE
6123 which satisfy MATCH-KEYS in the natural order for the types of the
6124 primary key fields of that table. An unspecified value is
6125 returned.
6126
6127 - Function: delete* handle key-dimension column-types match-keys
6128 Removes all rows which satisfy MATCH-KEYS from the table opened in
6129 HANDLE. An unspecified value is returned.
6130
6131 - Function: present? handle key
6132 Returns a non-`#f' value if there is a row associated with KEY in
6133 the table opened in HANDLE and `#f' otherwise.
6134
6135 - Function: delete handle key
6136 Removes the row associated with KEY from the table opened in
6137 HANDLE. An unspecified value is returned.
6138
6139 - Function: make-getter key-dimension types
6140 Returns a procedure which takes arguments HANDLE and KEY. This
6141 procedure returns a list of the non-primary values of the relation
6142 (in the base table opened in HANDLE) whose primary key is KEY if
6143 it exists, and `#f' otherwise.
6144
6145 - Function: make-putter key-dimension types
6146 Returns a procedure which takes arguments HANDLE and KEY and
6147 VALUE-LIST. This procedure associates the primary key KEY with
6148 the values in VALUE-LIST (in the base table opened in HANDLE) and
6149 returns an unspecified value.
6150
6151 - Function: supported-type? symbol
6152 Returns `#t' if SYMBOL names a type allowed as a column value by
6153 the implementation, and `#f' otherwise. At a minimum, an
6154 implementation must support the types `integer', `symbol',
6155 `string', `boolean', and `base-id'.
6156
6157 - Function: supported-key-type? symbol
6158 Returns `#t' if SYMBOL names a type allowed as a key value by the
6159 implementation, and `#f' otherwise. At a minimum, an
6160 implementation must support the types `integer', and `symbol'.
6161
6162 `integer'
6163 Scheme exact integer.
6164
6165 `symbol'
6166 Scheme symbol.
6167
6168 `boolean'
6169 `#t' or `#f'.
6170
6171 `base-id'
6172 Objects suitable for passing as the BASE-ID parameter to
6173 `open-table'. The value of CATALOG-ID must be an acceptable
6174 `base-id'.
6175
6176 \1f
6177 File: slib.info, Node: Relational Database, Next: Weight-Balanced Trees, Prev: Base Table, Up: Database Packages
6178
6179 Relational Database
6180 ===================
6181
6182 `(require 'relational-database)'
6183
6184 This package implements a database system inspired by the Relational
6185 Model (`E. F. Codd, A Relational Model of Data for Large Shared Data
6186 Banks'). An SLIB relational database implementation can be created
6187 from any *Note Base Table:: implementation.
6188
6189 * Menu:
6190
6191 * Motivations:: Database Manifesto
6192 * Creating and Opening Relational Databases::
6193 * Relational Database Operations::
6194 * Table Operations::
6195 * Catalog Representation::
6196 * Unresolved Issues::
6197 * Database Utilities:: 'database-utilities
6198 * Database Reports::
6199 * Database Browser:: 'database-browse
6200
6201 \1f
6202 File: slib.info, Node: Motivations, Next: Creating and Opening Relational Databases, Prev: Relational Database, Up: Relational Database
6203
6204 Motivations
6205 -----------
6206
6207 Most nontrivial programs contain databases: Makefiles, configure
6208 scripts, file backup, calendars, editors, source revision control, CAD
6209 systems, display managers, menu GUIs, games, parsers, debuggers,
6210 profilers, and even error reporting are all rife with databases. Coding
6211 databases is such a common activity in programming that many may not be
6212 aware of how often they do it.
6213
6214 A database often starts as a dispatch in a program. The author,
6215 perhaps because of the need to make the dispatch configurable, the need
6216 for correlating dispatch in other routines, or because of changes or
6217 growth, devises a data structure to contain the information, a routine
6218 for interpreting that data structure, and perhaps routines for
6219 augmenting and modifying the stored data. The dispatch must be
6220 converted into this form and tested.
6221
6222 The programmer may need to devise an interactive program for enabling
6223 easy examination and modification of the information contained in this
6224 database. Often, in an attempt to foster modularity and avoid delays in
6225 release, intermediate file formats for the database information are
6226 devised. It often turns out that users prefer modifying these
6227 intermediate files with a text editor to using the interactive program
6228 in order to do operations (such as global changes) not forseen by the
6229 program's author.
6230
6231 In order to address this need, the conscientious software engineer may
6232 even provide a scripting language to allow users to make repetitive
6233 database changes. Users will grumble that they need to read a large
6234 manual and learn yet another programming language (even if it _almost_
6235 has language "xyz" syntax) in order to do simple configuration.
6236
6237 All of these facilities need to be designed, coded, debugged,
6238 documented, and supported; often causing what was very simple in concept
6239 to become a major developement project.
6240
6241 This view of databases just outlined is somewhat the reverse of the
6242 view of the originators of the "Relational Model" of database
6243 abstraction. The relational model was devised to unify and allow
6244 interoperation of large multi-user databases running on diverse
6245 platforms. A fairly general purpose "Comprehensive Language" for
6246 database manipulations is mandated (but not specified) as part of the
6247 relational model for databases.
6248
6249 One aspect of the Relational Model of some importance is that the
6250 "Comprehensive Language" must be expressible in some form which can be
6251 stored in the database. This frees the programmer from having to make
6252 programs data-driven in order to use a database.
6253
6254 This package includes as one of its basic supported types Scheme
6255 "expression"s. This type allows expressions as defined by the Scheme
6256 standards to be stored in the database. Using `slib:eval' retrieved
6257 expressions can be evaluated (in the top-level environment). Scheme's
6258 `lambda' facilitates closure of environments, modularity, etc. so that
6259 procedures (which could not be stored directly most databases) can
6260 still be effectively retrieved. Since `slib:eval' evaluates
6261 expressions in the top-level environment, built-in and user defined
6262 procedures can be easily accessed by name.
6263
6264 This package's purpose is to standardize (through a common interface)
6265 database creation and usage in Scheme programs. The relational model's
6266 provision for inclusion of language expressions as data as well as the
6267 description (in tables, of course) of all of its tables assures that
6268 relational databases are powerful enough to assume the roles currently
6269 played by thousands of ad-hoc routines and data formats.
6270
6271 Such standardization to a relational-like model brings many benefits:
6272
6273 * Tables, fields, domains, and types can be dealt with by name in
6274 programs.
6275
6276 * The underlying database implementation can be changed (for
6277 performance or other reasons) by changing a single line of code.
6278
6279 * The formats of tables can be easily extended or changed without
6280 altering code.
6281
6282 * Consistency checks are specified as part of the table descriptions.
6283 Changes in checks need only occur in one place.
6284
6285 * All the configuration information which the developer wishes to
6286 group together is easily grouped, without needing to change
6287 programs aware of only some of these tables.
6288
6289 * Generalized report generators, interactive entry programs, and
6290 other database utilities can be part of a shared library. The
6291 burden of adding configurability to a program is greatly reduced.
6292
6293 * Scheme is the "comprehensive language" for these databases.
6294 Scripting for configuration no longer needs to be in a separate
6295 language with additional documentation.
6296
6297 * Scheme's latent types mesh well with the strict typing and logical
6298 requirements of the relational model.
6299
6300 * Portable formats allow easy interchange of data. The included
6301 table descriptions help prevent misinterpretation of format.
6302
6303 \1f
6304 File: slib.info, Node: Creating and Opening Relational Databases, Next: Relational Database Operations, Prev: Motivations, Up: Relational Database
6305
6306 Creating and Opening Relational Databases
6307 -----------------------------------------
6308
6309 - Function: make-relational-system base-table-implementation
6310 Returns a procedure implementing a relational database using the
6311 BASE-TABLE-IMPLEMENTATION.
6312
6313 All of the operations of a base table implementation are accessed
6314 through a procedure defined by `require'ing that implementation.
6315 Similarly, all of the operations of the relational database
6316 implementation are accessed through the procedure returned by
6317 `make-relational-system'. For instance, a new relational database
6318 could be created from the procedure returned by
6319 `make-relational-system' by:
6320
6321 (require 'alist-table)
6322 (define relational-alist-system
6323 (make-relational-system alist-table))
6324 (define create-alist-database
6325 (relational-alist-system 'create-database))
6326 (define my-database
6327 (create-alist-database "mydata.db"))
6328
6329 What follows are the descriptions of the methods available from
6330 relational system returned by a call to `make-relational-system'.
6331
6332 - Function: create-database filename
6333 Returns an open, nearly empty relational database associated with
6334 FILENAME. The only tables defined are the system catalog and
6335 domain table. Calling the `close-database' method on this database
6336 and possibly other operations will cause FILENAME to be written
6337 to. If FILENAME is `#f' a temporary, non-disk based database will
6338 be created if such can be supported by the underlying base table
6339 implelentation. If the database cannot be created as specified
6340 `#f' is returned. For the fields and layout of descriptor tables,
6341 *Note Catalog Representation::
6342
6343 - Function: open-database filename mutable?
6344 Returns an open relational database associated with FILENAME. If
6345 MUTABLE? is `#t', this database will have methods capable of
6346 effecting change to the database. If MUTABLE? is `#f', only
6347 methods for inquiring the database will be available. Calling the
6348 `close-database' (and possibly other) method on a MUTABLE?
6349 database will cause FILENAME to be written to. If the database
6350 cannot be opened as specified `#f' is returned.
6351
6352 \1f
6353 File: slib.info, Node: Relational Database Operations, Next: Table Operations, Prev: Creating and Opening Relational Databases, Up: Relational Database
6354
6355 Relational Database Operations
6356 ------------------------------
6357
6358 These are the descriptions of the methods available from an open
6359 relational database. A method is retrieved from a database by calling
6360 the database with the symbol name of the operation. For example:
6361
6362 (define my-database
6363 (create-alist-database "mydata.db"))
6364 (define telephone-table-desc
6365 ((my-database 'create-table) 'telephone-table-desc))
6366
6367 - Function: close-database
6368 Causes the relational database to be written to its associated
6369 file (if any). If the write is successful, subsequent operations
6370 to this database will signal an error. If the operations completed
6371 successfully, `#t' is returned. Otherwise, `#f' is returned.
6372
6373 - Function: write-database filename
6374 Causes the relational database to be written to FILENAME. If the
6375 write is successful, also causes the database to henceforth be
6376 associated with FILENAME. Calling the `close-database' (and
6377 possibly other) method on this database will cause FILENAME to be
6378 written to. If FILENAME is `#f' this database will be changed to
6379 a temporary, non-disk based database if such can be supported by
6380 the underlying base table implelentation. If the operations
6381 completed successfully, `#t' is returned. Otherwise, `#f' is
6382 returned.
6383
6384 - Function: sync-database |
6385 Causes any pending updates to the database file to be written out. |
6386 If the operations completed successfully, `#t' is returned. |
6387 Otherwise, `#f' is returned. |
6388 |
6389 - Function: table-exists? table-name
6390 Returns `#t' if TABLE-NAME exists in the system catalog, otherwise
6391 returns `#f'.
6392
6393 - Function: open-table table-name mutable?
6394 Returns a "methods" procedure for an existing relational table in
6395 this database if it exists and can be opened in the mode indicated
6396 by MUTABLE?, otherwise returns `#f'.
6397
6398 These methods will be present only in databases which are MUTABLE?.
6399
6400 - Function: delete-table table-name
6401 Removes and returns the TABLE-NAME row from the system catalog if
6402 the table or view associated with TABLE-NAME gets removed from the
6403 database, and `#f' otherwise.
6404
6405 - Function: create-table table-desc-name
6406 Returns a methods procedure for a new (open) relational table for
6407 describing the columns of a new base table in this database,
6408 otherwise returns `#f'. For the fields and layout of descriptor
6409 tables, *Note Catalog Representation::.
6410
6411 - Function: create-table table-name table-desc-name
6412 Returns a methods procedure for a new (open) relational table with
6413 columns as described by TABLE-DESC-NAME, otherwise returns `#f'.
6414
6415 - Function: create-view ??
6416 - Function: project-table ??
6417 - Function: restrict-table ??
6418 - Function: cart-prod-tables ??
6419 Not yet implemented.
6420
6421 \1f
6422 File: slib.info, Node: Table Operations, Next: Catalog Representation, Prev: Relational Database Operations, Up: Relational Database
6423
6424 Table Operations
6425 ----------------
6426
6427 These are the descriptions of the methods available from an open
6428 relational table. A method is retrieved from a table by calling the
6429 table with the symbol name of the operation. For example:
6430
6431 (define telephone-table-desc
6432 ((my-database 'create-table) 'telephone-table-desc))
6433 (require 'common-list-functions)
6434 (define ndrp (telephone-table-desc 'row:insert))
6435 (ndrp '(1 #t name #f string))
6436 (ndrp '(2 #f telephone
6437 (lambda (d)
6438 (and (string? d) (> (string-length d) 2)
6439 (every
6440 (lambda (c)
6441 (memv c '(#\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9
6442 #\+ #\( #\ #\) #\-)))
6443 (string->list d))))
6444 string))
6445
6446 Some operations described below require primary key arguments. Primary
6447 keys arguments are denoted KEY1 KEY2 .... It is an error to call an
6448 operation for a table which takes primary key arguments with the wrong
6449 number of primary keys for that table.
6450
6451 The term "row" used below refers to a Scheme list of values (one for
6452 each column) in the order specified in the descriptor (table) for this
6453 table. Missing values appear as `#f'. Primary keys must not be
6454 missing.
6455
6456 - Function: get column-name
6457 Returns a procedure of arguments KEY1 KEY2 ... which returns the
6458 value for the COLUMN-NAME column of the row associated with
6459 primary keys KEY1, KEY2 ... if that row exists in the table, or
6460 `#f' otherwise.
6461
6462 ((plat 'get 'processor) 'djgpp) => i386
6463 ((plat 'get 'processor) 'be-os) => #f
6464
6465 - Function: get* column-name
6466 Returns a procedure of optional arguments MATCH-KEY1 ... which
6467 returns a list of the values for the specified column for all rows
6468 in this table. The optional MATCH-KEY1 ... arguments restrict
6469 actions to a subset of the table. See the match-key description
6470 below for details.
6471
6472 ((plat 'get* 'processor)) =>
6473 (i386 8086 i386 8086 i386 i386 8086 m68000
6474 m68000 m68000 m68000 m68000 powerpc)
6475
6476 ((plat 'get* 'processor) #f) =>
6477 (i386 8086 i386 8086 i386 i386 8086 m68000
6478 m68000 m68000 m68000 m68000 powerpc)
6479
6480 (define (a-key? key)
6481 (char=? #\a (string-ref (symbol->string key) 0)))
6482
6483 ((plat 'get* 'processor) a-key?) =>
6484 (m68000 m68000 m68000 m68000 m68000 powerpc)
6485
6486 ((plat 'get* 'name) a-key?) =>
6487 (atari-st-turbo-c atari-st-gcc amiga-sas/c-5.10
6488 amiga-aztec amiga-dice-c aix)
6489
6490 - Function: row:retrieve
6491 Returns a procedure of arguments KEY1 KEY2 ... which returns the
6492 row associated with primary keys KEY1, KEY2 ... if it exists, or
6493 `#f' otherwise.
6494
6495 ((plat 'row:retrieve) 'linux) => (linux i386 linux gcc)
6496 ((plat 'row:retrieve) 'multics) => #f
6497
6498 - Function: row:retrieve*
6499 Returns a procedure of optional arguments MATCH-KEY1 ... which
6500 returns a list of all rows in this table. The optional MATCH-KEY1
6501 ... arguments restrict actions to a subset of the table. See the
6502 match-key description below for details.
6503
6504 ((plat 'row:retrieve*) a-key?) =>
6505 ((atari-st-turbo-c m68000 atari turbo-c)
6506 (atari-st-gcc m68000 atari gcc)
6507 (amiga-sas/c-5.10 m68000 amiga sas/c)
6508 (amiga-aztec m68000 amiga aztec)
6509 (amiga-dice-c m68000 amiga dice-c)
6510 (aix powerpc aix -))
6511
6512 - Function: row:remove
6513 Returns a procedure of arguments KEY1 KEY2 ... which removes and
6514 returns the row associated with primary keys KEY1, KEY2 ... if it
6515 exists, or `#f' otherwise.
6516
6517 - Function: row:remove*
6518 Returns a procedure of optional arguments MATCH-KEY1 ... which
6519 removes and returns a list of all rows in this table. The optional
6520 MATCH-KEY1 ... arguments restrict actions to a subset of the
6521 table. See the match-key description below for details.
6522
6523 - Function: row:delete
6524 Returns a procedure of arguments KEY1 KEY2 ... which deletes the
6525 row associated with primary keys KEY1, KEY2 ... if it exists. The
6526 value returned is unspecified.
6527
6528 - Function: row:delete*
6529 Returns a procedure of optional arguments MATCH-KEY1 ... which
6530 Deletes all rows from this table. The optional MATCH-KEY1 ...
6531 arguments restrict deletions to a subset of the table. See the
6532 match-key description below for details. The value returned is
6533 unspecified. The descriptor table and catalog entry for this
6534 table are not affected.
6535
6536 - Function: row:update
6537 Returns a procedure of one argument, ROW, which adds the row, ROW,
6538 to this table. If a row for the primary key(s) specified by ROW
6539 already exists in this table, it will be overwritten. The value
6540 returned is unspecified.
6541
6542 - Function: row:update*
6543 Returns a procedure of one argument, ROWS, which adds each row in
6544 the list of rows, ROWS, to this table. If a row for the primary
6545 key specified by an element of ROWS already exists in this table,
6546 it will be overwritten. The value returned is unspecified.
6547
6548 - Function: row:insert
6549 Adds the row ROW to this table. If a row for the primary key(s)
6550 specified by ROW already exists in this table an error is
6551 signaled. The value returned is unspecified.
6552
6553 - Function: row:insert*
6554 Returns a procedure of one argument, ROWS, which adds each row in
6555 the list of rows, ROWS, to this table. If a row for the primary
6556 key specified by an element of ROWS already exists in this table,
6557 an error is signaled. The value returned is unspecified.
6558
6559 - Function: for-each-row
6560 Returns a procedure of arguments PROC MATCH-KEY1 ... which calls
6561 PROC with each ROW in this table in the (implementation-dependent)
6562 natural ordering for rows. The optional MATCH-KEY1 ... arguments
6563 restrict actions to a subset of the table. See the match-key
6564 description below for details.
6565
6566 _Real_ relational programmers would use some least-upper-bound join
6567 for every row to get them in order; But we don't have joins yet.
6568
6569 The (optional) MATCH-KEY1 ... arguments are used to restrict actions of
6570 a whole-table operation to a subset of that table. Those procedures
6571 (returned by methods) which accept match-key arguments will accept any
6572 number of match-key arguments between zero and the number of primary
6573 keys in the table. Any unspecified MATCH-KEY arguments default to `#f'.
6574
6575 The MATCH-KEY1 ... restrict the actions of the table command to those
6576 records whose primary keys each satisfy the corresponding MATCH-KEY
6577 argument. The arguments and their actions are:
6578
6579 `#f'
6580 The false value matches any key in the corresponding position.
6581
6582 an object of type procedure
6583 This procedure must take a single argument, the key in the
6584 corresponding position. Any key for which the procedure
6585 returns a non-false value is a match; Any key for which the
6586 procedure returns a `#f' is not.
6587
6588 other values
6589 Any other value matches only those keys `equal?' to it.
6590
6591 - Function: close-table
6592 Subsequent operations to this table will signal an error.
6593
6594 - Constant: column-names
6595 - Constant: column-foreigns
6596 - Constant: column-domains
6597 - Constant: column-types
6598 Return a list of the column names, foreign-key table names, domain
6599 names, or type names respectively for this table. These 4 methods
6600 are different from the others in that the list is returned, rather
6601 than a procedure to obtain the list.
6602
6603 - Constant: primary-limit
6604 Returns the number of primary keys fields in the relations in this
6605 table.
6606
6607 \1f
6608 File: slib.info, Node: Catalog Representation, Next: Unresolved Issues, Prev: Table Operations, Up: Relational Database
6609
6610 Catalog Representation
6611 ----------------------
6612
6613 Each database (in an implementation) has a "system catalog" which
6614 describes all the user accessible tables in that database (including
6615 itself).
6616
6617 The system catalog base table has the following fields. `PRI'
6618 indicates a primary key for that table.
6619
6620 PRI table-name
6621 column-limit the highest column number
6622 coltab-name descriptor table name
6623 bastab-id data base table identifier
6624 user-integrity-rule
6625 view-procedure A scheme thunk which, when called,
6626 produces a handle for the view. coltab
6627 and bastab are specified if and only if
6628 view-procedure is not.
6629
6630 Descriptors for base tables (not views) are tables (pointed to by
6631 system catalog). Descriptor (base) tables have the fields:
6632
6633 PRI column-number sequential integers from 1
6634 primary-key? boolean TRUE for primary key components
6635 column-name
6636 column-integrity-rule
6637 domain-name
6638
6639 A "primary key" is any column marked as `primary-key?' in the
6640 corresponding descriptor table. All the `primary-key?' columns must
6641 have lower column numbers than any non-`primary-key?' columns. Every
6642 table must have at least one primary key. Primary keys must be
6643 sufficient to distinguish all rows from each other in the table. All of
6644 the system defined tables have a single primary key.
6645
6646 This package currently supports tables having from 1 to 4 primary keys
6647 if there are non-primary columns, and any (natural) number if _all_
6648 columns are primary keys. If you need more than 4 primary keys, I would
6649 like to hear what you are doing!
6650
6651 A "domain" is a category describing the allowable values to occur in a
6652 column. It is described by a (base) table with the fields:
6653
6654 PRI domain-name
6655 foreign-table
6656 domain-integrity-rule
6657 type-id
6658 type-param
6659
6660 The "type-id" field value is a symbol. This symbol may be used by the
6661 underlying base table implementation in storing that field.
6662
6663 If the `foreign-table' field is non-`#f' then that field names a table
6664 from the catalog. The values for that domain must match a primary key
6665 of the table referenced by the TYPE-PARAM (or `#f', if allowed). This
6666 package currently does not support composite foreign-keys.
6667
6668 The types for which support is planned are:
6669 atom
6670 symbol
6671 string [<length>]
6672 number [<base>]
6673 money <currency>
6674 date-time
6675 boolean
6676
6677 foreign-key <table-name>
6678 expression
6679 virtual <expression>
6680
6681 \1f
6682 File: slib.info, Node: Unresolved Issues, Next: Database Utilities, Prev: Catalog Representation, Up: Relational Database
6683
6684 Unresolved Issues
6685 -----------------
6686
6687 Although `rdms.scm' is not large, I found it very difficult to write
6688 (six rewrites). I am not aware of any other examples of a generalized
6689 relational system (although there is little new in CS). I left out
6690 several aspects of the Relational model in order to simplify the job.
6691 The major features lacking (which might be addressed portably) are
6692 views, transaction boundaries, and protection.
6693
6694 Protection needs a model for specifying priveledges. Given how
6695 operations are accessed from handles it should not be difficult to
6696 restrict table accesses to those allowed for that user.
6697
6698 The system catalog has a field called `view-procedure'. This should
6699 allow a purely functional implementation of views. This will work but
6700 is unsatisfying for views resulting from a "select"ion (subset of
6701 rows); for whole table operations it will not be possible to reduce the
6702 number of keys scanned over when the selection is specified only by an
6703 opaque procedure.
6704
6705 Transaction boundaries present the most intriguing area. Transaction
6706 boundaries are actually a feature of the "Comprehensive Language" of the
6707 Relational database and not of the database. Scheme would seem to
6708 provide the opportunity for an extremely clean semantics for transaction
6709 boundaries since the builtin procedures with side effects are small in
6710 number and easily identified.
6711
6712 These side-effect builtin procedures might all be portably redefined
6713 to versions which properly handled transactions. Compiled library
6714 routines would need to be recompiled as well. Many system extensions
6715 (delete-file, system, etc.) would also need to be redefined.
6716
6717 There are 2 scope issues that must be resolved for multiprocess
6718 transaction boundaries:
6719
6720 Process scope
6721 The actions captured by a transaction should be only for the
6722 process which invoked the start of transaction. Although standard
6723 Scheme does not provide process primitives as such, `dynamic-wind'
6724 would provide a workable hook into process switching for many
6725 implementations.
6726
6727 Shared utilities with state
6728 Some shared utilities have state which should _not_ be part of a
6729 transaction. An example would be calling a pseudo-random number
6730 generator. If the success of a transaction depended on the
6731 pseudo-random number and failed, the state of the generator would
6732 be set back. Subsequent calls would keep returning the same
6733 number and keep failing.
6734
6735 Pseudo-random number generators are not reentrant; thus they would
6736 require locks in order to operate properly in a multiprocess
6737 environment. Are all examples of utilities whose state should not
6738 be part of transactions also non-reentrant? If so, perhaps
6739 suspending transaction capture for the duration of locks would
6740 solve this problem.
6741
6742 \1f
6743 File: slib.info, Node: Database Utilities, Next: Database Reports, Prev: Unresolved Issues, Up: Relational Database
6744
6745 Database Utilities
6746 ------------------
6747
6748 `(require 'database-utilities)'
6749
6750 This enhancement wraps a utility layer on `relational-database' which
6751 provides:
6752 * Automatic loading of the appropriate base-table package when
6753 opening a database.
6754
6755 * Automatic execution of initialization commands stored in database.
6756
6757 * Transparent execution of database commands stored in `*commands*'
6758 table in database.
6759
6760 Also included are utilities which provide:
6761 * Data definition from Scheme lists and
6762
6763 * Report generation
6764
6765 for any SLIB relational database.
6766
6767 - Function: create-database filename base-table-type
6768 Returns an open, nearly empty enhanced (with `*commands*' table)
6769 relational database (with base-table type BASE-TABLE-TYPE)
6770 associated with FILENAME.
6771
6772 - Function: open-database filename
6773 - Function: open-database filename base-table-type
6774 Returns an open enchanced relational database associated with
6775 FILENAME. The database will be opened with base-table type
6776 BASE-TABLE-TYPE) if supplied. If BASE-TABLE-TYPE is not supplied,
6777 `open-database' will attempt to deduce the correct
6778 base-table-type. If the database can not be opened or if it lacks
6779 the `*commands*' table, `#f' is returned.
6780
6781 - Function: open-database! filename
6782 - Function: open-database! filename base-table-type
6783 Returns _mutable_ open enchanced relational database ...
6784
6785 The table `*commands*' in an "enhanced" relational-database has the
6786 fields (with domains):
6787 PRI name symbol
6788 parameters parameter-list
6789 procedure expression
6790 documentation string
6791
6792 The `parameters' field is a foreign key (domain `parameter-list') of
6793 the `*catalog-data*' table and should have the value of a table
6794 described by `*parameter-columns*'. This `parameter-list' table
6795 describes the arguments suitable for passing to the associated command.
6796 The intent of this table is to be of a form such that different
6797 user-interfaces (for instance, pull-down menus or plain-text queries)
6798 can operate from the same table. A `parameter-list' table has the
6799 following fields:
6800 PRI index uint
6801 name symbol
6802 arity parameter-arity
6803 domain domain
6804 defaulter expression
6805 expander expression
6806 documentation string
6807
6808 The `arity' field can take the values:
6809
6810 `single'
6811 Requires a single parameter of the specified domain.
6812
6813 `optional'
6814 A single parameter of the specified domain or zero parameters is
6815 acceptable.
6816
6817 `boolean'
6818 A single boolean parameter or zero parameters (in which case `#f'
6819 is substituted) is acceptable.
6820
6821 `nary'
6822 Any number of parameters of the specified domain are acceptable.
6823 The argument passed to the command function is always a list of the
6824 parameters.
6825
6826 `nary1'
6827 One or more of parameters of the specified domain are acceptable.
6828 The argument passed to the command function is always a list of the
6829 parameters.
6830
6831 The `domain' field specifies the domain which a parameter or
6832 parameters in the `index'th field must satisfy.
6833
6834 The `defaulter' field is an expression whose value is either `#f' or
6835 a procedure of one argument (the parameter-list) which returns a _list_
6836 of the default value or values as appropriate. Note that since the
6837 `defaulter' procedure is called every time a default parameter is
6838 needed for this column, "sticky" defaults can be implemented using
6839 shared state with the domain-integrity-rule.
6840
6841 Invoking Commands
6842 .................
6843
6844 When an enhanced relational-database is called with a symbol which
6845 matches a NAME in the `*commands*' table, the associated procedure
6846 expression is evaluated and applied to the enhanced
6847 relational-database. A procedure should then be returned which the user
6848 can invoke on (optional) arguments.
6849
6850 The command `*initialize*' is special. If present in the
6851 `*commands*' table, `open-database' or `open-database!' will return the
6852 value of the `*initialize*' command. Notice that arbitrary code can be
6853 run when the `*initialize*' procedure is automatically applied to the
6854 enhanced relational-database.
6855
6856 Note also that if you wish to shadow or hide from the user
6857 relational-database methods described in *Note Relational Database
6858 Operations::, this can be done by a dispatch in the closure returned by
6859 the `*initialize*' expression rather than by entries in the
6860 `*commands*' table if it is desired that the underlying methods remain
6861 accessible to code in the `*commands*' table.
6862
6863 - Function: make-command-server rdb table-name
6864 Returns a procedure of 2 arguments, a (symbol) command and a
6865 call-back procedure. When this returned procedure is called, it
6866 looks up COMMAND in table TABLE-NAME and calls the call-back
6867 procedure with arguments:
6868 COMMAND
6869 The COMMAND
6870
6871 COMMAND-VALUE
6872 The result of evaluating the expression in the PROCEDURE
6873 field of TABLE-NAME and calling it with RDB.
6874
6875 PARAMETER-NAME
6876 A list of the "official" name of each parameter. Corresponds
6877 to the `name' field of the COMMAND's parameter-table.
6878
6879 POSITIONS
6880 A list of the positive integer index of each parameter.
6881 Corresponds to the `index' field of the COMMAND's
6882 parameter-table.
6883
6884 ARITIES
6885 A list of the arities of each parameter. Corresponds to the
6886 `arity' field of the COMMAND's parameter-table. For a
6887 description of `arity' see table above.
6888
6889 TYPES
6890 A list of the type name of each parameter. Correspnds to the
6891 `type-id' field of the contents of the `domain' of the
6892 COMMAND's parameter-table.
6893
6894 DEFAULTERS
6895 A list of the defaulters for each parameter. Corresponds to
6896 the `defaulters' field of the COMMAND's parameter-table.
6897
6898 DOMAIN-INTEGRITY-RULES
6899 A list of procedures (one for each parameter) which tests
6900 whether a value for a parameter is acceptable for that
6901 parameter. The procedure should be called with each datum in
6902 the list for `nary' arity parameters.
6903
6904 ALIASES
6905 A list of lists of `(alias parameter-name)'. There can be
6906 more than one alias per PARAMETER-NAME.
6907
6908 For information about parameters, *Note Parameter lists::. Here is an
6909 example of setting up a command with arguments and parsing those
6910 arguments from a `getopt' style argument list (*note Getopt::).
6911
6912 (require 'database-utilities)
6913 (require 'fluid-let)
6914 (require 'parameters)
6915 (require 'getopt)
6916
6917 (define my-rdb (create-database #f 'alist-table))
6918
6919 (define-tables my-rdb
6920 '(foo-params
6921 *parameter-columns*
6922 *parameter-columns*
6923 ((1 single-string single string
6924 (lambda (pl) '("str")) #f "single string")
6925 (2 nary-symbols nary symbol
6926 (lambda (pl) '()) #f "zero or more symbols")
6927 (3 nary1-symbols nary1 symbol
6928 (lambda (pl) '(symb)) #f "one or more symbols")
6929 (4 optional-number optional uint
6930 (lambda (pl) '()) #f "zero or one number")
6931 (5 flag boolean boolean
6932 (lambda (pl) '(#f)) #f "a boolean flag")))
6933 '(foo-pnames
6934 ((name string))
6935 ((parameter-index uint))
6936 (("s" 1)
6937 ("single-string" 1)
6938 ("n" 2)
6939 ("nary-symbols" 2)
6940 ("N" 3)
6941 ("nary1-symbols" 3)
6942 ("o" 4)
6943 ("optional-number" 4)
6944 ("f" 5)
6945 ("flag" 5)))
6946 '(my-commands
6947 ((name symbol))
6948 ((parameters parameter-list)
6949 (parameter-names parameter-name-translation)
6950 (procedure expression)
6951 (documentation string))
6952 ((foo
6953 foo-params
6954 foo-pnames
6955 (lambda (rdb) (lambda args (print args)))
6956 "test command arguments"))))
6957
6958 (define (dbutil:serve-command-line rdb command-table
6959 command argc argv)
6960 (set! argv (if (vector? argv) (vector->list argv) argv))
6961 ((make-command-server rdb command-table)
6962 command
6963 (lambda (comname comval options positions
6964 arities types defaulters dirs aliases)
6965 (apply comval (getopt->arglist
6966 argc argv options positions
6967 arities types defaulters dirs aliases)))))
6968
6969 (define (cmd . opts)
6970 (fluid-let ((*optind* 1))
6971 (printf "%-34s => "
6972 (call-with-output-string
6973 (lambda (pt) (write (cons 'cmd opts) pt))))
6974 (set! opts (cons "cmd" opts))
6975 (force-output)
6976 (dbutil:serve-command-line
6977 my-rdb 'my-commands 'foo (length opts) opts)))
6978
6979 (cmd) => ("str" () (symb) () #f)
6980 (cmd "-f") => ("str" () (symb) () #t)
6981 (cmd "--flag") => ("str" () (symb) () #t)
6982 (cmd "-o177") => ("str" () (symb) (177) #f)
6983 (cmd "-o" "177") => ("str" () (symb) (177) #f)
6984 (cmd "--optional" "621") => ("str" () (symb) (621) #f)
6985 (cmd "--optional=621") => ("str" () (symb) (621) #f)
6986 (cmd "-s" "speciality") => ("speciality" () (symb) () #f)
6987 (cmd "-sspeciality") => ("speciality" () (symb) () #f)
6988 (cmd "--single" "serendipity") => ("serendipity" () (symb) () #f)
6989 (cmd "--single=serendipity") => ("serendipity" () (symb) () #f)
6990 (cmd "-n" "gravity" "piety") => ("str" () (piety gravity) () #f)
6991 (cmd "-ngravity" "piety") => ("str" () (piety gravity) () #f)
6992 (cmd "--nary" "chastity") => ("str" () (chastity) () #f)
6993 (cmd "--nary=chastity" "") => ("str" () ( chastity) () #f)
6994 (cmd "-N" "calamity") => ("str" () (calamity) () #f)
6995 (cmd "-Ncalamity") => ("str" () (calamity) () #f)
6996 (cmd "--nary1" "surety") => ("str" () (surety) () #f)
6997 (cmd "--nary1=surety") => ("str" () (surety) () #f)
6998 (cmd "-N" "levity" "fealty") => ("str" () (fealty levity) () #f)
6999 (cmd "-Nlevity" "fealty") => ("str" () (fealty levity) () #f)
7000 (cmd "--nary1" "surety" "brevity") => ("str" () (brevity surety) () #f)
7001 (cmd "--nary1=surety" "brevity") => ("str" () (brevity surety) () #f)
7002 (cmd "-?")
7003 -|
7004 Usage: cmd [OPTION ARGUMENT ...] ...
7005
7006 -f, --flag
7007 -o, --optional[=]<number>
7008 -n, --nary[=]<symbols> ...
7009 -N, --nary1[=]<symbols> ...
7010 -s, --single[=]<string>
7011
7012 ERROR: getopt->parameter-list "unrecognized option" "-?"
7013
7014 Some commands are defined in all extended relational-databases. The
7015 are called just like *Note Relational Database Operations::.
7016
7017 - Function: add-domain domain-row
7018 Adds DOMAIN-ROW to the "domains" table if there is no row in the
7019 domains table associated with key `(car DOMAIN-ROW)' and returns
7020 `#t'. Otherwise returns `#f'.
7021
7022 For the fields and layout of the domain table, *Note Catalog
7023 Representation::. Currently, these fields are
7024 * domain-name
7025
7026 * foreign-table
7027
7028 * domain-integrity-rule
7029
7030 * type-id
7031
7032 * type-param
7033
7034 The following example adds 3 domains to the `build' database.
7035 `Optstring' is either a string or `#f'. `filename' is a string
7036 and `build-whats' is a symbol.
7037
7038 (for-each (build 'add-domain)
7039 '((optstring #f
7040 (lambda (x) (or (not x) (string? x)))
7041 string
7042 #f)
7043 (filename #f #f string #f)
7044 (build-whats #f #f symbol #f)))
7045
7046 - Function: delete-domain domain-name
7047 Removes and returns the DOMAIN-NAME row from the "domains" table.
7048
7049 - Function: domain-checker domain
7050 Returns a procedure to check an argument for conformance to domain
7051 DOMAIN.
7052
7053 Defining Tables
7054 ...............
7055
7056 - Procedure: define-tables rdb spec-0 ...
7057 Adds tables as specified in SPEC-0 ... to the open
7058 relational-database RDB. Each SPEC has the form:
7059
7060 (<name> <descriptor-name> <descriptor-name> <rows>)
7061 or
7062 (<name> <primary-key-fields> <other-fields> <rows>)
7063
7064 where <name> is the table name, <descriptor-name> is the symbol
7065 name of a descriptor table, <primary-key-fields> and
7066 <other-fields> describe the primary keys and other fields
7067 respectively, and <rows> is a list of data rows to be added to the
7068 table.
7069
7070 <primary-key-fields> and <other-fields> are lists of field
7071 descriptors of the form:
7072
7073 (<column-name> <domain>)
7074 or
7075 (<column-name> <domain> <column-integrity-rule>)
7076
7077 where <column-name> is the column name, <domain> is the domain of
7078 the column, and <column-integrity-rule> is an expression whose
7079 value is a procedure of one argument (which returns `#f' to signal
7080 an error).
7081
7082 If <domain> is not a defined domain name and it matches the name of
7083 this table or an already defined (in one of SPEC-0 ...) single key
7084 field table, a foriegn-key domain will be created for it.
7085
7086 The following example shows a new database with the name of `foo.db'
7087 being created with tables describing processor families and
7088 processor/os/compiler combinations.
7089
7090 The database command `define-tables' is defined to call `define-tables'
7091 with its arguments. The database is also configured to print `Welcome'
7092 when the database is opened. The database is then closed and reopened.
7093
7094 (require 'database-utilities)
7095 (define my-rdb (create-database "foo.db" 'alist-table))
7096
7097 (define-tables my-rdb
7098 '(*commands*
7099 ((name symbol))
7100 ((parameters parameter-list)
7101 (procedure expression)
7102 (documentation string))
7103 ((define-tables
7104 no-parameters
7105 no-parameter-names
7106 (lambda (rdb) (lambda specs (apply define-tables rdb specs)))
7107 "Create or Augment tables from list of specs")
7108 (*initialize*
7109 no-parameters
7110 no-parameter-names
7111 (lambda (rdb) (display "Welcome") (newline) rdb)
7112 "Print Welcome"))))
7113
7114 ((my-rdb 'define-tables)
7115 '(processor-family
7116 ((family atom))
7117 ((also-ran processor-family))
7118 ((m68000 #f)
7119 (m68030 m68000)
7120 (i386 8086)
7121 (8086 #f)
7122 (powerpc #f)))
7123
7124 '(platform
7125 ((name symbol))
7126 ((processor processor-family)
7127 (os symbol)
7128 (compiler symbol))
7129 ((aix powerpc aix -)
7130 (amiga-dice-c m68000 amiga dice-c)
7131 (amiga-aztec m68000 amiga aztec)
7132 (amiga-sas/c-5.10 m68000 amiga sas/c)
7133 (atari-st-gcc m68000 atari gcc)
7134 (atari-st-turbo-c m68000 atari turbo-c)
7135 (borland-c-3.1 8086 ms-dos borland-c)
7136 (djgpp i386 ms-dos gcc)
7137 (linux i386 linux gcc)
7138 (microsoft-c 8086 ms-dos microsoft-c)
7139 (os/2-emx i386 os/2 gcc)
7140 (turbo-c-2 8086 ms-dos turbo-c)
7141 (watcom-9.0 i386 ms-dos watcom))))
7142
7143 ((my-rdb 'close-database))
7144
7145 (set! my-rdb (open-database "foo.db" 'alist-table))
7146 -|
7147 Welcome
7148
7149 Listing Tables |
7150 .............. |
7151 |
7152 - Procedure: list-table-definition rdb table-name |
7153 If symbol TABLE-NAME exists in the open relational-database RDB, |
7154 then returns a list of the table-name, its primary key names and |
7155 domains, its other key names and domains, and the table's records |
7156 (as lists). Otherwise, returns #f. |
7157 |
7158 The list returned by `list-table-definition', when passed as an |
7159 argument to `define-tables', will recreate the table. |
7160 |
7161 \1f
7162 File: slib.info, Node: Database Reports, Next: Database Browser, Prev: Database Utilities, Up: Relational Database
7163
7164 Database Reports
7165 ----------------
7166
7167 Code for generating database reports is in `report.scm'. After writing
7168 it using `format', I discovered that Common-Lisp `format' is not
7169 useable for this application because there is no mechanismm for
7170 truncating fields. `report.scm' needs to be rewritten using `printf'.
7171
7172 - Procedure: create-report rdb destination report-name table
7173 - Procedure: create-report rdb destination report-name
7174 The symbol REPORT-NAME must be primary key in the table named
7175 `*reports*' in the relational database RDB. DESTINATION is a
7176 port, string, or symbol. If DESTINATION is a:
7177
7178 port
7179 The table is created as ascii text and written to that port.
7180
7181 string
7182 The table is created as ascii text and written to the file
7183 named by DESTINATION.
7184
7185 symbol
7186 DESTINATION is the primary key for a row in the table named
7187 *printers*.
7188
7189 The report is prepared as follows:
7190
7191 * `Format' (*note Format::) is called with the `header' field
7192 and the (list of) `column-names' of the table.
7193
7194 * `Format' is called with the `reporter' field and (on
7195 successive calls) each record in the natural order for the
7196 table. A count is kept of the number of newlines output by
7197 format. When the number of newlines to be output exceeds the
7198 number of lines per page, the set of lines will be broken if
7199 there are more than `minimum-break' left on this page and the
7200 number of lines for this row is larger or equal to twice
7201 `minimum-break'.
7202
7203 * `Format' is called with the `footer' field and the (list of)
7204 `column-names' of the table. The footer field should not
7205 output a newline.
7206
7207 * A new page is output.
7208
7209 * This entire process repeats until all the rows are output.
7210
7211 Each row in the table *reports* has the fields:
7212
7213 name
7214 The report name.
7215
7216 default-table
7217 The table to report on if none is specified.
7218
7219 header, footer
7220 A `format' string. At the beginning and end of each page
7221 respectively, `format' is called with this string and the (list of)
7222 column-names of this table.
7223
7224 reporter
7225 A `format' string. For each row in the table, `format' is called
7226 with this string and the row.
7227
7228 minimum-break
7229 The minimum number of lines into which the report lines for a row
7230 can be broken. Use `0' if a row's lines should not be broken over
7231 page boundaries.
7232
7233 Each row in the table *printers* has the fields:
7234
7235 name
7236 The printer name.
7237
7238 print-procedure
7239 The procedure to call to actually print.
7240
7241 \1f
7242 File: slib.info, Node: Database Browser, Prev: Database Reports, Up: Relational Database
7243
7244 Database Browser
7245 ----------------
7246
7247 (require 'database-browse)
7248
7249 - Procedure: browse database
7250 Prints the names of all the tables in DATABASE and sets browse's
7251 default to DATABASE.
7252
7253 - Procedure: browse
7254 Prints the names of all the tables in the default database.
7255
7256 - Procedure: browse table-name
7257 For each record of the table named by the symbol TABLE-NAME,
7258 prints a line composed of all the field values.
7259
7260 - Procedure: browse pathname
7261 Opens the database named by the string PATHNAME, prints the names
7262 of all its tables, and sets browse's default to the database.
7263
7264 - Procedure: browse database table-name
7265 Sets browse's default to DATABASE and prints the records of the
7266 table named by the symbol TABLE-NAME.
7267
7268 - Procedure: browse pathname table-name
7269 Opens the database named by the string PATHNAME and sets browse's
7270 default to it; `browse' prints the records of the table named by
7271 the symbol TABLE-NAME.
7272
7273
7274 \1f
7275 File: slib.info, Node: Weight-Balanced Trees, Prev: Relational Database, Up: Database Packages
7276
7277 Weight-Balanced Trees
7278 =====================
7279
7280 `(require 'wt-tree)'
7281
7282 Balanced binary trees are a useful data structure for maintaining
7283 large sets of ordered objects or sets of associations whose keys are
7284 ordered. MIT Scheme has an comprehensive implementation of
7285 weight-balanced binary trees which has several advantages over the
7286 other data structures for large aggregates:
7287
7288 * In addition to the usual element-level operations like insertion,
7289 deletion and lookup, there is a full complement of collection-level
7290 operations, like set intersection, set union and subset test, all
7291 of which are implemented with good orders of growth in time and
7292 space. This makes weight balanced trees ideal for rapid
7293 prototyping of functionally derived specifications.
7294
7295 * An element in a tree may be indexed by its position under the
7296 ordering of the keys, and the ordinal position of an element may
7297 be determined, both with reasonable efficiency.
7298
7299 * Operations to find and remove minimum element make weight balanced
7300 trees simple to use for priority queues.
7301
7302 * The implementation is _functional_ rather than _imperative_. This
7303 means that operations like `inserting' an association in a tree do
7304 not destroy the old tree, in much the same way that `(+ 1 x)'
7305 modifies neither the constant 1 nor the value bound to `x'. The
7306 trees are referentially transparent thus the programmer need not
7307 worry about copying the trees. Referential transparency allows
7308 space efficiency to be achieved by sharing subtrees.
7309
7310
7311 These features make weight-balanced trees suitable for a wide range of
7312 applications, especially those that require large numbers of sets or
7313 discrete maps. Applications that have a few global databases and/or
7314 concentrate on element-level operations like insertion and lookup are
7315 probably better off using hash-tables or red-black trees.
7316
7317 The _size_ of a tree is the number of associations that it contains.
7318 Weight balanced binary trees are balanced to keep the sizes of the
7319 subtrees of each node within a constant factor of each other. This
7320 ensures logarithmic times for single-path operations (like lookup and
7321 insertion). A weight balanced tree takes space that is proportional to
7322 the number of associations in the tree. For the current
7323 implementation, the constant of proportionality is six words per
7324 association.
7325
7326 Weight balanced trees can be used as an implementation for either
7327 discrete sets or discrete maps (associations). Sets are implemented by
7328 ignoring the datum that is associated with the key. Under this scheme
7329 if an associations exists in the tree this indicates that the key of the
7330 association is a member of the set. Typically a value such as `()',
7331 `#t' or `#f' is associated with the key.
7332
7333 Many operations can be viewed as computing a result that, depending on
7334 whether the tree arguments are thought of as sets or maps, is known by
7335 two different names. An example is `wt-tree/member?', which, when
7336 regarding the tree argument as a set, computes the set membership
7337 operation, but, when regarding the tree as a discrete map,
7338 `wt-tree/member?' is the predicate testing if the map is defined at an
7339 element in its domain. Most names in this package have been chosen
7340 based on interpreting the trees as sets, hence the name
7341 `wt-tree/member?' rather than `wt-tree/defined-at?'.
7342
7343 The weight balanced tree implementation is a run-time-loadable option.
7344 To use weight balanced trees, execute
7345
7346 (load-option 'wt-tree)
7347
7348 once before calling any of the procedures defined here.
7349
7350 * Menu:
7351
7352 * Construction of Weight-Balanced Trees::
7353 * Basic Operations on Weight-Balanced Trees::
7354 * Advanced Operations on Weight-Balanced Trees::
7355 * Indexing Operations on Weight-Balanced Trees::
7356
7357 \1f
7358 File: slib.info, Node: Construction of Weight-Balanced Trees, Next: Basic Operations on Weight-Balanced Trees, Prev: Weight-Balanced Trees, Up: Weight-Balanced Trees
7359
7360 Construction of Weight-Balanced Trees
7361 -------------------------------------
7362
7363 Binary trees require there to be a total order on the keys used to
7364 arrange the elements in the tree. Weight balanced trees are organized
7365 by _types_, where the type is an object encapsulating the ordering
7366 relation. Creating a tree is a two-stage process. First a tree type
7367 must be created from the predicate which gives the ordering. The tree
7368 type is then used for making trees, either empty or singleton trees or
7369 trees from other aggregate structures like association lists. Once
7370 created, a tree `knows' its type and the type is used to test
7371 compatibility between trees in operations taking two trees. Usually a
7372 small number of tree types are created at the beginning of a program and
7373 used many times throughout the program's execution.
7374
7375 - procedure+: make-wt-tree-type key<?
7376 This procedure creates and returns a new tree type based on the
7377 ordering predicate KEY<?. KEY<? must be a total ordering, having
7378 the property that for all key values `a', `b' and `c':
7379
7380 (key<? a a) => #f
7381 (and (key<? a b) (key<? b a)) => #f
7382 (if (and (key<? a b) (key<? b c))
7383 (key<? a c)
7384 #t) => #t
7385
7386 Two key values are assumed to be equal if neither is less than the
7387 other by KEY<?.
7388
7389 Each call to `make-wt-tree-type' returns a distinct value, and
7390 trees are only compatible if their tree types are `eq?'. A
7391 consequence is that trees that are intended to be used in binary
7392 tree operations must all be created with a tree type originating
7393 from the same call to `make-wt-tree-type'.
7394
7395 - variable+: number-wt-type
7396 A standard tree type for trees with numeric keys. `Number-wt-type'
7397 could have been defined by
7398
7399 (define number-wt-type (make-wt-tree-type <))
7400
7401 - variable+: string-wt-type
7402 A standard tree type for trees with string keys. `String-wt-type'
7403 could have been defined by
7404
7405 (define string-wt-type (make-wt-tree-type string<?))
7406
7407 - procedure+: make-wt-tree wt-tree-type
7408 This procedure creates and returns a newly allocated weight
7409 balanced tree. The tree is empty, i.e. it contains no
7410 associations. WT-TREE-TYPE is a weight balanced tree type
7411 obtained by calling `make-wt-tree-type'; the returned tree has
7412 this type.
7413
7414 - procedure+: singleton-wt-tree wt-tree-type key datum
7415 This procedure creates and returns a newly allocated weight
7416 balanced tree. The tree contains a single association, that of
7417 DATUM with KEY. WT-TREE-TYPE is a weight balanced tree type
7418 obtained by calling `make-wt-tree-type'; the returned tree has
7419 this type.
7420
7421 - procedure+: alist->wt-tree tree-type alist
7422 Returns a newly allocated weight-balanced tree that contains the
7423 same associations as ALIST. This procedure is equivalent to:
7424
7425 (lambda (type alist)
7426 (let ((tree (make-wt-tree type)))
7427 (for-each (lambda (association)
7428 (wt-tree/add! tree
7429 (car association)
7430 (cdr association)))
7431 alist)
7432 tree))
7433
7434 \1f
7435 File: slib.info, Node: Basic Operations on Weight-Balanced Trees, Next: Advanced Operations on Weight-Balanced Trees, Prev: Construction of Weight-Balanced Trees, Up: Weight-Balanced Trees
7436
7437 Basic Operations on Weight-Balanced Trees
7438 -----------------------------------------
7439
7440 This section describes the basic tree operations on weight balanced
7441 trees. These operations are the usual tree operations for insertion,
7442 deletion and lookup, some predicates and a procedure for determining the
7443 number of associations in a tree.
7444
7445 - procedure+: wt-tree? object
7446 Returns `#t' if OBJECT is a weight-balanced tree, otherwise
7447 returns `#f'.
7448
7449 - procedure+: wt-tree/empty? wt-tree
7450 Returns `#t' if WT-TREE contains no associations, otherwise
7451 returns `#f'.
7452
7453 - procedure+: wt-tree/size wt-tree
7454 Returns the number of associations in WT-TREE, an exact
7455 non-negative integer. This operation takes constant time.
7456
7457 - procedure+: wt-tree/add wt-tree key datum
7458 Returns a new tree containing all the associations in WT-TREE and
7459 the association of DATUM with KEY. If WT-TREE already had an
7460 association for KEY, the new association overrides the old. The
7461 average and worst-case times required by this operation are
7462 proportional to the logarithm of the number of associations in
7463 WT-TREE.
7464
7465 - procedure+: wt-tree/add! wt-tree key datum
7466 Associates DATUM with KEY in WT-TREE and returns an unspecified
7467 value. If WT-TREE already has an association for KEY, that
7468 association is replaced. The average and worst-case times
7469 required by this operation are proportional to the logarithm of
7470 the number of associations in WT-TREE.
7471
7472 - procedure+: wt-tree/member? key wt-tree
7473 Returns `#t' if WT-TREE contains an association for KEY, otherwise
7474 returns `#f'. The average and worst-case times required by this
7475 operation are proportional to the logarithm of the number of
7476 associations in WT-TREE.
7477
7478 - procedure+: wt-tree/lookup wt-tree key default
7479 Returns the datum associated with KEY in WT-TREE. If WT-TREE
7480 doesn't contain an association for KEY, DEFAULT is returned. The
7481 average and worst-case times required by this operation are
7482 proportional to the logarithm of the number of associations in
7483 WT-TREE.
7484
7485 - procedure+: wt-tree/delete wt-tree key
7486 Returns a new tree containing all the associations in WT-TREE,
7487 except that if WT-TREE contains an association for KEY, it is
7488 removed from the result. The average and worst-case times required
7489 by this operation are proportional to the logarithm of the number
7490 of associations in WT-TREE.
7491
7492 - procedure+: wt-tree/delete! wt-tree key
7493 If WT-TREE contains an association for KEY the association is
7494 removed. Returns an unspecified value. The average and worst-case
7495 times required by this operation are proportional to the logarithm
7496 of the number of associations in WT-TREE.
7497
7498 \1f
7499 File: slib.info, Node: Advanced Operations on Weight-Balanced Trees, Next: Indexing Operations on Weight-Balanced Trees, Prev: Basic Operations on Weight-Balanced Trees, Up: Weight-Balanced Trees
7500
7501 Advanced Operations on Weight-Balanced Trees
7502 --------------------------------------------
7503
7504 In the following the _size_ of a tree is the number of associations
7505 that the tree contains, and a _smaller_ tree contains fewer
7506 associations.
7507
7508 - procedure+: wt-tree/split< wt-tree bound
7509 Returns a new tree containing all and only the associations in
7510 WT-TREE which have a key that is less than BOUND in the ordering
7511 relation of the tree type of WT-TREE. The average and worst-case
7512 times required by this operation are proportional to the logarithm
7513 of the size of WT-TREE.
7514
7515 - procedure+: wt-tree/split> wt-tree bound
7516 Returns a new tree containing all and only the associations in
7517 WT-TREE which have a key that is greater than BOUND in the
7518 ordering relation of the tree type of WT-TREE. The average and
7519 worst-case times required by this operation are proportional to the
7520 logarithm of size of WT-TREE.
7521
7522 - procedure+: wt-tree/union wt-tree-1 wt-tree-2
7523 Returns a new tree containing all the associations from both trees.
7524 This operation is asymmetric: when both trees have an association
7525 for the same key, the returned tree associates the datum from
7526 WT-TREE-2 with the key. Thus if the trees are viewed as discrete
7527 maps then `wt-tree/union' computes the map override of WT-TREE-1 by
7528 WT-TREE-2. If the trees are viewed as sets the result is the set
7529 union of the arguments. The worst-case time required by this
7530 operation is proportional to the sum of the sizes of both trees.
7531 If the minimum key of one tree is greater than the maximum key of
7532 the other tree then the time required is at worst proportional to
7533 the logarithm of the size of the larger tree.
7534
7535 - procedure+: wt-tree/intersection wt-tree-1 wt-tree-2
7536 Returns a new tree containing all and only those associations from
7537 WT-TREE-1 which have keys appearing as the key of an association
7538 in WT-TREE-2. Thus the associated data in the result are those
7539 from WT-TREE-1. If the trees are being used as sets the result is
7540 the set intersection of the arguments. As a discrete map
7541 operation, `wt-tree/intersection' computes the domain restriction
7542 of WT-TREE-1 to (the domain of) WT-TREE-2. The time required by
7543 this operation is never worse that proportional to the sum of the
7544 sizes of the trees.
7545
7546 - procedure+: wt-tree/difference wt-tree-1 wt-tree-2
7547 Returns a new tree containing all and only those associations from
7548 WT-TREE-1 which have keys that _do not_ appear as the key of an
7549 association in WT-TREE-2. If the trees are viewed as sets the
7550 result is the asymmetric set difference of the arguments. As a
7551 discrete map operation, it computes the domain restriction of
7552 WT-TREE-1 to the complement of (the domain of) WT-TREE-2. The
7553 time required by this operation is never worse that proportional to
7554 the sum of the sizes of the trees.
7555
7556 - procedure+: wt-tree/subset? wt-tree-1 wt-tree-2
7557 Returns `#t' iff the key of each association in WT-TREE-1 is the
7558 key of some association in WT-TREE-2, otherwise returns `#f'.
7559 Viewed as a set operation, `wt-tree/subset?' is the improper subset
7560 predicate. A proper subset predicate can be constructed:
7561
7562 (define (proper-subset? s1 s2)
7563 (and (wt-tree/subset? s1 s2)
7564 (< (wt-tree/size s1) (wt-tree/size s2))))
7565
7566 As a discrete map operation, `wt-tree/subset?' is the subset test
7567 on the domain(s) of the map(s). In the worst-case the time
7568 required by this operation is proportional to the size of
7569 WT-TREE-1.
7570
7571 - procedure+: wt-tree/set-equal? wt-tree-1 wt-tree-2
7572 Returns `#t' iff for every association in WT-TREE-1 there is an
7573 association in WT-TREE-2 that has the same key, and _vice versa_.
7574
7575 Viewing the arguments as sets `wt-tree/set-equal?' is the set
7576 equality predicate. As a map operation it determines if two maps
7577 are defined on the same domain.
7578
7579 This procedure is equivalent to
7580
7581 (lambda (wt-tree-1 wt-tree-2)
7582 (and (wt-tree/subset? wt-tree-1 wt-tree-2
7583 (wt-tree/subset? wt-tree-2 wt-tree-1)))
7584
7585 In the worst-case the time required by this operation is
7586 proportional to the size of the smaller tree.
7587
7588 - procedure+: wt-tree/fold combiner initial wt-tree
7589 This procedure reduces WT-TREE by combining all the associations,
7590 using an reverse in-order traversal, so the associations are
7591 visited in reverse order. COMBINER is a procedure of three
7592 arguments: a key, a datum and the accumulated result so far.
7593 Provided COMBINER takes time bounded by a constant, `wt-tree/fold'
7594 takes time proportional to the size of WT-TREE.
7595
7596 A sorted association list can be derived simply:
7597
7598 (wt-tree/fold (lambda (key datum list)
7599 (cons (cons key datum) list))
7600 '()
7601 WT-TREE))
7602
7603 The data in the associations can be summed like this:
7604
7605 (wt-tree/fold (lambda (key datum sum) (+ sum datum))
7606 0
7607 WT-TREE)
7608
7609 - procedure+: wt-tree/for-each action wt-tree
7610 This procedure traverses the tree in-order, applying ACTION to
7611 each association. The associations are processed in increasing
7612 order of their keys. ACTION is a procedure of two arguments which
7613 take the key and datum respectively of the association. Provided
7614 ACTION takes time bounded by a constant, `wt-tree/for-each' takes
7615 time proportional to in the size of WT-TREE. The example prints
7616 the tree:
7617
7618 (wt-tree/for-each (lambda (key value)
7619 (display (list key value)))
7620 WT-TREE))
7621
7622 \1f
7623 File: slib.info, Node: Indexing Operations on Weight-Balanced Trees, Prev: Advanced Operations on Weight-Balanced Trees, Up: Weight-Balanced Trees
7624
7625 Indexing Operations on Weight-Balanced Trees
7626 --------------------------------------------
7627
7628 Weight balanced trees support operations that view the tree as sorted
7629 sequence of associations. Elements of the sequence can be accessed by
7630 position, and the position of an element in the sequence can be
7631 determined, both in logarthmic time.
7632
7633 - procedure+: wt-tree/index wt-tree index
7634 - procedure+: wt-tree/index-datum wt-tree index
7635 - procedure+: wt-tree/index-pair wt-tree index
7636 Returns the 0-based INDEXth association of WT-TREE in the sorted
7637 sequence under the tree's ordering relation on the keys.
7638 `wt-tree/index' returns the INDEXth key, `wt-tree/index-datum'
7639 returns the datum associated with the INDEXth key and
7640 `wt-tree/index-pair' returns a new pair `(KEY . DATUM)' which is
7641 the `cons' of the INDEXth key and its datum. The average and
7642 worst-case times required by this operation are proportional to
7643 the logarithm of the number of associations in the tree.
7644
7645 These operations signal an error if the tree is empty, if
7646 INDEX`<0', or if INDEX is greater than or equal to the number of
7647 associations in the tree.
7648
7649 Indexing can be used to find the median and maximum keys in the
7650 tree as follows:
7651
7652 median: (wt-tree/index WT-TREE
7653 (quotient (wt-tree/size WT-TREE) 2))
7654
7655 maximum: (wt-tree/index WT-TREE
7656 (-1+ (wt-tree/size WT-TREE)))
7657
7658 - procedure+: wt-tree/rank wt-tree key
7659 Determines the 0-based position of KEY in the sorted sequence of
7660 the keys under the tree's ordering relation, or `#f' if the tree
7661 has no association with for KEY. This procedure returns either an
7662 exact non-negative integer or `#f'. The average and worst-case
7663 times required by this operation are proportional to the logarithm
7664 of the number of associations in the tree.
7665
7666 - procedure+: wt-tree/min wt-tree
7667 - procedure+: wt-tree/min-datum wt-tree
7668 - procedure+: wt-tree/min-pair wt-tree
7669 Returns the association of WT-TREE that has the least key under
7670 the tree's ordering relation. `wt-tree/min' returns the least key,
7671 `wt-tree/min-datum' returns the datum associated with the least key
7672 and `wt-tree/min-pair' returns a new pair `(key . datum)' which is
7673 the `cons' of the minimum key and its datum. The average and
7674 worst-case times required by this operation are proportional to the
7675 logarithm of the number of associations in the tree.
7676
7677 These operations signal an error if the tree is empty. They could
7678 be written
7679 (define (wt-tree/min tree) (wt-tree/index tree 0))
7680 (define (wt-tree/min-datum tree) (wt-tree/index-datum tree 0))
7681 (define (wt-tree/min-pair tree) (wt-tree/index-pair tree 0))
7682
7683 - procedure+: wt-tree/delete-min wt-tree
7684 Returns a new tree containing all of the associations in WT-TREE
7685 except the association with the least key under the WT-TREE's
7686 ordering relation. An error is signalled if the tree is empty.
7687 The average and worst-case times required by this operation are
7688 proportional to the logarithm of the number of associations in the
7689 tree. This operation is equivalent to
7690
7691 (wt-tree/delete WT-TREE (wt-tree/min WT-TREE))
7692
7693 - procedure+: wt-tree/delete-min! wt-tree
7694 Removes the association with the least key under the WT-TREE's
7695 ordering relation. An error is signalled if the tree is empty.
7696 The average and worst-case times required by this operation are
7697 proportional to the logarithm of the number of associations in the
7698 tree. This operation is equivalent to
7699
7700 (wt-tree/delete! WT-TREE (wt-tree/min WT-TREE))
7701
7702 \1f
7703 File: slib.info, Node: Other Packages, Next: About SLIB, Prev: Database Packages, Up: Top
7704
7705 Other Packages
7706 **************
7707
7708 * Menu:
7709
7710 * Data Structures:: Various data structures.
7711 * Procedures:: Miscellaneous utility procedures.
7712 * Standards Support:: Support for Scheme Standards.
7713 * Session Support:: REPL and Debugging.
7714 * Extra-SLIB Packages::
7715
7716 \1f
7717 File: slib.info, Node: Data Structures, Next: Procedures, Prev: Other Packages, Up: Other Packages
7718
7719 Data Structures
7720 ===============
7721
7722 * Menu:
7723
7724 * Arrays:: 'array
7725 * Array Mapping:: 'array-for-each
7726 * Association Lists:: 'alist
7727 * Byte:: 'byte
7728 * Portable Image Files:: 'pnm
7729 * Collections:: 'collect
7730 * Dynamic Data Type:: 'dynamic
7731 * Hash Tables:: 'hash-table
7732 * Hashing:: 'hash, 'sierpinski, 'soundex
7733 * Object:: 'object
7734 * Priority Queues:: 'priority-queue
7735 * Queues:: 'queue
7736 * Records:: 'record
7737 * Structures:: 'struct, 'structure
7738
7739 \1f
7740 File: slib.info, Node: Arrays, Next: Array Mapping, Prev: Data Structures, Up: Data Structures
7741
7742 Arrays
7743 ------
7744
7745 `(require 'array)'
7746
7747 - Function: array? obj
7748 Returns `#t' if the OBJ is an array, and `#f' if not.
7749
7750 - Function: make-array initial-value bound1 bound2 ...
7751 Creates and returns an array that has as many dimensins as there
7752 are BOUNDs and fills it with INITIAL-VALUE.
7753
7754 When constructing an array, BOUND is either an inclusive range of
7755 indices expressed as a two element list, or an upper bound expressed as
7756 a single integer. So
7757 (make-array 'foo 3 3) == (make-array 'foo '(0 2) '(0 2))
7758
7759 - Function: make-shared-array array mapper bound1 bound2 ...
7760 `make-shared-array' can be used to create shared subarrays of other
7761 arrays. The MAPPER is a function that translates coordinates in
7762 the new array into coordinates in the old array. A MAPPER must be
7763 linear, and its range must stay within the bounds of the old
7764 array, but it can be otherwise arbitrary. A simple example:
7765 (define fred (make-array #f 8 8))
7766 (define freds-diagonal
7767 (make-shared-array fred (lambda (i) (list i i)) 8))
7768 (array-set! freds-diagonal 'foo 3)
7769 (array-ref fred 3 3)
7770 => FOO
7771 (define freds-center
7772 (make-shared-array fred (lambda (i j) (list (+ 3 i) (+ 3 j)))
7773 2 2))
7774 (array-ref freds-center 0 0)
7775 => FOO
7776
7777 - Function: array-rank obj
7778 Returns the number of dimensions of OBJ. If OBJ is not an array,
7779 0 is returned.
7780
7781 - Function: array-shape array
7782 `array-shape' returns a list of inclusive bounds. So:
7783 (array-shape (make-array 'foo 3 5))
7784 => ((0 2) (0 4))
7785
7786 - Function: array-dimensions array
7787 `array-dimensions' is similar to `array-shape' but replaces
7788 elements with a 0 minimum with one greater than the maximum. So:
7789 (array-dimensions (make-array 'foo 3 5))
7790 => (3 5)
7791
7792 - Procedure: array-in-bounds? array index1 index2 ...
7793 Returns `#t' if its arguments would be acceptable to `array-ref'.
7794
7795 - Function: array-ref array index1 index2 ...
7796 Returns the element at the `(INDEX1, INDEX2)' element in ARRAY.
7797
7798 - Procedure: array-set! array new-value index1 index2 ...
7799
7800 - Function: array-1d-ref array index
7801 - Function: array-2d-ref array index1 index2
7802 - Function: array-3d-ref array index1 index2 index3
7803
7804 - Procedure: array-1d-set! array new-value index
7805 - Procedure: array-2d-set! array new-value index1 index2
7806 - Procedure: array-3d-set! array new-value index1 index2 index3
7807
7808 The functions are just fast versions of `array-ref' and `array-set!'
7809 that take a fixed number of arguments, and perform no bounds checking.
7810
7811 If you comment out the bounds checking code, this is about as
7812 efficient as you could ask for without help from the compiler.
7813
7814 An exercise left to the reader: implement the rest of APL.
7815
7816 \1f
7817 File: slib.info, Node: Array Mapping, Next: Association Lists, Prev: Arrays, Up: Data Structures
7818
7819 Array Mapping
7820 -------------
7821
7822 `(require 'array-for-each)'
7823
7824 - Function: array-map! array0 proc array1 ...
7825 ARRAY1, ... must have the same number of dimensions as ARRAY0 and
7826 have a range for each index which includes the range for the
7827 corresponding index in ARRAY0. PROC is applied to each tuple of
7828 elements of ARRAY1 ... and the result is stored as the
7829 corresponding element in ARRAY0. The value returned is
7830 unspecified. The order of application is unspecified.
7831
7832 - Function: array-for-each PROC ARRAY0 ...
7833 PROC is applied to each tuple of elements of ARRAY0 ... in
7834 row-major order. The value returned is unspecified.
7835
7836 - Function: array-indexes ARRAY
7837 Returns an array of lists of indexes for ARRAY such that, if LI is
7838 a list of indexes for which ARRAY is defined, (equal? LI (apply
7839 array-ref (array-indexes ARRAY) LI)).
7840
7841 - Function: array-index-map! array proc
7842 applies PROC to the indices of each element of ARRAY in turn,
7843 storing the result in the corresponding element. The value
7844 returned and the order of application are unspecified.
7845
7846 One can implement ARRAY-INDEXES as
7847 (define (array-indexes array)
7848 (let ((ra (apply make-array #f (array-shape array))))
7849 (array-index-map! ra (lambda x x))
7850 ra))
7851 Another example:
7852 (define (apl:index-generator n)
7853 (let ((v (make-uniform-vector n 1)))
7854 (array-index-map! v (lambda (i) i))
7855 v))
7856
7857 - Function: array-copy! source destination
7858 Copies every element from vector or array SOURCE to the
7859 corresponding element of DESTINATION. DESTINATION must have the
7860 same rank as SOURCE, and be at least as large in each dimension.
7861 The order of copying is unspecified.
7862
7863 \1f
7864 File: slib.info, Node: Association Lists, Next: Byte, Prev: Array Mapping, Up: Data Structures
7865
7866 Association Lists
7867 -----------------
7868
7869 `(require 'alist)'
7870
7871 Alist functions provide utilities for treating a list of key-value
7872 pairs as an associative database. These functions take an equality
7873 predicate, PRED, as an argument. This predicate should be repeatable,
7874 symmetric, and transitive.
7875
7876 Alist functions can be used with a secondary index method such as hash
7877 tables for improved performance.
7878
7879 - Function: predicate->asso pred
7880 Returns an "association function" (like `assq', `assv', or
7881 `assoc') corresponding to PRED. The returned function returns a
7882 key-value pair whose key is `pred'-equal to its first argument or
7883 `#f' if no key in the alist is PRED-equal to the first argument.
7884
7885 - Function: alist-inquirer pred
7886 Returns a procedure of 2 arguments, ALIST and KEY, which returns
7887 the value associated with KEY in ALIST or `#f' if KEY does not
7888 appear in ALIST.
7889
7890 - Function: alist-associator pred
7891 Returns a procedure of 3 arguments, ALIST, KEY, and VALUE, which
7892 returns an alist with KEY and VALUE associated. Any previous
7893 value associated with KEY will be lost. This returned procedure
7894 may or may not have side effects on its ALIST argument. An
7895 example of correct usage is:
7896 (define put (alist-associator string-ci=?))
7897 (define alist '())
7898 (set! alist (put alist "Foo" 9))
7899
7900 - Function: alist-remover pred
7901 Returns a procedure of 2 arguments, ALIST and KEY, which returns
7902 an alist with an association whose KEY is key removed. This
7903 returned procedure may or may not have side effects on its ALIST
7904 argument. An example of correct usage is:
7905 (define rem (alist-remover string-ci=?))
7906 (set! alist (rem alist "foo"))
7907
7908 - Function: alist-map proc alist
7909 Returns a new association list formed by mapping PROC over the
7910 keys and values of ALIST. PROC must be a function of 2 arguments
7911 which returns the new value part.
7912
7913 - Function: alist-for-each proc alist
7914 Applies PROC to each pair of keys and values of ALIST. PROC must
7915 be a function of 2 arguments. The returned value is unspecified.
7916
7917 \1f
7918 File: slib.info, Node: Byte, Next: Portable Image Files, Prev: Association Lists, Up: Data Structures
7919
7920 Byte
7921 ----
7922
7923 `(require 'byte)'
7924
7925 Some algorithms are expressed in terms of arrays of small integers.
7926 Using Scheme strings to implement these arrays is not portable vis-a-vis
7927 the correspondence between integers and characters and non-ascii
7928 character sets. These functions abstract the notion of a "byte".
7929
7930 - Function: byte-ref bytes k
7931 K must be a valid index of BYTES. `byte-ref' returns byte K of
7932 BYTES using zero-origin indexing.
7933
7934 - Procedure: byte-set! bytes k byte
7935 K must be a valid index of BYTES%, and BYTE must be a small
7936 integer. `Byte-set!' stores BYTE in element K of BYTES and
7937 returns an unspecified value.
7938
7939 - Function: make-bytes k
7940 - Function: make-bytes k byte
7941 `Make-bytes' returns a newly allocated byte-array of length K. If
7942 BYTE is given, then all elements of the byte-array are initialized
7943 to BYTE, otherwise the contents of the byte-array are unspecified.
7944
7945
7946 - Function: bytes-length bytes
7947 `bytes-length' returns length of byte-array BYTES.
7948
7949
7950 - Function: write-byte byte
7951 - Function: write-byte byte port
7952 Writes the byte BYTE (not an external representation of the byte)
7953 to the given PORT and returns an unspecified value. The PORT
7954 argument may be omitted, in which case it defaults to the value
7955 returned by `current-output-port'.
7956
7957
7958 - Function: read-byte
7959 - Function: read-byte port
7960 Returns the next byte available from the input PORT, updating the
7961 PORT to point to the following byte. If no more bytes are
7962 available, an end of file object is returned. PORT may be
7963 omitted, in which case it defaults to the value returned by
7964 `current-input-port'.
7965
7966
7967 - Function: bytes byte ...
7968 Returns a newly allocated byte-array composed of the arguments.
7969
7970
7971 - Function: bytes->list bytes
7972 - Function: list->bytes bytes
7973 `Bytes->list' returns a newly allocated list of the bytes that
7974 make up the given byte-array. `List->bytes' returns a newly
7975 allocated byte-array formed from the small integers in the list
7976 BYTES. `Bytes->list' and `list->bytes' are inverses so far as
7977 `equal?' is concerned.
7978
7979
7980 \1f
7981 File: slib.info, Node: Portable Image Files, Next: Collections, Prev: Byte, Up: Data Structures
7982
7983 Portable Image Files
7984 --------------------
7985
7986 `(require 'pnm)'
7987
7988 - Function: pnm:type-dimensions path
7989 The string PATH must name a "portable bitmap graphics" file.
7990 `pnm:type-dimensions' returns a list of 4 items:
7991 1. A symbol describing the type of the file named by PATH.
7992
7993 2. The image width in pixels.
7994
7995 3. The image height in pixels.
7996
7997 4. The maximum value of pixels assume in the file.
7998
7999 The current set of file-type symbols is:
8000 pbm
8001 pbm-raw
8002 Black-and-White image; pixel values are 0 or 1.
8003
8004 pgm
8005 pgm-raw
8006 Gray (monochrome) image; pixel values are from 0 to MAXVAL
8007 specified in file header.
8008
8009 ppm
8010 ppm-raw
8011 RGB (full color) image; red, green, and blue interleaved
8012 pixel values are from 0 to MAXVAL
8013
8014
8015 - Function: pnm:image-file->array path array
8016 Reads the "portable bitmap graphics" file named by PATH into
8017 ARRAY. ARRAY must be the correct size and type for PATH. ARRAY
8018 is returned.
8019
8020 - Function: pnm:image-file->array path
8021 `pnm:image-file->array' creates and returns an array with the
8022 "portable bitmap graphics" file named by PATH read into it.
8023
8024
8025 - Procedure: pnm:array-write type array maxval path
8026 Writes the contents of ARRAY to a TYPE image file named PATH. The
8027 file will have pixel values between 0 and MAXVAL, which must be
8028 compatible with TYPE. For `pbm' files, MAXVAL must be `1'.
8029
8030
8031 \1f
8032 File: slib.info, Node: Collections, Next: Dynamic Data Type, Prev: Portable Image Files, Up: Data Structures
8033
8034 Collections
8035 -----------
8036
8037 `(require 'collect)'
8038
8039 Routines for managing collections. Collections are aggregate data
8040 structures supporting iteration over their elements, similar to the
8041 Dylan(TM) language, but with a different interface. They have
8042 "elements" indexed by corresponding "keys", although the keys may be
8043 implicit (as with lists).
8044
8045 New types of collections may be defined as YASOS objects (*note
8046 Yasos::). They must support the following operations:
8047 * `(collection? SELF)' (always returns `#t');
8048
8049 * `(size SELF)' returns the number of elements in the collection;
8050
8051 * `(print SELF PORT)' is a specialized print operation for the
8052 collection which prints a suitable representation on the given
8053 PORT or returns it as a string if PORT is `#t';
8054
8055 * `(gen-elts SELF)' returns a thunk which on successive invocations
8056 yields elements of SELF in order or gives an error if it is
8057 invoked more than `(size SELF)' times;
8058
8059 * `(gen-keys SELF)' is like `gen-elts', but yields the collection's
8060 keys in order.
8061
8062 They might support specialized `for-each-key' and `for-each-elt'
8063 operations.
8064
8065 - Function: collection? obj
8066 A predicate, true initially of lists, vectors and strings. New
8067 sorts of collections must answer `#t' to `collection?'.
8068
8069 - Procedure: map-elts proc . collections
8070 - Procedure: do-elts proc . collections
8071 PROC is a procedure taking as many arguments as there are
8072 COLLECTIONS (at least one). The COLLECTIONS are iterated over in
8073 their natural order and PROC is applied to the elements yielded by
8074 each iteration in turn. The order in which the arguments are
8075 supplied corresponds to te order in which the COLLECTIONS appear.
8076 `do-elts' is used when only side-effects of PROC are of interest
8077 and its return value is unspecified. `map-elts' returns a
8078 collection (actually a vector) of the results of the applications
8079 of PROC.
8080
8081 Example:
8082 (map-elts + (list 1 2 3) (vector 1 2 3))
8083 => #(2 4 6)
8084
8085 - Procedure: map-keys proc . collections
8086 - Procedure: do-keys proc . collections
8087 These are analogous to `map-elts' and `do-elts', but each
8088 iteration is over the COLLECTIONS' _keys_ rather than their
8089 elements.
8090
8091 Example:
8092 (map-keys + (list 1 2 3) (vector 1 2 3))
8093 => #(0 2 4)
8094
8095 - Procedure: for-each-key collection proc
8096 - Procedure: for-each-elt collection proc
8097 These are like `do-keys' and `do-elts' but only for a single
8098 collection; they are potentially more efficient.
8099
8100 - Function: reduce proc seed . collections
8101 A generalization of the list-based `comlist:reduce-init' (*note
8102 Lists as sequences::) to collections which will shadow the
8103 list-based version if `(require 'collect)' follows `(require
8104 'common-list-functions)' (*note Common List Functions::).
8105
8106 Examples:
8107 (reduce + 0 (vector 1 2 3))
8108 => 6
8109 (reduce union '() '((a b c) (b c d) (d a)))
8110 => (c b d a).
8111
8112 - Function: any? pred . collections
8113 A generalization of the list-based `some' (*note Lists as
8114 sequences::) to collections.
8115
8116 Example:
8117 (any? odd? (list 2 3 4 5))
8118 => #t
8119
8120 - Function: every? pred . collections
8121 A generalization of the list-based `every' (*note Lists as
8122 sequences::) to collections.
8123
8124 Example:
8125 (every? collection? '((1 2) #(1 2)))
8126 => #t
8127
8128 - Function: empty? collection
8129 Returns `#t' iff there are no elements in COLLECTION.
8130
8131 `(empty? COLLECTION) == (zero? (size COLLECTION))'
8132
8133 - Function: size collection
8134 Returns the number of elements in COLLECTION.
8135
8136 - Function: Setter list-ref
8137 See *Note Setters:: for a definition of "setter". N.B. `(setter
8138 list-ref)' doesn't work properly for element 0 of a list.
8139
8140 Here is a sample collection: `simple-table' which is also a `table'.
8141 (define-predicate TABLE?)
8142 (define-operation (LOOKUP table key failure-object))
8143 (define-operation (ASSOCIATE! table key value)) ;; returns key
8144 (define-operation (REMOVE! table key)) ;; returns value
8145
8146 (define (MAKE-SIMPLE-TABLE)
8147 (let ( (table (list)) )
8148 (object
8149 ;; table behaviors
8150 ((TABLE? self) #t)
8151 ((SIZE self) (size table))
8152 ((PRINT self port) (format port "#<SIMPLE-TABLE>"))
8153 ((LOOKUP self key failure-object)
8154 (cond
8155 ((assq key table) => cdr)
8156 (else failure-object)
8157 ))
8158 ((ASSOCIATE! self key value)
8159 (cond
8160 ((assq key table)
8161 => (lambda (bucket) (set-cdr! bucket value) key))
8162 (else
8163 (set! table (cons (cons key value) table))
8164 key)
8165 ))
8166 ((REMOVE! self key);; returns old value
8167 (cond
8168 ((null? table) (slib:error "TABLE:REMOVE! Key not found: " key))
8169 ((eq? key (caar table))
8170 (let ( (value (cdar table)) )
8171 (set! table (cdr table))
8172 value)
8173 )
8174 (else
8175 (let loop ( (last table) (this (cdr table)) )
8176 (cond
8177 ((null? this)
8178 (slib:error "TABLE:REMOVE! Key not found: " key))
8179 ((eq? key (caar this))
8180 (let ( (value (cdar this)) )
8181 (set-cdr! last (cdr this))
8182 value)
8183 )
8184 (else
8185 (loop (cdr last) (cdr this)))
8186 ) ) )
8187 ))
8188 ;; collection behaviors
8189 ((COLLECTION? self) #t)
8190 ((GEN-KEYS self) (collect:list-gen-elts (map car table)))
8191 ((GEN-ELTS self) (collect:list-gen-elts (map cdr table)))
8192 ((FOR-EACH-KEY self proc)
8193 (for-each (lambda (bucket) (proc (car bucket))) table)
8194 )
8195 ((FOR-EACH-ELT self proc)
8196 (for-each (lambda (bucket) (proc (cdr bucket))) table)
8197 )
8198 ) ) )
8199
8200 \1f
8201 File: slib.info, Node: Dynamic Data Type, Next: Hash Tables, Prev: Collections, Up: Data Structures
8202
8203 Dynamic Data Type
8204 -----------------
8205
8206 `(require 'dynamic)'
8207
8208 - Function: make-dynamic obj
8209 Create and returns a new "dynamic" whose global value is OBJ.
8210
8211 - Function: dynamic? obj
8212 Returns true if and only if OBJ is a dynamic. No object
8213 satisfying `dynamic?' satisfies any of the other standard type
8214 predicates.
8215
8216 - Function: dynamic-ref dyn
8217 Return the value of the given dynamic in the current dynamic
8218 environment.
8219
8220 - Procedure: dynamic-set! dyn obj
8221 Change the value of the given dynamic to OBJ in the current
8222 dynamic environment. The returned value is unspecified.
8223
8224 - Function: call-with-dynamic-binding dyn obj thunk
8225 Invoke and return the value of the given thunk in a new, nested
8226 dynamic environment in which the given dynamic has been bound to a
8227 new location whose initial contents are the value OBJ. This
8228 dynamic environment has precisely the same extent as the
8229 invocation of the thunk and is thus captured by continuations
8230 created within that invocation and re-established by those
8231 continuations when they are invoked.
8232
8233 The `dynamic-bind' macro is not implemented.
8234
8235 \1f
8236 File: slib.info, Node: Hash Tables, Next: Hashing, Prev: Dynamic Data Type, Up: Data Structures
8237
8238 Hash Tables
8239 -----------
8240
8241 `(require 'hash-table)'
8242
8243 - Function: predicate->hash pred
8244 Returns a hash function (like `hashq', `hashv', or `hash')
8245 corresponding to the equality predicate PRED. PRED should be
8246 `eq?', `eqv?', `equal?', `=', `char=?', `char-ci=?', `string=?', or
8247 `string-ci=?'.
8248
8249 A hash table is a vector of association lists.
8250
8251 - Function: make-hash-table k
8252 Returns a vector of K empty (association) lists.
8253
8254 Hash table functions provide utilities for an associative database.
8255 These functions take an equality predicate, PRED, as an argument. PRED
8256 should be `eq?', `eqv?', `equal?', `=', `char=?', `char-ci=?',
8257 `string=?', or `string-ci=?'.
8258
8259 - Function: predicate->hash-asso pred
8260 Returns a hash association function of 2 arguments, KEY and
8261 HASHTAB, corresponding to PRED. The returned function returns a
8262 key-value pair whose key is PRED-equal to its first argument or
8263 `#f' if no key in HASHTAB is PRED-equal to the first argument.
8264
8265 - Function: hash-inquirer pred
8266 Returns a procedure of 3 arguments, `hashtab' and `key', which
8267 returns the value associated with `key' in `hashtab' or `#f' if
8268 key does not appear in `hashtab'.
8269
8270 - Function: hash-associator pred
8271 Returns a procedure of 3 arguments, HASHTAB, KEY, and VALUE, which
8272 modifies HASHTAB so that KEY and VALUE associated. Any previous
8273 value associated with KEY will be lost.
8274
8275 - Function: hash-remover pred
8276 Returns a procedure of 2 arguments, HASHTAB and KEY, which
8277 modifies HASHTAB so that the association whose key is KEY is
8278 removed.
8279
8280 - Function: hash-map proc hash-table
8281 Returns a new hash table formed by mapping PROC over the keys and
8282 values of HASH-TABLE. PROC must be a function of 2 arguments
8283 which returns the new value part.
8284
8285 - Function: hash-for-each proc hash-table
8286 Applies PROC to each pair of keys and values of HASH-TABLE. PROC
8287 must be a function of 2 arguments. The returned value is
8288 unspecified.
8289
8290 \1f
8291 File: slib.info, Node: Hashing, Next: Object, Prev: Hash Tables, Up: Data Structures
8292
8293 Hashing
8294 -------
8295
8296 `(require 'hash)'
8297
8298 These hashing functions are for use in quickly classifying objects.
8299 Hash tables use these functions.
8300
8301 - Function: hashq obj k
8302 - Function: hashv obj k
8303 - Function: hash obj k
8304 Returns an exact non-negative integer less than K. For each
8305 non-negative integer less than K there are arguments OBJ for which
8306 the hashing functions applied to OBJ and K returns that integer.
8307
8308 For `hashq', `(eq? obj1 obj2)' implies `(= (hashq obj1 k) (hashq
8309 obj2))'.
8310
8311 For `hashv', `(eqv? obj1 obj2)' implies `(= (hashv obj1 k) (hashv
8312 obj2))'.
8313
8314 For `hash', `(equal? obj1 obj2)' implies `(= (hash obj1 k) (hash
8315 obj2))'.
8316
8317 `hash', `hashv', and `hashq' return in time bounded by a constant.
8318 Notice that items having the same `hash' implies the items have
8319 the same `hashv' implies the items have the same `hashq'.
8320
8321 `(require 'sierpinski)'
8322
8323 - Function: make-sierpinski-indexer max-coordinate
8324 Returns a procedure (eg hash-function) of 2 numeric arguments which
8325 preserves _nearness_ in its mapping from NxN to N.
8326
8327 MAX-COORDINATE is the maximum coordinate (a positive integer) of a
8328 population of points. The returned procedures is a function that
8329 takes the x and y coordinates of a point, (non-negative integers)
8330 and returns an integer corresponding to the relative position of
8331 that point along a Sierpinski curve. (You can think of this as
8332 computing a (pseudo-) inverse of the Sierpinski spacefilling
8333 curve.)
8334
8335 Example use: Make an indexer (hash-function) for integer points
8336 lying in square of integer grid points [0,99]x[0,99]:
8337 (define space-key (make-sierpinski-indexer 100))
8338 Now let's compute the index of some points:
8339 (space-key 24 78) => 9206
8340 (space-key 23 80) => 9172
8341
8342 Note that locations (24, 78) and (23, 80) are near in index and
8343 therefore, because the Sierpinski spacefilling curve is
8344 continuous, we know they must also be near in the plane. Nearness
8345 in the plane does not, however, necessarily correspond to nearness
8346 in index, although it _tends_ to be so.
8347
8348 Example applications:
8349 * Sort points by Sierpinski index to get heuristic solution to
8350 _travelling salesman problem_. For details of performance,
8351 see L. Platzman and J. Bartholdi, "Spacefilling curves and the
8352 Euclidean travelling salesman problem", JACM 36(4):719-737
8353 (October 1989) and references therein.
8354
8355 * Use Sierpinski index as key by which to store 2-dimensional
8356 data in a 1-dimensional data structure (such as a table).
8357 Then locations that are near each other in 2-d space will
8358 tend to be near each other in 1-d data structure; and
8359 locations that are near in 1-d data structure will be near in
8360 2-d space. This can significantly speed retrieval from
8361 secondary storage because contiguous regions in the plane
8362 will tend to correspond to contiguous regions in secondary
8363 storage. (This is a standard technique for managing CAD/CAM
8364 or geographic data.)
8365
8366
8367 `(require 'soundex)'
8368
8369 - Function: soundex name
8370 Computes the _soundex_ hash of NAME. Returns a string of an
8371 initial letter and up to three digits between 0 and 6. Soundex
8372 supposedly has the property that names that sound similar in normal
8373 English pronunciation tend to map to the same key.
8374
8375 Soundex was a classic algorithm used for manual filing of personal
8376 records before the advent of computers. It performs adequately for
8377 English names but has trouble with other languages. |
8378
8379 See Knuth, Vol. 3 `Sorting and searching', pp 391-2
8380
8381 To manage unusual inputs, `soundex' omits all non-alphabetic
8382 characters. Consequently, in this implementation:
8383
8384 (soundex <string of blanks>) => ""
8385 (soundex "") => ""
8386
8387 Examples from Knuth:
8388
8389 (map soundex '("Euler" "Gauss" "Hilbert" "Knuth"
8390 "Lloyd" "Lukasiewicz"))
8391 => ("E460" "G200" "H416" "K530" "L300" "L222")
8392
8393 (map soundex '("Ellery" "Ghosh" "Heilbronn" "Kant"
8394 "Ladd" "Lissajous"))
8395 => ("E460" "G200" "H416" "K530" "L300" "L222")
8396
8397 Some cases in which the algorithm fails (Knuth):
8398
8399 (map soundex '("Rogers" "Rodgers")) => ("R262" "R326")
8400
8401 (map soundex '("Sinclair" "St. Clair")) => ("S524" "S324")
8402
8403 (map soundex '("Tchebysheff" "Chebyshev")) => ("T212" "C121")
8404
8405 \1f
8406 File: slib.info, Node: Object, Next: Priority Queues, Prev: Hashing, Up: Data Structures
8407
8408 Macroless Object System
8409 -----------------------
8410
8411 `(require 'object)'
8412
8413 This is the Macroless Object System written by Wade Humeniuk
8414 (whumeniu@datap.ca). Conceptual Tributes: *Note Yasos::, MacScheme's
8415 %object, CLOS, Lack of R4RS macros.
8416
8417 Concepts
8418 --------
8419
8420 OBJECT
8421 An object is an ordered association-list (by `eq?') of methods
8422 (procedures). Methods can be added (`make-method!'), deleted
8423 (`unmake-method!') and retrieved (`get-method'). Objects may
8424 inherit methods from other objects. The object binds to the
8425 environment it was created in, allowing closures to be used to
8426 hide private procedures and data.
8427
8428 GENERIC-METHOD
8429 A generic-method associates (in terms of `eq?') object's method.
8430 This allows scheme function style to be used for objects. The
8431 calling scheme for using a generic method is `(generic-method
8432 object param1 param2 ...)'.
8433
8434 METHOD
8435 A method is a procedure that exists in the object. To use a method
8436 get-method must be called to look-up the method. Generic methods
8437 implement the get-method functionality. Methods may be added to an
8438 object associated with any scheme obj in terms of eq?
8439
8440 GENERIC-PREDICATE
8441 A generic method that returns a boolean value for any scheme obj.
8442
8443 PREDICATE
8444 A object's method asscociated with a generic-predicate. Returns
8445 `#t'.
8446
8447 Procedures
8448 ----------
8449
8450 - Function: make-object ancestor ...
8451 Returns an object. Current object implementation is a tagged
8452 vector. ANCESTORs are optional and must be objects in terms of
8453 object?. ANCESTORs methods are included in the object. Multiple
8454 ANCESTORs might associate the same generic-method with a method.
8455 In this case the method of the ANCESTOR first appearing in the
8456 list is the one returned by `get-method'.
8457
8458 - Function: object? obj
8459 Returns boolean value whether OBJ was created by make-object.
8460
8461 - Function: make-generic-method exception-procedure
8462 Returns a procedure which be associated with an object's methods.
8463 If EXCEPTION-PROCEDURE is specified then it is used to process
8464 non-objects.
8465
8466 - Function: make-generic-predicate
8467 Returns a boolean procedure for any scheme object.
8468
8469 - Function: make-method! object generic-method method
8470 Associates METHOD to the GENERIC-METHOD in the object. The METHOD
8471 overrides any previous association with the GENERIC-METHOD within
8472 the object. Using `unmake-method!' will restore the object's
8473 previous association with the GENERIC-METHOD. METHOD must be a
8474 procedure.
8475
8476 - Function: make-predicate! object generic-preciate
8477 Makes a predicate method associated with the GENERIC-PREDICATE.
8478
8479 - Function: unmake-method! object generic-method
8480 Removes an object's association with a GENERIC-METHOD .
8481
8482 - Function: get-method object generic-method
8483 Returns the object's method associated (if any) with the
8484 GENERIC-METHOD. If no associated method exists an error is
8485 flagged.
8486
8487 Examples
8488 --------
8489
8490 (require 'object)
8491
8492 (define instantiate (make-generic-method))
8493
8494 (define (make-instance-object . ancestors)
8495 (define self (apply make-object
8496 (map (lambda (obj) (instantiate obj)) ancestors)))
8497 (make-method! self instantiate (lambda (self) self))
8498 self)
8499
8500 (define who (make-generic-method))
8501 (define imigrate! (make-generic-method))
8502 (define emigrate! (make-generic-method))
8503 (define describe (make-generic-method))
8504 (define name (make-generic-method))
8505 (define address (make-generic-method))
8506 (define members (make-generic-method))
8507
8508 (define society
8509 (let ()
8510 (define self (make-instance-object))
8511 (define population '())
8512 (make-method! self imigrate!
8513 (lambda (new-person)
8514 (if (not (eq? new-person self))
8515 (set! population (cons new-person population)))))
8516 (make-method! self emigrate!
8517 (lambda (person)
8518 (if (not (eq? person self))
8519 (set! population
8520 (comlist:remove-if (lambda (member)
8521 (eq? member person))
8522 population)))))
8523 (make-method! self describe
8524 (lambda (self)
8525 (map (lambda (person) (describe person)) population)))
8526 (make-method! self who
8527 (lambda (self) (map (lambda (person) (name person))
8528 population)))
8529 (make-method! self members (lambda (self) population))
8530 self))
8531
8532 (define (make-person %name %address)
8533 (define self (make-instance-object society))
8534 (make-method! self name (lambda (self) %name))
8535 (make-method! self address (lambda (self) %address))
8536 (make-method! self who (lambda (self) (name self)))
8537 (make-method! self instantiate
8538 (lambda (self)
8539 (make-person (string-append (name self) "-son-of")
8540 %address)))
8541 (make-method! self describe
8542 (lambda (self) (list (name self) (address self))))
8543 (imigrate! self)
8544 self)
8545
8546 Inverter Documentation
8547 ......................
8548
8549 Inheritance:
8550 <inverter>::(<number> <description>)
8551 Generic-methods
8552 <inverter>::value => <number>::value
8553 <inverter>::set-value! => <number>::set-value!
8554 <inverter>::describe => <description>::describe
8555 <inverter>::help
8556 <inverter>::invert
8557 <inverter>::inverter?
8558
8559 Number Documention
8560 ..................
8561
8562 Inheritance
8563 <number>::()
8564 Slots
8565 <number>::<x>
8566 Generic Methods
8567 <number>::value
8568 <number>::set-value!
8569
8570 Inverter code
8571 .............
8572
8573 (require 'object)
8574
8575 (define value (make-generic-method (lambda (val) val)))
8576 (define set-value! (make-generic-method))
8577 (define invert (make-generic-method
8578 (lambda (val)
8579 (if (number? val)
8580 (/ 1 val)
8581 (error "Method not supported:" val)))))
8582 (define noop (make-generic-method))
8583 (define inverter? (make-generic-predicate))
8584 (define describe (make-generic-method))
8585 (define help (make-generic-method))
8586
8587 (define (make-number x)
8588 (define self (make-object))
8589 (make-method! self value (lambda (this) x))
8590 (make-method! self set-value!
8591 (lambda (this new-value) (set! x new-value)))
8592 self)
8593
8594 (define (make-description str)
8595 (define self (make-object))
8596 (make-method! self describe (lambda (this) str))
8597 (make-method! self help (lambda (this) "Help not available"))
8598 self)
8599
8600 (define (make-inverter)
8601 (let* ((self (make-object
8602 (make-number 1)
8603 (make-description "A number which can be inverted")))
8604 (<value> (get-method self value)))
8605 (make-method! self invert (lambda (self) (/ 1 (<value> self))))
8606 (make-predicate! self inverter?)
8607 (unmake-method! self help)
8608 (make-method! self help
8609 (lambda (self)
8610 (display "Inverter Methods:") (newline)
8611 (display " (value inverter) ==> n") (newline)))
8612 self))
8613
8614 ;;;; Try it out
8615
8616 (define invert! (make-generic-method))
8617
8618 (define x (make-inverter))
8619
8620 (make-method! x invert! (lambda (x) (set-value! x (/ 1 (value x)))))
8621
8622 (value x) => 1
8623 (set-value! x 33) => undefined
8624 (invert! x) => undefined
8625 (value x) => 1/33
8626
8627 (unmake-method! x invert!) => undefined
8628
8629 (invert! x) error--> ERROR: Method not supported: x
8630
8631 \1f
8632 File: slib.info, Node: Priority Queues, Next: Queues, Prev: Object, Up: Data Structures
8633
8634 Priority Queues
8635 ---------------
8636
8637 `(require 'priority-queue)'
8638
8639 - Function: make-heap pred<?
8640 Returns a binary heap suitable which can be used for priority queue
8641 operations.
8642
8643 - Function: heap-length heap
8644 Returns the number of elements in HEAP.
8645
8646 - Procedure: heap-insert! heap item
8647 Inserts ITEM into HEAP. ITEM can be inserted multiple times. The
8648 value returned is unspecified.
8649
8650 - Function: heap-extract-max! heap
8651 Returns the item which is larger than all others according to the
8652 PRED<? argument to `make-heap'. If there are no items in HEAP, an
8653 error is signaled.
8654
8655 The algorithm for priority queues was taken from `Introduction to
8656 Algorithms' by T. Cormen, C. Leiserson, R. Rivest. 1989 MIT Press.
8657
8658 \1f
8659 File: slib.info, Node: Queues, Next: Records, Prev: Priority Queues, Up: Data Structures
8660
8661 Queues
8662 ------
8663
8664 `(require 'queue)'
8665
8666 A "queue" is a list where elements can be added to both the front and
8667 rear, and removed from the front (i.e., they are what are often called
8668 "dequeues"). A queue may also be used like a stack.
8669
8670 - Function: make-queue
8671 Returns a new, empty queue.
8672
8673 - Function: queue? obj
8674 Returns `#t' if OBJ is a queue.
8675
8676 - Function: queue-empty? q
8677 Returns `#t' if the queue Q is empty.
8678
8679 - Procedure: queue-push! q datum
8680 Adds DATUM to the front of queue Q.
8681
8682 - Procedure: enquque! q datum
8683 Adds DATUM to the rear of queue Q.
8684
8685 All of the following functions raise an error if the queue Q is empty.
8686
8687 - Function: queue-front q
8688 Returns the datum at the front of the queue Q.
8689
8690 - Function: queue-rear q
8691 Returns the datum at the rear of the queue Q.
8692
8693 - Prcoedure: queue-pop! q
8694 - Procedure: dequeue! q
8695 Both of these procedures remove and return the datum at the front
8696 of the queue. `queue-pop!' is used to suggest that the queue is
8697 being used like a stack.
8698
8699 \1f
8700 File: slib.info, Node: Records, Next: Structures, Prev: Queues, Up: Data Structures
8701
8702 Records
8703 -------
8704
8705 `(require 'record)'
8706
8707 The Record package provides a facility for user to define their own
8708 record data types.
8709
8710 - Function: make-record-type type-name field-names
8711 Returns a "record-type descriptor", a value representing a new data
8712 type disjoint from all others. The TYPE-NAME argument must be a
8713 string, but is only used for debugging purposes (such as the
8714 printed representation of a record of the new type). The
8715 FIELD-NAMES argument is a list of symbols naming the "fields" of a
8716 record of the new type. It is an error if the list contains any
8717 duplicates. It is unspecified how record-type descriptors are
8718 represented.
8719
8720 - Function: record-constructor rtd [field-names]
8721 Returns a procedure for constructing new members of the type
8722 represented by RTD. The returned procedure accepts exactly as
8723 many arguments as there are symbols in the given list,
8724 FIELD-NAMES; these are used, in order, as the initial values of
8725 those fields in a new record, which is returned by the constructor
8726 procedure. The values of any fields not named in that list are
8727 unspecified. The FIELD-NAMES argument defaults to the list of
8728 field names in the call to `make-record-type' that created the
8729 type represented by RTD; if the FIELD-NAMES argument is provided,
8730 it is an error if it contains any duplicates or any symbols not in
8731 the default list.
8732
8733 - Function: record-predicate rtd
8734 Returns a procedure for testing membership in the type represented
8735 by RTD. The returned procedure accepts exactly one argument and
8736 returns a true value if the argument is a member of the indicated
8737 record type; it returns a false value otherwise.
8738
8739 - Function: record-accessor rtd field-name
8740 Returns a procedure for reading the value of a particular field of
8741 a member of the type represented by RTD. The returned procedure
8742 accepts exactly one argument which must be a record of the
8743 appropriate type; it returns the current value of the field named
8744 by the symbol FIELD-NAME in that record. The symbol FIELD-NAME
8745 must be a member of the list of field-names in the call to
8746 `make-record-type' that created the type represented by RTD.
8747
8748 - Function: record-modifier rtd field-name
8749 Returns a procedure for writing the value of a particular field of
8750 a member of the type represented by RTD. The returned procedure
8751 accepts exactly two arguments: first, a record of the appropriate
8752 type, and second, an arbitrary Scheme value; it modifies the field
8753 named by the symbol FIELD-NAME in that record to contain the given
8754 value. The returned value of the modifier procedure is
8755 unspecified. The symbol FIELD-NAME must be a member of the list
8756 of field-names in the call to `make-record-type' that created the
8757 type represented by RTD.
8758
8759 In May of 1996, as a product of discussion on the `rrrs-authors'
8760 mailing list, I rewrote `record.scm' to portably implement type
8761 disjointness for record data types.
8762
8763 As long as an implementation's procedures are opaque and the `record'
8764 code is loaded before other programs, this will give disjoint record
8765 types which are unforgeable and incorruptible by R4RS procedures.
8766
8767 As a consequence, the procedures `record?', `record-type-descriptor',
8768 `record-type-name'.and `record-type-field-names' are no longer
8769 supported.
8770
8771 \1f
8772 File: slib.info, Node: Structures, Prev: Records, Up: Data Structures
8773
8774 Structures
8775 ----------
8776
8777 `(require 'struct)' (uses defmacros)
8778
8779 `defmacro's which implement "records" from the book `Essentials of
8780 Programming Languages' by Daniel P. Friedman, M. Wand and C.T. Haynes.
8781 Copyright 1992 Jeff Alexander, Shinnder Lee, and Lewis Patterson
8782
8783 Matthew McDonald <mafm@cs.uwa.edu.au> added field setters.
8784
8785 - Macro: define-record tag (var1 var2 ...)
8786 Defines several functions pertaining to record-name TAG:
8787
8788 - Function: make-TAG var1 var2 ...
8789
8790 - Function: TAG? obj
8791
8792 - Function: TAG->var1 obj
8793
8794 - Function: TAG->var2 obj
8795 ...
8796
8797 - Function: set-TAG-var1! obj val
8798
8799 - Function: set-TAG-var2! obj val
8800 ...
8801
8802 Here is an example of its use.
8803
8804 (define-record term (operator left right))
8805 => #<unspecified>
8806 (define foo (make-term 'plus 1 2))
8807 => foo
8808 (term->left foo)
8809 => 1
8810 (set-term-left! foo 2345)
8811 => #<unspecified>
8812 (term->left foo)
8813 => 2345
8814
8815 - Macro: variant-case exp (tag (var1 var2 ...) body) ...
8816 executes the following for the matching clause:
8817
8818 ((lambda (VAR1 VAR ...) BODY)
8819 (TAG->VAR1 EXP)
8820 (TAG->VAR2 EXP) ...)
8821
8822 \1f
8823 File: slib.info, Node: Procedures, Next: Standards Support, Prev: Data Structures, Up: Other Packages
8824
8825 Procedures
8826 ==========
8827
8828 Anything that doesn't fall neatly into any of the other categories
8829 winds up here.
8830
8831 * Menu:
8832
8833 * Common List Functions:: 'common-list-functions
8834 * Tree Operations:: 'tree
8835 * Type Coercion:: 'coerce |
8836 * Chapter Ordering:: 'chapter-order
8837 * Sorting:: 'sort
8838 * Topological Sort:: Keep your socks on.
8839 * String-Case:: 'string-case
8840 * String Ports:: 'string-port
8841 * String Search:: Also Search from a Port.
8842 * Line I/O:: 'line-i/o
8843 * Multi-Processing:: 'process
8844 * Metric Units:: Portable manifest types for numeric values. |
8845
8846 \1f
8847 File: slib.info, Node: Common List Functions, Next: Tree Operations, Prev: Procedures, Up: Procedures
8848
8849 Common List Functions
8850 ---------------------
8851
8852 `(require 'common-list-functions)'
8853
8854 The procedures below follow the Common LISP equivalents apart from
8855 optional arguments in some cases.
8856
8857 * Menu:
8858
8859 * List construction::
8860 * Lists as sets::
8861 * Lists as sequences::
8862 * Destructive list operations::
8863 * Non-List functions::
8864
8865 \1f
8866 File: slib.info, Node: List construction, Next: Lists as sets, Prev: Common List Functions, Up: Common List Functions
8867
8868 List construction
8869 .................
8870
8871 - Function: make-list k . init
8872 `make-list' creates and returns a list of K elements. If INIT is
8873 included, all elements in the list are initialized to INIT.
8874
8875 Example:
8876 (make-list 3)
8877 => (#<unspecified> #<unspecified> #<unspecified>)
8878 (make-list 5 'foo)
8879 => (foo foo foo foo foo)
8880
8881 - Function: list* x . y
8882 Works like `list' except that the cdr of the last pair is the last
8883 argument unless there is only one argument, when the result is
8884 just that argument. Sometimes called `cons*'. E.g.:
8885 (list* 1)
8886 => 1
8887 (list* 1 2 3)
8888 => (1 2 . 3)
8889 (list* 1 2 '(3 4))
8890 => (1 2 3 4)
8891 (list* ARGS '())
8892 == (list ARGS)
8893
8894 - Function: copy-list lst
8895 `copy-list' makes a copy of LST using new pairs and returns it.
8896 Only the top level of the list is copied, i.e., pairs forming
8897 elements of the copied list remain `eq?' to the corresponding
8898 elements of the original; the copy is, however, not `eq?' to the
8899 original, but is `equal?' to it.
8900
8901 Example:
8902 (copy-list '(foo foo foo))
8903 => (foo foo foo)
8904 (define q '(foo bar baz bang))
8905 (define p q)
8906 (eq? p q)
8907 => #t
8908 (define r (copy-list q))
8909 (eq? q r)
8910 => #f
8911 (equal? q r)
8912 => #t
8913 (define bar '(bar))
8914 (eq? bar (car (copy-list (list bar 'foo))))
8915 => #t
8916
8917 \1f
8918 File: slib.info, Node: Lists as sets, Next: Lists as sequences, Prev: List construction, Up: Common List Functions
8919
8920 Lists as sets
8921 .............
8922
8923 `eqv?' is used to test for membership by procedures which treat lists
8924 as sets.
8925
8926 - Function: adjoin e l
8927 `adjoin' returns the adjoint of the element E and the list L.
8928 That is, if E is in L, `adjoin' returns L, otherwise, it returns
8929 `(cons E L)'.
8930
8931 Example:
8932 (adjoin 'baz '(bar baz bang))
8933 => (bar baz bang)
8934 (adjoin 'foo '(bar baz bang))
8935 => (foo bar baz bang)
8936
8937 - Function: union l1 l2
8938 `union' returns the combination of L1 and L2. Duplicates between
8939 L1 and L2 are culled. Duplicates within L1 or within L2 may or
8940 may not be removed.
8941
8942 Example:
8943 (union '(1 2 3 4) '(5 6 7 8))
8944 => (4 3 2 1 5 6 7 8)
8945 (union '(1 2 3 4) '(3 4 5 6))
8946 => (2 1 3 4 5 6)
8947
8948 - Function: intersection l1 l2
8949 `intersection' returns all elements that are in both L1 and L2.
8950
8951 Example:
8952 (intersection '(1 2 3 4) '(3 4 5 6))
8953 => (4 3) |
8954 (intersection '(1 2 3 4) '(5 6 7 8))
8955 => ()
8956
8957 - Function: set-difference l1 l2
8958 `set-difference' returns all elements that are in L1 but not in L2.
8959
8960 Example:
8961 (set-difference '(1 2 3 4) '(3 4 5 6))
8962 => (2 1) |
8963 (set-difference '(1 2 3 4) '(1 2 3 4 5 6))
8964 => ()
8965
8966 - Function: member-if pred lst
8967 `member-if' returns LST if `(PRED ELEMENT)' is `#t' for any
8968 ELEMENT in LST. Returns `#f' if PRED does not apply to any
8969 ELEMENT in LST.
8970
8971 Example:
8972 (member-if vector? '(1 2 3 4))
8973 => #f
8974 (member-if number? '(1 2 3 4))
8975 => (1 2 3 4)
8976
8977 - Function: some pred lst . more-lsts
8978 PRED is a boolean function of as many arguments as there are list
8979 arguments to `some' i.e., LST plus any optional arguments. PRED
8980 is applied to successive elements of the list arguments in order.
8981 `some' returns `#t' as soon as one of these applications returns
8982 `#t', and is `#f' if none returns `#t'. All the lists should have
8983 the same length.
8984
8985 Example:
8986 (some odd? '(1 2 3 4))
8987 => #t
8988
8989 (some odd? '(2 4 6 8))
8990 => #f
8991
8992 (some > '(2 3) '(1 4))
8993 => #f
8994
8995 - Function: every pred lst . more-lsts
8996 `every' is analogous to `some' except it returns `#t' if every
8997 application of PRED is `#t' and `#f' otherwise.
8998
8999 Example:
9000 (every even? '(1 2 3 4))
9001 => #f
9002
9003 (every even? '(2 4 6 8))
9004 => #t
9005
9006 (every > '(2 3) '(1 4))
9007 => #f
9008
9009 - Function: notany pred . lst
9010 `notany' is analogous to `some' but returns `#t' if no application
9011 of PRED returns `#t' or `#f' as soon as any one does.
9012
9013 - Function: notevery pred . lst
9014 `notevery' is analogous to `some' but returns `#t' as soon as an
9015 application of PRED returns `#f', and `#f' otherwise.
9016
9017 Example:
9018 (notevery even? '(1 2 3 4))
9019 => #t
9020
9021 (notevery even? '(2 4 6 8))
9022 => #f
9023
9024 - Function: list-of?? predicate |
9025 Returns a predicate which returns true if its argument is a list |
9026 every element of which satisfies PREDICATE. |
9027 |
9028 - Function: list-of?? predicate low-bound high-bound |
9029 LOW-BOUND and HIGH-BOUND are non-negative integers. `list-of??' |
9030 returns a predicate which returns true if its argument is a list |
9031 of length between LOW-BOUND and HIGH-BOUND (inclusive); every |
9032 element of which satisfies PREDICATE. |
9033 |
9034 - Function: list-of?? predicate bound |
9035 BOUND is an integer. If BOUND is negative, `list-of??' returns a |
9036 predicate which returns true if its argument is a list of length |
9037 greater than `(- BOUND)'; every element of which satisfies |
9038 PREDICATE. Otherwise, `list-of??' returns a predicate which |
9039 returns true if its argument is a list of length less than or |
9040 equal to BOUND; every element of which satisfies PREDICATE. |
9041 |
9042 - Function: find-if pred lst
9043 `find-if' searches for the first ELEMENT in LST such that `(PRED
9044 ELEMENT)' returns `#t'. If it finds any such ELEMENT in LST,
9045 ELEMENT is returned. Otherwise, `#f' is returned.
9046
9047 Example:
9048 (find-if number? '(foo 1 bar 2))
9049 => 1
9050
9051 (find-if number? '(foo bar baz bang))
9052 => #f
9053
9054 (find-if symbol? '(1 2 foo bar))
9055 => foo
9056
9057 - Function: remove elt lst
9058 `remove' removes all occurrences of ELT from LST using `eqv?' to
9059 test for equality and returns everything that's left. N.B.: other
9060 implementations (Chez, Scheme->C and T, at least) use `equal?' as
9061 the equality test.
9062
9063 Example:
9064 (remove 1 '(1 2 1 3 1 4 1 5))
9065 => (5 4 3 2) |
9066
9067 (remove 'foo '(bar baz bang))
9068 => (bang baz bar) |
9069
9070 - Function: remove-if pred lst
9071 `remove-if' removes all ELEMENTs from LST where `(PRED ELEMENT)'
9072 is `#t' and returns everything that's left.
9073
9074 Example:
9075 (remove-if number? '(1 2 3 4))
9076 => ()
9077
9078 (remove-if even? '(1 2 3 4 5 6 7 8))
9079 => (7 5 3 1) |
9080
9081 - Function: remove-if-not pred lst
9082 `remove-if-not' removes all ELEMENTs from LST for which `(PRED
9083 ELEMENT)' is `#f' and returns everything that's left.
9084
9085 Example:
9086 (remove-if-not number? '(foo bar baz))
9087 => ()
9088 (remove-if-not odd? '(1 2 3 4 5 6 7 8))
9089 => (7 5 3 1) |
9090
9091 - Function: has-duplicates? lst
9092 returns `#t' if 2 members of LST are `equal?', `#f' otherwise.
9093
9094 Example:
9095 (has-duplicates? '(1 2 3 4))
9096 => #f
9097
9098 (has-duplicates? '(2 4 3 4))
9099 => #t
9100
9101 The procedure `remove-duplicates' uses `member' (rather than `memv').
9102
9103 - Function: remove-duplicates lst
9104 returns a copy of LST with its duplicate members removed.
9105 Elements are considered duplicate if they are `equal?'.
9106
9107 Example:
9108 (remove-duplicates '(1 2 3 4))
9109 => (4 3 2 1)
9110
9111 (remove-duplicates '(2 4 3 4))
9112 => (3 4 2)
9113
9114 \1f
9115 File: slib.info, Node: Lists as sequences, Next: Destructive list operations, Prev: Lists as sets, Up: Common List Functions
9116
9117 Lists as sequences
9118 ..................
9119
9120 - Function: position obj lst
9121 `position' returns the 0-based position of OBJ in LST, or `#f' if
9122 OBJ does not occur in LST.
9123
9124 Example:
9125 (position 'foo '(foo bar baz bang))
9126 => 0
9127 (position 'baz '(foo bar baz bang))
9128 => 2
9129 (position 'oops '(foo bar baz bang))
9130 => #f
9131
9132 - Function: reduce p lst
9133 `reduce' combines all the elements of a sequence using a binary
9134 operation (the combination is left-associative). For example,
9135 using `+', one can add up all the elements. `reduce' allows you to
9136 apply a function which accepts only two arguments to more than 2
9137 objects. Functional programmers usually refer to this as "foldl".
9138 `collect:reduce' (*note Collections::) provides a version of
9139 `collect' generalized to collections.
9140
9141 Example:
9142 (reduce + '(1 2 3 4))
9143 => 10
9144 (define (bad-sum . l) (reduce + l))
9145 (bad-sum 1 2 3 4)
9146 == (reduce + (1 2 3 4))
9147 == (+ (+ (+ 1 2) 3) 4)
9148 => 10
9149 (bad-sum)
9150 == (reduce + ())
9151 => ()
9152 (reduce string-append '("hello" "cruel" "world"))
9153 == (string-append (string-append "hello" "cruel") "world")
9154 => "hellocruelworld"
9155 (reduce anything '())
9156 => ()
9157 (reduce anything '(x))
9158 => x
9159
9160 What follows is a rather non-standard implementation of `reverse'
9161 in terms of `reduce' and a combinator elsewhere called "C".
9162
9163 ;;; Contributed by Jussi Piitulainen (jpiitula@ling.helsinki.fi)
9164
9165 (define commute
9166 (lambda (f)
9167 (lambda (x y)
9168 (f y x))))
9169
9170 (define reverse
9171 (lambda (args)
9172 (reduce-init (commute cons) '() args)))
9173
9174 - Function: reduce-init p init lst
9175 `reduce-init' is the same as reduce, except that it implicitly
9176 inserts INIT at the start of the list. `reduce-init' is preferred
9177 if you want to handle the null list, the one-element, and lists
9178 with two or more elements consistently. It is common to use the
9179 operator's idempotent as the initializer. Functional programmers
9180 usually call this "foldl".
9181
9182 Example:
9183 (define (sum . l) (reduce-init + 0 l))
9184 (sum 1 2 3 4)
9185 == (reduce-init + 0 (1 2 3 4))
9186 == (+ (+ (+ (+ 0 1) 2) 3) 4)
9187 => 10
9188 (sum)
9189 == (reduce-init + 0 '())
9190 => 0
9191
9192 (reduce-init string-append "@" '("hello" "cruel" "world"))
9193 ==
9194 (string-append (string-append (string-append "@" "hello")
9195 "cruel")
9196 "world")
9197 => "@hellocruelworld"
9198
9199 Given a differentiation of 2 arguments, `diff', the following will
9200 differentiate by any number of variables.
9201 (define (diff* exp . vars)
9202 (reduce-init diff exp vars))
9203
9204 Example:
9205 ;;; Real-world example: Insertion sort using reduce-init.
9206
9207 (define (insert l item)
9208 (if (null? l)
9209 (list item)
9210 (if (< (car l) item)
9211 (cons (car l) (insert (cdr l) item))
9212 (cons item l))))
9213 (define (insertion-sort l) (reduce-init insert '() l))
9214
9215 (insertion-sort '(3 1 4 1 5)
9216 == (reduce-init insert () (3 1 4 1 5))
9217 == (insert (insert (insert (insert (insert () 3) 1) 4) 1) 5)
9218 == (insert (insert (insert (insert (3)) 1) 4) 1) 5)
9219 == (insert (insert (insert (1 3) 4) 1) 5)
9220 == (insert (insert (1 3 4) 1) 5)
9221 == (insert (1 1 3 4) 5)
9222 => (1 1 3 4 5)
9223
9224 - Function: last lst n
9225 `last' returns the last N elements of LST. N must be a
9226 non-negative integer.
9227
9228 Example:
9229 (last '(foo bar baz bang) 2)
9230 => (baz bang)
9231 (last '(1 2 3) 0)
9232 => 0
9233
9234 - Function: butlast lst n
9235 `butlast' returns all but the last N elements of LST.
9236
9237 Example:
9238 (butlast '(a b c d) 3)
9239 => (a)
9240 (butlast '(a b c d) 4)
9241 => ()
9242
9243 `last' and `butlast' split a list into two parts when given identical
9244 arugments.
9245 (last '(a b c d e) 2)
9246 => (d e)
9247 (butlast '(a b c d e) 2)
9248 => (a b c)
9249
9250 - Function: nthcdr n lst
9251 `nthcdr' takes N `cdr's of LST and returns the result. Thus
9252 `(nthcdr 3 LST)' == `(cdddr LST)'
9253
9254 Example:
9255 (nthcdr 2 '(a b c d))
9256 => (c d)
9257 (nthcdr 0 '(a b c d))
9258 => (a b c d)
9259
9260 - Function: butnthcdr n lst
9261 `butnthcdr' returns all but the nthcdr N elements of LST.
9262
9263 Example:
9264 (butnthcdr 3 '(a b c d))
9265 => (a b c)
9266 (butnthcdr 4 '(a b c d))
9267 => (a b c d) |
9268
9269 `nthcdr' and `butnthcdr' split a list into two parts when given
9270 identical arugments.
9271 (nthcdr 2 '(a b c d e))
9272 => (c d e)
9273 (butnthcdr 2 '(a b c d e))
9274 => (a b)
9275
9276 \1f
9277 File: slib.info, Node: Destructive list operations, Next: Non-List functions, Prev: Lists as sequences, Up: Common List Functions
9278
9279 Destructive list operations
9280 ...........................
9281
9282 These procedures may mutate the list they operate on, but any such
9283 mutation is undefined.
9284
9285 - Procedure: nconc args
9286 `nconc' destructively concatenates its arguments. (Compare this
9287 with `append', which copies arguments rather than destroying them.)
9288 Sometimes called `append!' (*note Rev2 Procedures::).
9289
9290 Example: You want to find the subsets of a set. Here's the
9291 obvious way:
9292
9293 (define (subsets set)
9294 (if (null? set)
9295 '(())
9296 (append (mapcar (lambda (sub) (cons (car set) sub))
9297 (subsets (cdr set)))
9298 (subsets (cdr set)))))
9299 But that does way more consing than you need. Instead, you could
9300 replace the `append' with `nconc', since you don't have any need
9301 for all the intermediate results.
9302
9303 Example:
9304 (define x '(a b c))
9305 (define y '(d e f))
9306 (nconc x y)
9307 => (a b c d e f)
9308 x
9309 => (a b c d e f)
9310
9311 `nconc' is the same as `append!' in `sc2.scm'.
9312
9313 - Procedure: nreverse lst
9314 `nreverse' reverses the order of elements in LST by mutating
9315 `cdr's of the list. Sometimes called `reverse!'.
9316
9317 Example:
9318 (define foo '(a b c))
9319 (nreverse foo)
9320 => (c b a)
9321 foo
9322 => (a)
9323
9324 Some people have been confused about how to use `nreverse',
9325 thinking that it doesn't return a value. It needs to be pointed
9326 out that
9327 (set! lst (nreverse lst))
9328
9329 is the proper usage, not
9330 (nreverse lst)
9331 The example should suffice to show why this is the case.
9332
9333 - Procedure: delete elt lst
9334 - Procedure: delete-if pred lst
9335 - Procedure: delete-if-not pred lst
9336 Destructive versions of `remove' `remove-if', and `remove-if-not'.
9337
9338 Example:
9339 (define lst '(foo bar baz bang))
9340 (delete 'foo lst)
9341 => (bar baz bang)
9342 lst
9343 => (foo bar baz bang)
9344
9345 (define lst '(1 2 3 4 5 6 7 8 9))
9346 (delete-if odd? lst)
9347 => (2 4 6 8)
9348 lst
9349 => (1 2 4 6 8)
9350
9351 Some people have been confused about how to use `delete',
9352 `delete-if', and `delete-if', thinking that they dont' return a
9353 value. It needs to be pointed out that
9354 (set! lst (delete el lst))
9355
9356 is the proper usage, not
9357 (delete el lst)
9358 The examples should suffice to show why this is the case.
9359
9360 \1f
9361 File: slib.info, Node: Non-List functions, Prev: Destructive list operations, Up: Common List Functions
9362
9363 Non-List functions
9364 ..................
9365
9366 - Function: and? . args
9367 `and?' checks to see if all its arguments are true. If they are,
9368 `and?' returns `#t', otherwise, `#f'. (In contrast to `and', this
9369 is a function, so all arguments are always evaluated and in an
9370 unspecified order.)
9371
9372 Example:
9373 (and? 1 2 3)
9374 => #t
9375 (and #f 1 2)
9376 => #f
9377
9378 - Function: or? . args
9379 `or?' checks to see if any of its arguments are true. If any is
9380 true, `or?' returns `#t', and `#f' otherwise. (To `or' as `and?'
9381 is to `and'.)
9382
9383 Example:
9384 (or? 1 2 #f)
9385 => #t
9386 (or? #f #f #f)
9387 => #f
9388
9389 - Function: atom? object
9390 Returns `#t' if OBJECT is not a pair and `#f' if it is pair.
9391 (Called `atom' in Common LISP.)
9392 (atom? 1)
9393 => #t
9394 (atom? '(1 2))
9395 => #f
9396 (atom? #(1 2)) ; dubious!
9397 => #t
9398 |
9399 \1f
9400 File: slib.info, Node: Tree Operations, Next: Type Coercion, Prev: Common List Functions, Up: Procedures
9401 |
9402 Tree operations
9403 ---------------
9404
9405 `(require 'tree)'
9406
9407 These are operations that treat lists a representations of trees.
9408
9409 - Function: subst new old tree
9410 - Function: substq new old tree
9411 - Function: substv new old tree
9412 `subst' makes a copy of TREE, substituting NEW for every subtree
9413 or leaf of TREE which is `equal?' to OLD and returns a modified
9414 tree. The original TREE is unchanged, but may share parts with
9415 the result.
9416
9417 `substq' and `substv' are similar, but test against OLD using
9418 `eq?' and `eqv?' respectively.
9419
9420 Examples:
9421 (substq 'tempest 'hurricane '(shakespeare wrote (the hurricane)))
9422 => (shakespeare wrote (the tempest))
9423 (substq 'foo '() '(shakespeare wrote (twelfth night)))
9424 => (shakespeare wrote (twelfth night . foo) . foo)
9425 (subst '(a . cons) '(old . pair)
9426 '((old . spice) ((old . shoes) old . pair) (old . pair)))
9427 => ((old . spice) ((old . shoes) a . cons) (a . cons))
9428
9429 - Function: copy-tree tree
9430 Makes a copy of the nested list structure TREE using new pairs and
9431 returns it. All levels are copied, so that none of the pairs in
9432 the tree are `eq?' to the original ones - only the leaves are.
9433
9434 Example:
9435 (define bar '(bar))
9436 (copy-tree (list bar 'foo))
9437 => ((bar) foo)
9438 (eq? bar (car (copy-tree (list bar 'foo))))
9439 => #f
9440
9441 \1f
9442 File: slib.info, Node: Type Coercion, Next: Chapter Ordering, Prev: Tree Operations, Up: Procedures
9443 |
9444 Type Coercion |
9445 ------------- |
9446 |
9447 `(require 'coerce)' |
9448 |
9449 - Function: type-of obj |
9450 Returns a symbol name for the type of OBJ. |
9451 |
9452 - Function: coerce obj result-type |
9453 Converts and returns OBJ of type `char', `number', `string', |
9454 `symbol', `list', or `vector' to RESULT-TYPE (which must be one of |
9455 these symbols). |
9456 |
9457 \1f
9458 File: slib.info, Node: Chapter Ordering, Next: Sorting, Prev: Type Coercion, Up: Procedures
9459 |
9460 Chapter Ordering
9461 ----------------
9462
9463 `(require 'chapter-order)'
9464
9465 The `chap:' functions deal with strings which are ordered like
9466 chapter numbers (or letters) in a book. Each section of the string
9467 consists of consecutive numeric or consecutive aphabetic characters of
9468 like case.
9469
9470 - Function: chap:string<? string1 string2
9471 Returns #t if the first non-matching run of alphabetic upper-case
9472 or the first non-matching run of alphabetic lower-case or the first
9473 non-matching run of numeric characters of STRING1 is `string<?'
9474 than the corresponding non-matching run of characters of STRING2.
9475
9476 (chap:string<? "a.9" "a.10") => #t
9477 (chap:string<? "4c" "4aa") => #t
9478 (chap:string<? "Revised^{3.99}" "Revised^{4}") => #t
9479
9480 - Function: chap:string>? string1 string2
9481 - Function: chap:string<=? string1 string2
9482 - Function: chap:string>=? string1 string2
9483 Implement the corresponding chapter-order predicates.
9484
9485 - Function: chap:next-string string
9486 Returns the next string in the _chapter order_. If STRING has no
9487 alphabetic or numeric characters, `(string-append STRING "0")' is
9488 returnd. The argument to chap:next-string will always be
9489 `chap:string<?' than the result.
9490
9491 (chap:next-string "a.9") => "a.10"
9492 (chap:next-string "4c") => "4d"
9493 (chap:next-string "4z") => "4aa"
9494 (chap:next-string "Revised^{4}") => "Revised^{5}"
9495
9496 \1f
9497 File: slib.info, Node: Sorting, Next: Topological Sort, Prev: Chapter Ordering, Up: Procedures
9498
9499 Sorting
9500 -------
9501
9502 `(require 'sort)'
9503
9504 Many Scheme systems provide some kind of sorting functions. They do
9505 not, however, always provide the _same_ sorting functions, and those
9506 that I have had the opportunity to test provided inefficient ones (a
9507 common blunder is to use quicksort which does not perform well).
9508
9509 Because `sort' and `sort!' are not in the standard, there is very
9510 little agreement about what these functions look like. For example,
9511 Dybvig says that Chez Scheme provides
9512 (merge predicate list1 list2)
9513 (merge! predicate list1 list2)
9514 (sort predicate list)
9515 (sort! predicate list)
9516
9517 while MIT Scheme 7.1, following Common LISP, offers unstable
9518 (sort list predicate)
9519
9520 TI PC Scheme offers
9521 (sort! list/vector predicate?)
9522
9523 and Elk offers
9524 (sort list/vector predicate?)
9525 (sort! list/vector predicate?)
9526
9527 Here is a comprehensive catalogue of the variations I have found.
9528
9529 1. Both `sort' and `sort!' may be provided.
9530
9531 2. `sort' may be provided without `sort!'.
9532
9533 3. `sort!' may be provided without `sort'.
9534
9535 4. Neither may be provided.
9536
9537 5. The sequence argument may be either a list or a vector.
9538
9539 6. The sequence argument may only be a list.
9540
9541 7. The sequence argument may only be a vector.
9542
9543 8. The comparison function may be expected to behave like `<'.
9544
9545 9. The comparison function may be expected to behave like `<='.
9546
9547 10. The interface may be `(sort predicate? sequence)'.
9548
9549 11. The interface may be `(sort sequence predicate?)'.
9550
9551 12. The interface may be `(sort sequence &optional (predicate? <))'.
9552
9553 13. The sort may be stable.
9554
9555 14. The sort may be unstable.
9556
9557 All of this variation really does not help anybody. A nice simple
9558 merge sort is both stable and fast (quite a lot faster than _quick_
9559 sort).
9560
9561 I am providing this source code with no restrictions at all on its use
9562 (but please retain D.H.D.Warren's credit for the original idea). You
9563 may have to rename some of these functions in order to use them in a
9564 system which already provides incompatible or inferior sorts. For each
9565 of the functions, only the top-level define needs to be edited to do
9566 that.
9567
9568 I could have given these functions names which would not clash with
9569 any Scheme that I know of, but I would like to encourage implementors to
9570 converge on a single interface, and this may serve as a hint. The
9571 argument order for all functions has been chosen to be as close to
9572 Common LISP as made sense, in order to avoid NIH-itis.
9573
9574 Each of the five functions has a required _last_ parameter which is a
9575 comparison function. A comparison function `f' is a function of 2
9576 arguments which acts like `<'. For example,
9577
9578 (not (f x x))
9579 (and (f x y) (f y z)) == (f x z)
9580
9581 The standard functions `<', `>', `char<?', `char>?', `char-ci<?',
9582 `char-ci>?', `string<?', `string>?', `string-ci<?', and `string-ci>?'
9583 are suitable for use as comparison functions. Think of `(less? x y)'
9584 as saying when `x' must _not_ precede `y'.
9585
9586 - Function: sorted? sequence less?
9587 Returns `#t' when the sequence argument is in non-decreasing order
9588 according to LESS? (that is, there is no adjacent pair `... x y
9589 ...' for which `(less? y x)').
9590
9591 Returns `#f' when the sequence contains at least one out-of-order
9592 pair. It is an error if the sequence is neither a list nor a
9593 vector.
9594
9595 - Function: merge list1 list2 less?
9596 This merges two lists, producing a completely new list as result.
9597 I gave serious consideration to producing a Common-LISP-compatible
9598 version. However, Common LISP's `sort' is our `sort!' (well, in
9599 fact Common LISP's `stable-sort' is our `sort!', merge sort is
9600 _fast_ as well as stable!) so adapting CL code to Scheme takes a
9601 bit of work anyway. I did, however, appeal to CL to determine the
9602 _order_ of the arguments.
9603
9604 - Procedure: merge! list1 list2 less?
9605 Merges two lists, re-using the pairs of LIST1 and LIST2 to build
9606 the result. If the code is compiled, and LESS? constructs no new
9607 pairs, no pairs at all will be allocated. The first pair of the
9608 result will be either the first pair of LIST1 or the first pair of
9609 LIST2, but you can't predict which.
9610
9611 The code of `merge' and `merge!' could have been quite a bit
9612 simpler, but they have been coded to reduce the amount of work
9613 done per iteration. (For example, we only have one `null?' test
9614 per iteration.)
9615
9616 - Function: sort sequence less?
9617 Accepts either a list or a vector, and returns a new sequence
9618 which is sorted. The new sequence is the same type as the input.
9619 Always `(sorted? (sort sequence less?) less?)'. The original
9620 sequence is not altered in any way. The new sequence shares its
9621 _elements_ with the old one; no elements are copied.
9622
9623 - Procedure: sort! sequence less?
9624 Returns its sorted result in the original boxes. If the original
9625 sequence is a list, no new storage is allocated at all. If the
9626 original sequence is a vector, the sorted elements are put back in
9627 the same vector.
9628
9629 Some people have been confused about how to use `sort!', thinking
9630 that it doesn't return a value. It needs to be pointed out that
9631 (set! slist (sort! slist <))
9632
9633 is the proper usage, not
9634 (sort! slist <)
9635
9636 Note that these functions do _not_ accept a CL-style `:key' argument.
9637 A simple device for obtaining the same expressiveness is to define
9638 (define (keyed less? key)
9639 (lambda (x y) (less? (key x) (key y))))
9640
9641 and then, when you would have written
9642 (sort a-sequence #'my-less :key #'my-key)
9643
9644 in Common LISP, just write
9645 (sort! a-sequence (keyed my-less? my-key))
9646
9647 in Scheme.
9648
9649 \1f
9650 File: slib.info, Node: Topological Sort, Next: String-Case, Prev: Sorting, Up: Procedures
9651
9652 Topological Sort
9653 ----------------
9654
9655 `(require 'topological-sort)' or `(require 'tsort)'
9656
9657 The algorithm is inspired by Cormen, Leiserson and Rivest (1990)
9658 `Introduction to Algorithms', chapter 23.
9659
9660 - Function: tsort dag pred
9661 - Function: topological-sort dag pred
9662 where
9663 DAG
9664 is a list of sublists. The car of each sublist is a vertex.
9665 The cdr is the adjacency list of that vertex, i.e. a list of
9666 all vertices to which there exists an edge from the car
9667 vertex.
9668
9669 PRED
9670 is one of `eq?', `eqv?', `equal?', `=', `char=?',
9671 `char-ci=?', `string=?', or `string-ci=?'.
9672
9673 Sort the directed acyclic graph DAG so that for every edge from
9674 vertex U to V, U will come before V in the resulting list of
9675 vertices.
9676
9677 Time complexity: O (|V| + |E|)
9678
9679 Example (from Cormen):
9680 Prof. Bumstead topologically sorts his clothing when getting
9681 dressed. The first argument to `tsort' describes which
9682 garments he needs to put on before others. (For example,
9683 Prof Bumstead needs to put on his shirt before he puts on his
9684 tie or his belt.) `tsort' gives the correct order of
9685 dressing:
9686
9687 (require 'tsort)
9688 (tsort '((shirt tie belt)
9689 (tie jacket)
9690 (belt jacket)
9691 (watch)
9692 (pants shoes belt)
9693 (undershorts pants shoes)
9694 (socks shoes))
9695 eq?)
9696 =>
9697 (socks undershorts pants shoes watch shirt belt tie jacket)
9698
9699 \1f
9700 File: slib.info, Node: String-Case, Next: String Ports, Prev: Topological Sort, Up: Procedures
9701
9702 String-Case
9703 -----------
9704
9705 `(require 'string-case)'
9706
9707 - Procedure: string-upcase str
9708 - Procedure: string-downcase str
9709 - Procedure: string-capitalize str
9710 The obvious string conversion routines. These are non-destructive.
9711
9712 - Function: string-upcase! str
9713 - Function: string-downcase! str
9714 - Function: string-captialize! str
9715 The destructive versions of the functions above.
9716
9717 - Function: string-ci->symbol str
9718 Converts string STR to a symbol having the same case as if the
9719 symbol had been `read'.
9720
9721 - Function: symbol-append obj1 ... |
9722 Converts OBJ1 ... to strings, appends them, and converts to a |
9723 symbol which is returned. Strings and numbers are converted to |
9724 read's symbol case; the case of symbol characters is not changed. |
9725 #f is converted to the empty string (symbol). |
9726 |
9727 \1f
9728 File: slib.info, Node: String Ports, Next: String Search, Prev: String-Case, Up: Procedures
9729
9730 String Ports
9731 ------------
9732
9733 `(require 'string-port)'
9734
9735 - Procedure: call-with-output-string proc
9736 PROC must be a procedure of one argument. This procedure calls
9737 PROC with one argument: a (newly created) output port. When the
9738 function returns, the string composed of the characters written
9739 into the port is returned.
9740
9741 - Procedure: call-with-input-string string proc
9742 PROC must be a procedure of one argument. This procedure calls
9743 PROC with one argument: an (newly created) input port from which
9744 STRING's contents may be read. When PROC returns, the port is
9745 closed and the value yielded by the procedure PROC is returned.
9746
9747 \1f
9748 File: slib.info, Node: String Search, Next: Line I/O, Prev: String Ports, Up: Procedures
9749
9750 String Search
9751 -------------
9752
9753 `(require 'string-search)'
9754
9755 - Procedure: string-index string char
9756 - Procedure: string-index-ci string char
9757 Returns the index of the first occurence of CHAR within STRING, or
9758 `#f' if the STRING does not contain a character CHAR.
9759
9760 - Procedure: string-reverse-index string char
9761 - Procedure: string-reverse-index-ci string char
9762 Returns the index of the last occurence of CHAR within STRING, or
9763 `#f' if the STRING does not contain a character CHAR.
9764
9765 - procedure: substring? pattern string
9766 - procedure: substring-ci? pattern string
9767 Searches STRING to see if some substring of STRING is equal to
9768 PATTERN. `substring?' returns the index of the first character of
9769 the first substring of STRING that is equal to PATTERN; or `#f' if
9770 STRING does not contain PATTERN.
9771
9772 (substring? "rat" "pirate") => 2
9773 (substring? "rat" "outrage") => #f
9774 (substring? "" any-string) => 0
9775
9776 - Procedure: find-string-from-port? str in-port max-no-chars
9777 Looks for a string STR within the first MAX-NO-CHARS chars of the
9778 input port IN-PORT.
9779
9780 - Procedure: find-string-from-port? str in-port
9781 When called with two arguments, the search span is limited by the
9782 end of the input stream.
9783
9784 - Procedure: find-string-from-port? str in-port char
9785 Searches up to the first occurrence of character CHAR in STR.
9786
9787 - Procedure: find-string-from-port? str in-port proc
9788 Searches up to the first occurrence of the procedure PROC
9789 returning non-false when called with a character (from IN-PORT)
9790 argument.
9791
9792 When the STR is found, `find-string-from-port?' returns the number
9793 of characters it has read from the port, and the port is set to
9794 read the first char after that (that is, after the STR) The
9795 function returns `#f' when the STR isn't found.
9796
9797 `find-string-from-port?' reads the port _strictly_ sequentially,
9798 and does not perform any buffering. So `find-string-from-port?'
9799 can be used even if the IN-PORT is open to a pipe or other
9800 communication channel.
9801
9802 - Function: string-subst txt old1 new1 ...
9803 Returns a copy of string TXT with all occurrences of string OLD1
9804 in TXT replaced with NEW1, OLD2 replaced with NEW2 ....
9805
9806 \1f
9807 File: slib.info, Node: Line I/O, Next: Multi-Processing, Prev: String Search, Up: Procedures
9808
9809 Line I/O
9810 --------
9811
9812 `(require 'line-i/o)'
9813
9814 - Function: read-line
9815 - Function: read-line port
9816 Returns a string of the characters up to, but not including a
9817 newline or end of file, updating PORT to point to the character
9818 following the newline. If no characters are available, an end of
9819 file object is returned. The PORT argument may be omitted, in
9820 which case it defaults to the value returned by
9821 `current-input-port'.
9822
9823 - Function: read-line! string
9824 - Function: read-line! string port
9825 Fills STRING with characters up to, but not including a newline or
9826 end of file, updating the PORT to point to the last character read
9827 or following the newline if it was read. If no characters are
9828 available, an end of file object is returned. If a newline or end
9829 of file was found, the number of characters read is returned.
9830 Otherwise, `#f' is returned. The PORT argument may be omitted, in
9831 which case it defaults to the value returned by
9832 `current-input-port'.
9833
9834 - Function: write-line string
9835 - Function: write-line string port
9836 Writes STRING followed by a newline to the given PORT and returns
9837 an unspecified value. The PORT argument may be omitted, in which
9838 case it defaults to the value returned by `current-input-port'.
9839
9840 - Function: display-file path
9841 - Function: display-file path port
9842 Displays the contents of the file named by PATH to PORT. The PORT
9843 argument may be ommited, in which case it defaults to the value
9844 returned by `current-output-port'.
9845
9846 \1f
9847 File: slib.info, Node: Multi-Processing, Next: Metric Units, Prev: Line I/O, Up: Procedures
9848 |
9849 Multi-Processing
9850 ----------------
9851
9852 `(require 'process)'
9853
9854 This module implements asynchronous (non-polled) time-sliced
9855 multi-processing in the SCM Scheme implementation using procedures
9856 `alarm' and `alarm-interrupt'. Until this is ported to another
9857 implementation, consider it an example of writing schedulers in Scheme.
9858
9859 - Procedure: add-process! proc
9860 Adds proc, which must be a procedure (or continuation) capable of
9861 accepting accepting one argument, to the `process:queue'. The
9862 value returned is unspecified. The argument to PROC should be
9863 ignored. If PROC returns, the process is killed.
9864
9865 - Procedure: process:schedule!
9866 Saves the current process on `process:queue' and runs the next
9867 process from `process:queue'. The value returned is unspecified.
9868
9869 - Procedure: kill-process!
9870 Kills the current process and runs the next process from
9871 `process:queue'. If there are no more processes on
9872 `process:queue', `(slib:exit)' is called (*note System::).
9873
9874 \1f
9875 File: slib.info, Node: Metric Units, Prev: Multi-Processing, Up: Procedures
9876 |
9877 Metric Units |
9878 ------------ |
9879 |
9880 `(require 'metric-units)' |
9881 |
9882 <http://swissnet.ai.mit.edu/~jaffer/MIXF.html> |
9883 |
9884 "Metric Interchange Format" is a character string encoding for |
9885 numerical values and units which: |
9886 |
9887 * is unambiguous in all locales; |
9888 |
9889 * uses only [TOG] "Portable Character Set" characters matching "Basic |
9890 Latin" characters in Plane 0 of the Universal Character Set [UCS]; |
9891 |
9892 * is transparent to [UTF-7] and [UTF-8] UCS transformation formats; |
9893 |
9894 * is human readable and writable; |
9895 |
9896 * is machine readable and writable; |
9897 |
9898 * incorporates SI prefixes and units; |
9899 |
9900 * incorporates [ISO 6093] numbers; and |
9901 |
9902 * incorporates [IEC 60027-2] binary prefixes. |
9903 |
9904 In the expression for the value of a quantity, the unit symbol is |
9905 placed after the numerical value. A dot (PERIOD, `.') is placed between |
9906 the numerical value and the unit symbol. |
9907 |
9908 Within a compound unit, each of the base and derived symbols can |
9909 optionally have an attached SI prefix. |
9910 |
9911 Unit symbols formed from other unit symbols by multiplication are |
9912 indicated by means of a dot (PERIOD, `.') placed between them. |
9913 |
9914 Unit symbols formed from other unit symbols by division are indicated |
9915 by means of a SOLIDUS (`/') or negative exponents. The SOLIDUS must |
9916 not be repeated in the same compound unit unless contained within a |
9917 parenthesized subexpression. |
9918 |
9919 The grouping formed by a prefix symbol attached to a unit symbol |
9920 constitutes a new inseparable symbol (forming a multiple or submultiple |
9921 of the unit concerned) which can be raised to a positive or negative |
9922 power and which can be combined with other unit symbols to form compound |
9923 unit symbols. |
9924 |
9925 The grouping formed by surrounding compound unit symbols with |
9926 parentheses (`(' and `)') constitutes a new inseparable symbol which |
9927 can be raised to a positive or negative power and which can be combined |
9928 with other unit symbols to form compound unit symbols. |
9929 |
9930 Compound prefix symbols, that is, prefix symbols formed by the |
9931 juxtaposition of two or more prefix symbols, are not permitted. |
9932 |
9933 Prefix symbols are not used with the time-related unit symbols min |
9934 (minute), h (hour), d (day). No prefix symbol may be used with dB |
9935 (decibel). Only submultiple prefix symbols may be used with the unit |
9936 symbols L (liter), Np (neper), o (degree), oC (degree Celsius), rad |
9937 (radian), and sr (steradian). Submultiple prefix symbols may not be |
9938 used with the unit symbols t (metric ton), r (revolution), or Bd (baud). |
9939 |
9940 A unit exponent follows the unit, separated by a CIRCUMFLEX (`^'). |
9941 Exponents may be positive or negative. Fractional exponents must be |
9942 parenthesized. |
9943 |
9944 SI Prefixes |
9945 ........... |
9946 |
9947 Factor Name Symbol | Factor Name Symbol |
9948 ====== ==== ====== | ====== ==== ====== |
9949 1e24 yotta Y | 1e-1 deci d |
9950 1e21 zetta Z | 1e-2 centi c |
9951 1e18 exa E | 1e-3 milli m |
9952 1e15 peta P | 1e-6 micro u |
9953 1e12 tera T | 1e-9 nano n |
9954 1e9 giga G | 1e-12 pico p |
9955 1e6 mega M | 1e-15 femto f |
9956 1e3 kilo k | 1e-18 atto a |
9957 1e2 hecto h | 1e-21 zepto z |
9958 1e1 deka da | 1e-24 yocto y |
9959 |
9960 Binary Prefixes |
9961 ............... |
9962 |
9963 These binary prefixes are valid only with the units B (byte) and bit. |
9964 However, decimal prefixes can also be used with bit; and decimal |
9965 multiple (not submultiple) prefixes can also be used with B (byte). |
9966 |
9967 Factor (power-of-2) Name Symbol |
9968 ====== ============ ==== ====== |
9969 1.152921504606846976e18 (2^60) exbi Ei |
9970 1.125899906842624e15 (2^50) pebi Pi |
9971 1.099511627776e12 (2^40) tebi Ti |
9972 1.073741824e9 (2^30) gibi Gi |
9973 1.048576e6 (2^20) mebi Mi |
9974 1.024e3 (2^10) kibi Ki |
9975 |
9976 Unit Symbols |
9977 ............ |
9978 |
9979 Type of Quantity Name Symbol Equivalent |
9980 ================ ==== ====== ========== |
9981 time second s |
9982 time minute min = 60.s |
9983 time hour h = 60.min |
9984 time day d = 24.h |
9985 frequency hertz Hz s^-1 |
9986 signaling rate baud Bd s^-1 |
9987 length meter m |
9988 volume liter L dm^3 |
9989 plane angle radian rad |
9990 solid angle steradian sr rad^2 |
9991 plane angle revolution * r = 6.283185307179586.rad |
9992 plane angle degree * o = 2.777777777777778e-3.r |
9993 information capacity bit bit |
9994 information capacity byte, octet B = 8.bit |
9995 mass gram g |
9996 mass ton t Mg |
9997 mass unified atomic mass unit u = 1.66053873e-27.kg |
9998 amount of substance mole mol |
9999 catalytic activity katal kat mol/s |
10000 thermodynamic temperature kelvin K |
10001 centigrade temperature degree Celsius oC |
10002 luminous intensity candela cd |
10003 luminous flux lumen lm cd.sr |
10004 illuminance lux lx lm/m^2 |
10005 force newton N m.kg.s^-2 |
10006 pressure, stress pascal Pa N/m^2 |
10007 energy, work, heat joule J N.m |
10008 energy electronvolt eV = 1.602176462e-19.J |
10009 power, radiant flux watt W J/s |
10010 logarithm of power ratio neper Np |
10011 logarithm of power ratio decibel * dB = 0.1151293.Np |
10012 electric current ampere A |
10013 electric charge coulomb C s.A |
10014 electric potential, EMF volt V W/A |
10015 capacitance farad F C/V |
10016 electric resistance ohm Ohm V/A |
10017 electric conductance siemens S A/V |
10018 magnetic flux weber Wb V.s |
10019 magnetic flux density tesla T Wb/m^2 |
10020 inductance henry H Wb/A |
10021 radionuclide activity becquerel Bq s^-1 |
10022 absorbed dose energy gray Gy m^2.s^-2 |
10023 dose equivalent sievert Sv m^2.s^-2 |
10024 |
10025 * The formulas are: |
10026 |
10027 * r/rad = 8 * atan(1) |
10028 |
10029 * o/r = 1 / 360 |
10030 |
10031 * db/Np = ln(10) / 20 |
10032 |
10033 - Function: si:conversion-factor to-unit from-unit |
10034 If the strings FROM-UNIT and TO-UNIT express valid unit |
10035 expressions for quantities of the same unit-dimensions, then the |
10036 value returned by `si:conversion-factor' will be such that |
10037 multiplying a numerical value expressed in FROM-UNITs by the |
10038 returned conversion factor yields the numerical value expressed in |
10039 TO-UNITs. |
10040 |
10041 Otherwise, `si:conversion-factor' returns: |
10042 |
10043 -3 |
10044 if neither FROM-UNIT nor TO-UNIT is a syntactically valid |
10045 unit. |
10046 |
10047 -2 |
10048 if FROM-UNIT is not a syntactically valid unit. |
10049 |
10050 -1 |
10051 if TO-UNIT is not a syntactically valid unit. |
10052 |
10053 0 |
10054 if linear conversion (by a factor) is not possible. |
10055 |
10056 |
10057 (si:conversion-factor "km/s" "m/s" ) => 0.001 |
10058 (si:conversion-factor "N" "m/s" ) => 0 |
10059 (si:conversion-factor "moC" "oC" ) => 1000 |
10060 (si:conversion-factor "mK" "oC" ) => 0 |
10061 (si:conversion-factor "rad" "o" ) => 0.0174533 |
10062 (si:conversion-factor "K" "o" ) => 0 |
10063 (si:conversion-factor "K" "K" ) => 1 |
10064 (si:conversion-factor "oK" "oK" ) => -3 |
10065 (si:conversion-factor "" "s/s" ) => 1 |
10066 (si:conversion-factor "km/h" "mph" ) => -2 |
10067 |
10068 \1f
10069 File: slib.info, Node: Standards Support, Next: Session Support, Prev: Procedures, Up: Other Packages
10070 |
10071 Standards Support
10072 =================
10073
10074 * Menu:
10075
10076 * With-File:: 'with-file
10077 * Transcripts:: 'transcript
10078 * Rev2 Procedures:: 'rev2-procedures
10079 * Rev4 Optional Procedures:: 'rev4-optional-procedures
10080 * Multi-argument / and -:: 'multiarg/and-
10081 * Multi-argument Apply:: 'multiarg-apply
10082 * Rationalize:: 'rationalize
10083 * Promises:: 'promise
10084 * Dynamic-Wind:: 'dynamic-wind
10085 * Eval:: 'eval
10086 * Values:: 'values
10087
10088 \1f
10089 File: slib.info, Node: With-File, Next: Transcripts, Prev: Standards Support, Up: Standards Support
10090
10091 With-File
10092 ---------
10093
10094 `(require 'with-file)'
10095
10096 - Function: with-input-from-file file thunk
10097 - Function: with-output-to-file file thunk
10098 Description found in R4RS.
10099
10100 \1f
10101 File: slib.info, Node: Transcripts, Next: Rev2 Procedures, Prev: With-File, Up: Standards Support
10102
10103 Transcripts
10104 -----------
10105
10106 `(require 'transcript)'
10107
10108 - Function: transcript-on filename
10109 - Function: transcript-off filename
10110 Redefines `read-char', `read', `write-char', `write', `display',
10111 and `newline'.
10112
10113 \1f
10114 File: slib.info, Node: Rev2 Procedures, Next: Rev4 Optional Procedures, Prev: Transcripts, Up: Standards Support
10115
10116 Rev2 Procedures
10117 ---------------
10118
10119 `(require 'rev2-procedures)'
10120
10121 The procedures below were specified in the `Revised^2 Report on
10122 Scheme'. *N.B.*: The symbols `1+' and `-1+' are not `R4RS' syntax.
10123 Scheme->C, for instance, barfs on this module.
10124
10125 - Procedure: substring-move-left! string1 start1 end1 string2 start2
10126 - Procedure: substring-move-right! string1 start1 end1 string2 start2
10127 STRING1 and STRING2 must be a strings, and START1, START2 and END1
10128 must be exact integers satisfying
10129
10130 0 <= START1 <= END1 <= (string-length STRING1)
10131 0 <= START2 <= END1 - START1 + START2 <= (string-length STRING2)
10132
10133 `substring-move-left!' and `substring-move-right!' store
10134 characters of STRING1 beginning with index START1 (inclusive) and
10135 ending with index END1 (exclusive) into STRING2 beginning with
10136 index START2 (inclusive).
10137
10138 `substring-move-left!' stores characters in time order of
10139 increasing indices. `substring-move-right!' stores characters in
10140 time order of increasing indeces.
10141
10142 - Procedure: substring-fill! string start end char
10143 Fills the elements START-END of STRING with the character CHAR.
10144
10145 - Function: string-null? str
10146 == `(= 0 (string-length STR))'
10147
10148 - Procedure: append! . pairs
10149 Destructively appends its arguments. Equivalent to `nconc'.
10150
10151 - Function: 1+ n
10152 Adds 1 to N.
10153
10154 - Function: -1+ n
10155 Subtracts 1 from N.
10156
10157 - Function: <?
10158 - Function: <=?
10159 - Function: =?
10160 - Function: >?
10161 - Function: >=?
10162 These are equivalent to the procedures of the same name but
10163 without the trailing `?'.
10164
10165 \1f
10166 File: slib.info, Node: Rev4 Optional Procedures, Next: Multi-argument / and -, Prev: Rev2 Procedures, Up: Standards Support
10167
10168 Rev4 Optional Procedures
10169 ------------------------
10170
10171 `(require 'rev4-optional-procedures)'
10172
10173 For the specification of these optional procedures, *Note Standard
10174 procedures: (r4rs)Standard procedures.
10175
10176 - Function: list-tail l p
10177
10178 - Function: string->list s
10179
10180 - Function: list->string l
10181
10182 - Function: string-copy
10183
10184 - Procedure: string-fill! s obj
10185
10186 - Function: list->vector l
10187
10188 - Function: vector->list s
10189
10190 - Procedure: vector-fill! s obj
10191
10192 \1f
10193 File: slib.info, Node: Multi-argument / and -, Next: Multi-argument Apply, Prev: Rev4 Optional Procedures, Up: Standards Support
10194
10195 Multi-argument / and -
10196 ----------------------
10197
10198 `(require 'mutliarg/and-)'
10199
10200 For the specification of these optional forms, *Note Numerical
10201 operations: (r4rs)Numerical operations. The `two-arg:'* forms are only
10202 defined if the implementation does not support the many-argument forms.
10203
10204 - Function: two-arg:/ n1 n2
10205 The original two-argument version of `/'.
10206
10207 - Function: / divident . divisors
10208
10209 - Function: two-arg:- n1 n2
10210 The original two-argument version of `-'.
10211
10212 - Function: - minuend . subtrahends
10213
10214 \1f
10215 File: slib.info, Node: Multi-argument Apply, Next: Rationalize, Prev: Multi-argument / and -, Up: Standards Support
10216
10217 Multi-argument Apply
10218 --------------------
10219
10220 `(require 'multiarg-apply)'
10221
10222 For the specification of this optional form, *Note Control features:
10223 (r4rs)Control features.
10224
10225 - Function: two-arg:apply proc l
10226 The implementation's native `apply'. Only defined for
10227 implementations which don't support the many-argument version.
10228
10229 - Function: apply proc . args
10230
10231 \1f
10232 File: slib.info, Node: Rationalize, Next: Promises, Prev: Multi-argument Apply, Up: Standards Support
10233
10234 Rationalize
10235 -----------
10236
10237 `(require 'rationalize)'
10238
10239 The procedure "rationalize" is interesting because most programming
10240 languages do not provide anything analogous to it. Thanks to Alan
10241 Bawden for contributing this algorithm.
10242
10243 - Function: rationalize x y
10244 Computes the correct result for exact arguments (provided the
10245 implementation supports exact rational numbers of unlimited
10246 precision); and produces a reasonable answer for inexact arguments
10247 when inexact arithmetic is implemented using floating-point.
10248
10249 `Rationalize' has limited use in implementations lacking exact
10250 (non-integer) rational numbers. The following procedures return a list
10251 of the numerator and denominator.
10252
10253 - Function: find-ratio x y
10254 `find-ratio' returns the list of the _simplest_ numerator and
10255 denominator whose quotient differs from X by no more than Y.
10256
10257 (find-ratio 3/97 .0001) => (3 97) |
10258 (find-ratio 3/97 .001) => (1 32) |
10259
10260 - Function: find-ratio-between x y
10261 `find-ratio-between' returns the list of the _simplest_ numerator
10262 and denominator between X and Y.
10263
10264 (find-ratio-between 2/7 3/5) => (1 2) |
10265 (find-ratio-between -3/5 -2/7) => (-1 2) |
10266
10267 \1f
10268 File: slib.info, Node: Promises, Next: Dynamic-Wind, Prev: Rationalize, Up: Standards Support
10269
10270 Promises
10271 --------
10272
10273 `(require 'promise)'
10274
10275 - Function: make-promise proc
10276
10277 Change occurrences of `(delay EXPRESSION)' to `(make-promise (lambda
10278 () EXPRESSION))' and `(define force promise:force)' to implement
10279 promises if your implementation doesn't support them (*note Control
10280 features: (r4rs)Control features.).
10281
10282 \1f
10283 File: slib.info, Node: Dynamic-Wind, Next: Eval, Prev: Promises, Up: Standards Support
10284
10285 Dynamic-Wind
10286 ------------
10287
10288 `(require 'dynamic-wind)'
10289
10290 This facility is a generalization of Common LISP `unwind-protect',
10291 designed to take into account the fact that continuations produced by
10292 `call-with-current-continuation' may be reentered.
10293
10294 - Procedure: dynamic-wind thunk1 thunk2 thunk3
10295 The arguments THUNK1, THUNK2, and THUNK3 must all be procedures of
10296 no arguments (thunks).
10297
10298 `dynamic-wind' calls THUNK1, THUNK2, and then THUNK3. The value
10299 returned by THUNK2 is returned as the result of `dynamic-wind'.
10300 THUNK3 is also called just before control leaves the dynamic
10301 context of THUNK2 by calling a continuation created outside that
10302 context. Furthermore, THUNK1 is called before reentering the
10303 dynamic context of THUNK2 by calling a continuation created inside
10304 that context. (Control is inside the context of THUNK2 if THUNK2
10305 is on the current return stack).
10306
10307 *Warning:* There is no provision for dealing with errors or
10308 interrupts. If an error or interrupt occurs while using
10309 `dynamic-wind', the dynamic environment will be that in effect at
10310 the time of the error or interrupt.
10311
10312 \1f
10313 File: slib.info, Node: Eval, Next: Values, Prev: Dynamic-Wind, Up: Standards Support
10314
10315 Eval
10316 ----
10317
10318 `(require 'eval)'
10319
10320 - Function: eval expression environment-specifier
10321 Evaluates EXPRESSION in the specified environment and returns its
10322 value. EXPRESSION must be a valid Scheme expression represented
10323 as data, and ENVIRONMENT-SPECIFIER must be a value returned by one
10324 of the three procedures described below. Implementations may
10325 extend `eval' to allow non-expression programs (definitions) as
10326 the first argument and to allow other values as environments, with
10327 the restriction that `eval' is not allowed to create new bindings
10328 in the environments associated with `null-environment' or
10329 `scheme-report-environment'.
10330
10331 (eval '(* 7 3) (scheme-report-environment 5))
10332 => 21
10333
10334 (let ((f (eval '(lambda (f x) (f x x))
10335 (null-environment))))
10336 (f + 10))
10337 => 20
10338
10339 - Function: scheme-report-environment version
10340 - Function: null-environment version
10341 - Function: null-environment
10342 VERSION must be an exact non-negative integer N corresponding to a
10343 version of one of the Revised^N Reports on Scheme.
10344 `Scheme-report-environment' returns a specifier for an environment
10345 that contains the set of bindings specified in the corresponding
10346 report that the implementation supports. `Null-environment'
10347 returns a specifier for an environment that contains only the
10348 (syntactic) bindings for all the syntactic keywords defined in the
10349 given version of the report.
10350
10351 Not all versions may be available in all implementations at all
10352 times. However, an implementation that conforms to version N of
10353 the Revised^N Reports on Scheme must accept version N. An error
10354 is signalled if the specified version is not available.
10355
10356 The effect of assigning (through the use of `eval') a variable
10357 bound in a `scheme-report-environment' (for example `car') is
10358 unspecified. Thus the environments specified by
10359 `scheme-report-environment' may be immutable.
10360
10361
10362 - Function: interaction-environment
10363 This optional procedure returns a specifier for the environment
10364 that contains implementation-defined bindings, typically a
10365 superset of those listed in the report. The intent is that this
10366 procedure will return the environment in which the implementation
10367 would evaluate expressions dynamically typed by the user.
10368
10369 Here are some more `eval' examples:
10370
10371 (require 'eval)
10372 => #<unspecified>
10373 (define car 'volvo)
10374 => #<unspecified>
10375 car
10376 => volvo
10377 (eval 'car (interaction-environment))
10378 => volvo
10379 (eval 'car (scheme-report-environment 5))
10380 => #<primitive-procedure car>
10381 (eval '(eval 'car (interaction-environment))
10382 (scheme-report-environment 5))
10383 => volvo
10384 (eval '(eval '(set! car 'buick) (interaction-environment))
10385 (scheme-report-environment 5))
10386 => #<unspecified>
10387 car
10388 => buick
10389 (eval 'car (scheme-report-environment 5))
10390 => #<primitive-procedure car>
10391 (eval '(eval 'car (interaction-environment))
10392 (scheme-report-environment 5))
10393 => buick
10394
10395 \1f
10396 File: slib.info, Node: Values, Prev: Eval, Up: Standards Support
10397
10398 Values
10399 ------
10400
10401 `(require 'values)'
10402
10403 - Function: values obj ...
10404 `values' takes any number of arguments, and passes (returns) them
10405 to its continuation.
10406
10407 - Function: call-with-values thunk proc
10408 THUNK must be a procedure of no arguments, and PROC must be a
10409 procedure. `call-with-values' calls THUNK with a continuation
10410 that, when passed some values, calls PROC with those values as
10411 arguments.
10412
10413 Except for continuations created by the `call-with-values'
10414 procedure, all continuations take exactly one value, as now; the
10415 effect of passing no value or more than one value to continuations
10416 that were not created by the `call-with-values' procedure is
10417 unspecified.
10418
10419 \1f
10420 File: slib.info, Node: Session Support, Next: Extra-SLIB Packages, Prev: Standards Support, Up: Other Packages
10421
10422 Session Support
10423 ===============
10424
10425 * Menu:
10426
10427 * Repl:: Macros at top-level
10428 * Quick Print:: Loop-safe Output
10429 * Debug:: To err is human ...
10430 * Breakpoints:: Pause execution
10431 * Trace:: 'trace
10432 * System Interface:: 'system, 'getenv, and 'net-clients
10433
10434 \1f
10435 File: slib.info, Node: Repl, Next: Quick Print, Prev: Session Support, Up: Session Support
10436
10437 Repl
10438 ----
10439
10440 `(require 'repl)'
10441
10442 Here is a read-eval-print-loop which, given an eval, evaluates forms.
10443
10444 - Procedure: repl:top-level repl:eval
10445 `read's, `repl:eval's and `write's expressions from
10446 `(current-input-port)' to `(current-output-port)' until an
10447 end-of-file is encountered. `load', `slib:eval', `slib:error',
10448 and `repl:quit' dynamically bound during `repl:top-level'.
10449
10450 - Procedure: repl:quit
10451 Exits from the invocation of `repl:top-level'.
10452
10453 The `repl:' procedures establish, as much as is possible to do
10454 portably, a top level environment supporting macros. `repl:top-level'
10455 uses `dynamic-wind' to catch error conditions and interrupts. If your
10456 implementation supports this you are all set.
10457
10458 Otherwise, if there is some way your implementation can catch error
10459 conditions and interrupts, then have them call `slib:error'. It will
10460 display its arguments and reenter `repl:top-level'. `slib:error'
10461 dynamically bound by `repl:top-level'.
10462
10463 To have your top level loop always use macros, add any interrupt
10464 catching lines and the following lines to your Scheme init file:
10465 (require 'macro)
10466 (require 'repl)
10467 (repl:top-level macro:eval)
10468
10469 \1f
10470 File: slib.info, Node: Quick Print, Next: Debug, Prev: Repl, Up: Session Support
10471
10472 Quick Print
10473 -----------
10474
10475 `(require 'qp)'
10476
10477 When displaying error messages and warnings, it is paramount that the
10478 output generated for circular lists and large data structures be
10479 limited. This section supplies a procedure to do this. It could be
10480 much improved.
10481
10482 Notice that the neccessity for truncating output eliminates
10483 Common-Lisp's *Note Format:: from consideration; even when
10484 variables `*print-level*' and `*print-level*' are set, huge
10485 strings and bit-vectors are _not_ limited.
10486
10487 - Procedure: qp arg1 ...
10488 - Procedure: qpn arg1 ...
10489 - Procedure: qpr arg1 ...
10490 `qp' writes its arguments, separated by spaces, to
10491 `(current-output-port)'. `qp' compresses printing by substituting
10492 `...' for substructure it does not have sufficient room to print.
10493 `qpn' is like `qp' but outputs a newline before returning. `qpr'
10494 is like `qpn' except that it returns its last argument.
10495
10496 - Variable: *qp-width*
10497 `*qp-width*' is the largest number of characters that `qp' should
10498 use.
10499
10500 \1f
10501 File: slib.info, Node: Debug, Next: Breakpoints, Prev: Quick Print, Up: Session Support
10502
10503 Debug
10504 -----
10505
10506 `(require 'debug)'
10507
10508 Requiring `debug' automatically requires `trace' and `break'.
10509
10510 An application with its own datatypes may want to substitute its own
10511 printer for `qp'. This example shows how to do this:
10512
10513 (define qpn (lambda args) ...)
10514 (provide 'qp)
10515 (require 'debug)
10516
10517 - Procedure: trace-all file ...
10518 Traces (*note Trace::) all procedures `define'd at top-level in
10519 `file' ....
10520
10521 - Procedure: track-all file ...
10522 Tracks (*note Trace::) all procedures `define'd at top-level in
10523 `file' ....
10524
10525 - Procedure: stack-all file ...
10526 Stacks (*note Trace::) all procedures `define'd at top-level in
10527 `file' ....
10528
10529 - Procedure: break-all file ...
10530 Breakpoints (*note Breakpoints::) all procedures `define'd at
10531 top-level in `file' ....
10532
10533 \1f
10534 File: slib.info, Node: Breakpoints, Next: Trace, Prev: Debug, Up: Session Support
10535
10536 Breakpoints
10537 -----------
10538
10539 `(require 'break)'
10540
10541 - Function: init-debug
10542 If your Scheme implementation does not support `break' or `abort',
10543 a message will appear when you `(require 'break)' or `(require
10544 'debug)' telling you to type `(init-debug)'. This is in order to
10545 establish a top-level continuation. Typing `(init-debug)' at top
10546 level sets up a continuation for `break'.
10547
10548 - Function: breakpoint arg1 ...
10549 Returns from the top level continuation and pushes the
10550 continuation from which it was called on a continuation stack.
10551
10552 - Function: continue
10553 Pops the topmost continuation off of the continuation stack and
10554 returns an unspecified value to it.
10555
10556 - Function: continue arg1 ...
10557 Pops the topmost continuation off of the continuation stack and
10558 returns ARG1 ... to it.
10559
10560 - Macro: break proc1 ...
10561 Redefines the top-level named procedures given as arguments so that
10562 `breakpoint' is called before calling PROC1 ....
10563
10564 - Macro: break
10565 With no arguments, makes sure that all the currently broken
10566 identifiers are broken (even if those identifiers have been
10567 redefined) and returns a list of the broken identifiers.
10568
10569 - Macro: unbreak proc1 ...
10570 Turns breakpoints off for its arguments.
10571
10572 - Macro: unbreak
10573 With no arguments, unbreaks all currently broken identifiers and
10574 returns a list of these formerly broken identifiers.
10575
10576 These are _procedures_ for breaking. If defmacros are not natively
10577 supported by your implementation, these might be more convenient to use.
10578
10579 - Function: breakf proc
10580 - Function: breakf proc name
10581 To break, type
10582 (set! SYMBOL (breakf SYMBOL))
10583
10584 or
10585 (set! SYMBOL (breakf SYMBOL 'SYMBOL))
10586
10587 or
10588 (define SYMBOL (breakf FUNCTION))
10589
10590 or
10591 (define SYMBOL (breakf FUNCTION 'SYMBOL))
10592
10593 - Function: unbreakf proc
10594 To unbreak, type
10595 (set! SYMBOL (unbreakf SYMBOL))
10596
10597 \1f
10598 File: slib.info, Node: Trace, Next: System Interface, Prev: Breakpoints, Up: Session Support
10599
10600 Tracing
10601 -------
10602
10603 `(require 'trace)'
10604
10605 This feature provides three ways to monitor procedure invocations:
10606
10607 stack
10608 Pushes the procedure-name when the procedure is called; pops when
10609 it returns.
10610
10611 track
10612 Pushes the procedure-name and arguments when the procedure is
10613 called; pops when it returns.
10614
10615 trace
10616 Pushes the procedure-name and prints `CALL PROCEDURE-NAME ARG1
10617 ...' when the procdure is called; pops and prints `RETN
10618 PROCEDURE-NAME VALUE' when the procedure returns.
10619
10620 - Variable: debug:max-count
10621 If a traced procedure calls itself or untraced procedures which
10622 call it, stack, track, and trace will limit the number of stack
10623 pushes to DEBUG:MAX-COUNT.
10624
10625 - Function: print-call-stack
10626 - Function: print-call-stack port
10627 Prints the call-stack to PORT or the current-error-port.
10628
10629 - Macro: trace proc1 ...
10630 Traces the top-level named procedures given as arguments.
10631
10632 - Macro: trace
10633 With no arguments, makes sure that all the currently traced
10634 identifiers are traced (even if those identifiers have been
10635 redefined) and returns a list of the traced identifiers.
10636
10637 - Macro: track proc1 ...
10638 Traces the top-level named procedures given as arguments.
10639
10640 - Macro: track
10641 With no arguments, makes sure that all the currently tracked
10642 identifiers are tracked (even if those identifiers have been
10643 redefined) and returns a list of the tracked identifiers.
10644
10645 - Macro: stack proc1 ...
10646 Traces the top-level named procedures given as arguments.
10647
10648 - Macro: stack
10649 With no arguments, makes sure that all the currently stacked
10650 identifiers are stacked (even if those identifiers have been
10651 redefined) and returns a list of the stacked identifiers.
10652
10653 - Macro: untrace proc1 ...
10654 Turns tracing, tracking, and off for its arguments.
10655
10656 - Macro: untrace
10657 With no arguments, untraces all currently traced identifiers and
10658 returns a list of these formerly traced identifiers.
10659
10660 - Macro: untrack proc1 ...
10661 Turns tracing, tracking, and off for its arguments.
10662
10663 - Macro: untrack
10664 With no arguments, untracks all currently tracked identifiers and
10665 returns a list of these formerly tracked identifiers.
10666
10667 - Macro: unstack proc1 ...
10668 Turns tracing, stacking, and off for its arguments.
10669
10670 - Macro: unstack
10671 With no arguments, unstacks all currently stacked identifiers and
10672 returns a list of these formerly stacked identifiers.
10673
10674 These are _procedures_ for tracing. If defmacros are not natively
10675 supported by your implementation, these might be more convenient to use.
10676
10677 - Function: tracef proc
10678 - Function: tracef proc name
10679 To trace, type
10680 (set! SYMBOL (tracef SYMBOL))
10681
10682 or
10683 (set! SYMBOL (tracef SYMBOL 'SYMBOL))
10684
10685 or
10686 (define SYMBOL (tracef FUNCTION))
10687
10688 or
10689 (define SYMBOL (tracef FUNCTION 'SYMBOL))
10690
10691 - Function: untracef proc
10692 Removes tracing, tracking, or stacking for PROC. To untrace, type
10693 (set! SYMBOL (untracef SYMBOL))
10694
10695 \1f
10696 File: slib.info, Node: System Interface, Prev: Trace, Up: Session Support
10697
10698 System Interface
10699 ----------------
10700
10701 If `(provided? 'getenv)':
10702
10703 - Function: getenv name
10704 Looks up NAME, a string, in the program environment. If NAME is
10705 found a string of its value is returned. Otherwise, `#f' is
10706 returned.
10707
10708 If `(provided? 'system)':
10709
10710 - Function: system command-string
10711 Executes the COMMAND-STRING on the computer and returns the
10712 integer status code.
10713
10714 If `system' is provided by the Scheme implementation, the "net-clients"
10715 package provides interfaces to common network client programs like FTP,
10716 mail, and Netscape.
10717
10718 `(require 'net-clients)'
10719
10720 - Function: call-with-tmpnam proc
10721 - Function: call-with-tmpnam proc k
10722 Calls PROC with K arguments, strings returned by successive calls
10723 to `tmpnam'. If PROC returns, then any files named by the
10724 arguments to PROC are deleted automatically and the value(s)
10725 yielded by the PROC is(are) returned. K may be ommited, in which
10726 case it defaults to `1'.
10727
10728 - Function: user-email-address
10729 `user-email-address' returns a string of the form
10730 `username@hostname'. If this e-mail address cannot be obtained,
10731 #f is returned.
10732
10733 - Function: current-directory
10734 `current-directory' returns a string containing the absolute file
10735 name representing the current working directory. If this string
10736 cannot be obtained, #f is returned.
10737
10738 If `current-directory' cannot be supported by the platform, the
10739 value of `current-directory' is #f.
10740
10741 - Function: make-directory name
10742 Creates a sub-directory NAME of the current-directory. If
10743 successful, `make-directory' returns #t; otherwise #f.
10744
10745 - Function: null-directory? file-name
10746 Returns #t if changing directory to FILE-NAME makes the current
10747 working directory the same as it is before changing directory;
10748 otherwise returns #f.
10749
10750 - Function: absolute-path? file-name
10751 Returns #t if FILE-NAME is a fully specified pathname (does not
10752 depend on the current working directory); otherwise returns #f.
10753
10754 - Function: glob-pattern? str
10755 Returns #t if the string STR contains characters used for
10756 specifying glob patterns, namely `*', `?', or `['.
10757
10758 - Function: parse-ftp-address uri |
10759 Returns a list of the decoded FTP URI; or #f if indecipherable. |
10760 FTP "Uniform Resource Locator", "ange-ftp", and "getit" formats
10761 are handled. The returned list has four elements which are
10762 strings or #f:
10763
10764 0. username
10765
10766 1. password
10767
10768 2. remote-site
10769
10770 3. remote-directory
10771
10772 - Function: ftp-upload paths user password remote-site remote-dir
10773 PASSWORD must be a non-empty string or #f. PATHS must be a
10774 non-empty list of pathnames or Glob patterns (*note Filenames::)
10775 matching files to transfer.
10776
10777 `ftp-upload' puts the files specified by PATHS into the REMOTE-DIR
10778 directory of FTP REMOTE-SITE using name USER with (optional)
10779 PASSWORD.
10780
10781 If PASSWORD is #f and USER is not `ftp' or `anonymous', then USER
10782 is ignored; FTP takes the username and password from the `.netrc'
10783 or equivalent file.
10784
10785 - Function: path->uri path |
10786 Returns a URI-string for PATH on the local host. |
10787
10788 - Function: browse-url-netscape url
10789 If a `netscape' browser is running, `browse-url-netscape' causes
10790 the browser to display the page specified by string URL and
10791 returns #t.
10792
10793 If the browser is not running, `browse-url-netscape' runs
10794 `netscape' with the argument URL. If the browser starts as a
10795 background job, `browse-url-netscape' returns #t immediately; if
10796 the browser starts as a foreground job, then `browse-url-netscape'
10797 returns #t when the browser exits; otherwise it returns #f.
10798
10799 \1f
10800 File: slib.info, Node: Extra-SLIB Packages, Prev: Session Support, Up: Other Packages
10801
10802 Extra-SLIB Packages
10803 ===================
10804
10805 Several Scheme packages have been written using SLIB. There are
10806 several reasons why a package might not be included in the SLIB
10807 distribution:
10808 * Because it requires special hardware or software which is not
10809 universal.
10810
10811 * Because it is large and of limited interest to most Scheme users.
10812
10813 * Because it has copying terms different enough from the other SLIB
10814 packages that its inclusion would cause confusion.
10815
10816 * Because it is an application program, rather than a library module.
10817
10818 * Because I have been too busy to integrate it.
10819
10820 Once an optional package is installed (and an entry added to
10821 `*catalog*', the `require' mechanism allows it to be called up and used
10822 as easily as any other SLIB package. Some optional packages (for which
10823 `*catalog*' already has entries) available from SLIB sites are:
10824
10825 SLIB-PSD
10826 is a portable debugger for Scheme (requires emacs editor).
10827
10828 http://swissnet.ai.mit.edu/ftpdir/scm/slib-psd1-3.tar.gz
10829
10830 swissnet.ai.mit.edu:/pub/scm/slib-psd1-3.tar.gz
10831
10832 ftp.maths.tcd.ie:pub/bosullvn/jacal/slib-psd1-3.tar.gz
10833
10834 ftp.cs.indiana.edu:/pub/scheme-repository/utl/slib-psd1-3.tar.gz
10835
10836
10837 With PSD, you can run a Scheme program in an Emacs buffer, set
10838 breakpoints, single step evaluation and access and modify the
10839 program's variables. It works by instrumenting the original source
10840 code, so it should run with any R4RS compliant Scheme. It has been
10841 tested with SCM, Elk 1.5, and the sci interpreter in the Scheme->C
10842 system, but should work with other Schemes with a minimal amount
10843 of porting, if at all. Includes documentation and user's manual.
10844 Written by Pertti Kellom\"aki, pk@cs.tut.fi. The Lisp Pointers
10845 article describing PSD (Lisp Pointers VI(1):15-23, January-March
10846 1993) is available as
10847 http://www.cs.tut.fi/staff/pk/scheme/psd/article/article.html
10848
10849
10850 SCHELOG
10851 is an embedding of Prolog in Scheme.
10852 http://www.cs.rice.edu/CS/PLT/packages/schelog/
10853
10854
10855 JFILTER
10856 is a Scheme program which converts text among the JIS, EUC, and
10857 Shift-JIS Japanese character sets.
10858 http://www.sci.toyama-u.ac.jp/~iwao/Scheme/Jfilter/index.html
10859
10860 \1f
10861 File: slib.info, Node: About SLIB, Next: Index, Prev: Other Packages, Up: Top
10862
10863 About SLIB
10864 **********
10865
10866 More people than I can name have contributed to SLIB. Thanks to all of
10867 you!
10868
10869 SLIB 2d1, released March 2001. |
10870 Aubrey Jaffer <jaffer @ ai.mit.edu>
10871 Hyperactive Software - The Maniac Inside!
10872 <http://swissnet.ai.mit.edu/~jaffer/SLIB.html>
10873
10874 * Menu:
10875
10876 * Installation:: How to install SLIB on your system.
10877 * Porting:: SLIB to new platforms.
10878 * Coding Guidelines:: How to write modules for SLIB.
10879 * Copyrights:: Intellectual propery issues.
10880
10881 \1f
10882 File: slib.info, Node: Installation, Next: Porting, Prev: About SLIB, Up: About SLIB
10883
10884 Installation
10885 ============
10886
10887 Check the manifest in `README' to find a configuration file for your
10888 Scheme implementation. Initialization files for most IEEE P1178
10889 compliant Scheme Implementations are included with this distribution.
10890
10891 If the Scheme implementation supports `getenv', then the value of the
10892 shell environment variable SCHEME_LIBRARY_PATH will be used for
10893 `(library-vicinity)' if it is defined. Currently, Chez, Elk,
10894 MITScheme, scheme->c, VSCM, and SCM support `getenv'. Scheme48
10895 supports `getenv' but does not use it for determining
10896 `library-vicinity'. (That is done from the Makefile.)
10897
10898 You should check the definitions of `software-type',
10899 `scheme-implementation-version', `implementation-vicinity', and
10900 `library-vicinity' in the initialization file. There are comments in
10901 the file for how to configure it.
10902
10903 Once this is done you can modify the startup file for your Scheme
10904 implementation to `load' this initialization file. SLIB is then
10905 installed.
10906
10907 Multiple implementations of Scheme can all use the same SLIB
10908 directory. Simply configure each implementation's initialization file
10909 as outlined above.
10910
10911 - Implementation: SCM
10912 The SCM implementation does not require any initialization file as
10913 SLIB support is already built into SCM. See the documentation
10914 with SCM for installation instructions.
10915
10916 - Implementation: VSCM
10917 From: Matthias Blume <blume@cs.Princeton.EDU>
10918 Date: Tue, 1 Mar 1994 11:42:31 -0500
10919
10920 Disclaimer: The code below is only a quick hack. If I find some
10921 time to spare I might get around to make some more things work.
10922
10923 You have to provide `vscm.init' as an explicit command line
10924 argument. Since this is not very nice I would recommend the
10925 following installation procedure:
10926
10927 1. run scheme
10928
10929 2. `(load "vscm.init")'
10930
10931 3. `(slib:dump "dumpfile")'
10932
10933 4. mv dumpfile place-where-vscm-standard-bootfile-resides e.g.
10934 mv dumpfile /usr/local/vscm/lib/scheme-boot (In this case
10935 vscm should have been compiled with flag
10936 -DDEFAULT_BOOTFILE='"/usr/local/vscm/lib/scheme-boot"'. See
10937 Makefile (definition of DDP) for details.)
10938
10939
10940 - Implementation: Scheme48
10941 To make a Scheme48 image for an installation under `<prefix>',
10942
10943 1. `cd' to the SLIB directory
10944
10945 2. type `make prefix=<prefix> slib48'.
10946
10947 3. To install the image, type `make prefix=<prefix> install48'.
10948 This will also create a shell script with the name `slib48'
10949 which will invoke the saved image.
10950
10951 - Implementation: PLT Scheme
10952 - Implementation: DrScheme
10953 - Implementation: MzScheme
10954 Date: Mon, 2 Oct 2000 21:29:48 -0400 (EDT)
10955 From: Shriram Krishnamurthi <sk@cs.brown.edu>
10956
10957 We distribute an SLIB init file for our system. If you have PLT
10958 Scheme (our preferred name for the entire suite, which includes
10959 DrScheme, MzScheme and other implementations) installed, you ought
10960 to be able to run "help-desk", or run `drscheme' and choose Help
10961 Desk from the Help menu; in Help Desk, type `slib'. This will give
10962 instructions for how to load the SLIB init file.
10963
10964 \1f
10965 File: slib.info, Node: Porting, Next: Coding Guidelines, Prev: Installation, Up: About SLIB
10966
10967 Porting
10968 =======
10969
10970 If there is no initialization file for your Scheme implementation, you
10971 will have to create one. Your Scheme implementation must be largely
10972 compliant with `IEEE Std 1178-1990', `Revised^4 Report on the
10973 Algorithmic Language Scheme', or `Revised^5 Report on the Algorithmic
10974 Language Scheme' in order to support SLIB. (1)
10975
10976 `Template.scm' is an example configuration file. The comments inside
10977 will direct you on how to customize it to reflect your system. Give
10978 your new initialization file the implementation's name with `.init'
10979 appended. For instance, if you were porting `foo-scheme' then the
10980 initialization file might be called `foo.init'.
10981
10982 Your customized version should then be loaded as part of your scheme
10983 implementation's initialization. It will load `require.scm' from the
10984 library; this will allow the use of `provide', `provided?', and
10985 `require' along with the "vicinity" functions (these functions are
10986 documented in the section *Note Require::). The rest of the library
10987 will then be accessible in a system independent fashion.
10988
10989 Please mail new working configuration files to `jaffer @ ai.mit.edu'
10990 so that they can be included in the SLIB distribution.
10991
10992 ---------- Footnotes ----------
10993
10994 (1) If you are porting a `Revised^3 Report on the Algorithmic
10995 Language Scheme' implementation, then you will need to finish writing
10996 `sc4sc3.scm' and `load' it from your initialization file.
10997
10998 \1f
10999 File: slib.info, Node: Coding Guidelines, Next: Copyrights, Prev: Porting, Up: About SLIB
11000
11001 Coding Guidelines
11002 =================
11003
11004 All library packages are written in IEEE P1178 Scheme and assume that
11005 a configuration file and `require.scm' package have already been
11006 loaded. Other versions of Scheme can be supported in library packages
11007 as well by using, for example, `(provided? 'rev3-report)' or `(require
11008 'rev3-report)' (*note Require::).
11009
11010 The module name and `:' should prefix each symbol defined in the
11011 package. Definitions for external use should then be exported by having
11012 `(define foo module-name:foo)'.
11013
11014 Code submitted for inclusion in SLIB should not duplicate routines
11015 already in SLIB files. Use `require' to force those library routines
11016 to be used by your package. Care should be taken that there are no
11017 circularities in the `require's and `load's between the library
11018 packages.
11019
11020 Documentation should be provided in Emacs Texinfo format if possible,
11021 But documentation must be provided.
11022
11023 Your package will be released sooner with SLIB if you send me a file
11024 which tests your code. Please run this test _before_ you send me the
11025 code!
11026
11027 Modifications
11028 -------------
11029
11030 Please document your changes. A line or two for `ChangeLog' is
11031 sufficient for simple fixes or extensions. Look at the format of
11032 `ChangeLog' to see what information is desired. Please send me `diff'
11033 files from the latest SLIB distribution (remember to send `diff's of
11034 `slib.texi' and `ChangeLog'). This makes for less email traffic and
11035 makes it easier for me to integrate when more than one person is
11036 changing a file (this happens a lot with `slib.texi' and `*.init'
11037 files).
11038
11039 If someone else wrote a package you want to significantly modify,
11040 please try to contact the author, who may be working on a new version.
11041 This will insure against wasting effort on obsolete versions.
11042
11043 Please _do not_ reformat the source code with your favorite
11044 beautifier, make 10 fixes, and send me the resulting source code. I do
11045 not have the time to fish through 10000 diffs to find your 10 real
11046 fixes.
11047
11048 \1f
11049 File: slib.info, Node: Copyrights, Prev: Coding Guidelines, Up: About SLIB
11050
11051 Copyrights
11052 ==========
11053
11054 This section has instructions for SLIB authors regarding copyrights.
11055
11056 Each package in SLIB must either be in the public domain, or come
11057 with a statement of terms permitting users to copy, redistribute and
11058 modify it. The comments at the beginning of `require.scm' and
11059 `macwork.scm' illustrate copyright and appropriate terms.
11060
11061 If your code or changes amount to less than about 10 lines, you do not
11062 need to add your copyright or send a disclaimer.
11063
11064 Putting code into the Public Domain
11065 -----------------------------------
11066
11067 In order to put code in the public domain you should sign a copyright
11068 disclaimer and send it to the SLIB maintainer. Contact jaffer @
11069 ai.mit.edu for the address to mail the disclaimer to.
11070
11071 I, NAME, hereby affirm that I have placed the software package
11072 NAME in the public domain.
11073
11074 I affirm that I am the sole author and sole copyright holder for
11075 the software package, that I have the right to place this software
11076 package in the public domain, and that I will do nothing to
11077 undermine this status in the future.
11078
11079 SIGNATURE AND DATE
11080
11081 This wording assumes that you are the sole author. If you are not the
11082 sole author, the wording needs to be different. If you don't want to be
11083 bothered with sending a letter every time you release or modify a
11084 module, make your letter say that it also applies to your future
11085 revisions of that module.
11086
11087 Make sure no employer has any claim to the copyright on the work you
11088 are submitting. If there is any doubt, create a copyright disclaimer
11089 and have your employer sign it. Mail the signed disclaimer to the SLIB
11090 maintainer. Contact jaffer @ ai.mit.edu for the address to mail the
11091 disclaimer to. An example disclaimer follows.
11092
11093 Explicit copying terms
11094 ----------------------
11095
11096 If you submit more than about 10 lines of code which you are not placing
11097 into the Public Domain (by sending me a disclaimer) you need to:
11098
11099 * Arrange that your name appears in a copyright line for the
11100 appropriate year. Multiple copyright lines are acceptable.
11101
11102 * With your copyright line, specify any terms you require to be
11103 different from those already in the file.
11104
11105 * Make sure no employer has any claim to the copyright on the work
11106 you are submitting. If there is any doubt, create a copyright
11107 disclaimer and have your employer sign it. Mail the signed
11108 disclaim to the SLIB maintainer. Contact jaffer @ ai.mit.edu for
11109 the address to mail the disclaimer to.
11110
11111 Example: Company Copyright Disclaimer
11112 -------------------------------------
11113
11114 This disclaimer should be signed by a vice president or general
11115 manager of the company. If you can't get at them, anyone else
11116 authorized to license out software produced there will do. Here is a
11117 sample wording:
11118
11119 EMPLOYER Corporation hereby disclaims all copyright interest in
11120 the program PROGRAM written by NAME.
11121
11122 EMPLOYER Corporation affirms that it has no other intellectual
11123 property interest that would undermine this release, and will do
11124 nothing to undermine it in the future.
11125
11126 SIGNATURE AND DATE,
11127 NAME, TITLE, EMPLOYER Corporation
11128
11129 \1f
11130 File: slib.info, Node: Index, Prev: About SLIB, Up: Top
11131
11132 Procedure and Macro Index
11133 *************************
11134
11135 This is an alphabetical list of all the procedures and macros in SLIB.
11136
11137 * Menu:
11138
11139 * -: Multi-argument / and -.
11140 * -1+: Rev2 Procedures.
11141 * /: Multi-argument / and -.
11142 * 1+: Rev2 Procedures.
11143 * <=?: Rev2 Procedures.
11144 * <?: Rev2 Procedures.
11145 * =?: Rev2 Procedures.
11146 * >=?: Rev2 Procedures.
11147 * >?: Rev2 Procedures.
11148 * absolute-path?: System Interface.
11149 * add-domain: Database Utilities.
11150 * add-process!: Multi-Processing.
11151 * add-setter: Setters.
11152 * adjoin: Lists as sets.
11153 * adjoin-parameters!: Parameter lists.
11154 * alarm: Multi-Processing.
11155 * alarm-interrupt: Multi-Processing.
11156 * alist->wt-tree: Construction of Weight-Balanced Trees.
11157 * alist-associator: Association Lists.
11158 * alist-for-each: Association Lists.
11159 * alist-inquirer: Association Lists.
11160 * alist-map: Association Lists.
11161 * alist-remover: Association Lists.
11162 * and?: Non-List functions.
11163 * any?: Collections.
11164 * append!: Rev2 Procedures.
11165 * apply: Multi-argument Apply.
11166 * array-1d-ref: Arrays.
11167 * array-1d-set!: Arrays.
11168 * array-2d-ref: Arrays.
11169 * array-2d-set!: Arrays.
11170 * array-3d-ref: Arrays.
11171 * array-3d-set!: Arrays.
11172 * array-copy!: Array Mapping.
11173 * array-dimensions: Arrays.
11174 * array-for-each: Array Mapping.
11175 * array-in-bounds?: Arrays.
11176 * array-index-map!: Array Mapping.
11177 * array-indexes: Array Mapping.
11178 * array-map!: Array Mapping.
11179 * array-rank: Arrays.
11180 * array-ref: Arrays.
11181 * array-set!: Arrays.
11182 * array-shape: Arrays.
11183 * array?: Arrays.
11184 * asctime: Posix Time.
11185 * ash: Bit-Twiddling.
11186 * atom?: Non-List functions.
11187 * batch:call-with-output-script: Batch.
11188 * batch:command: Batch.
11189 * batch:comment: Batch.
11190 * batch:delete-file: Batch.
11191 * batch:initialize!: Batch.
11192 * batch:lines->file: Batch.
11193 * batch:rename-file: Batch.
11194 * batch:run-script: Batch.
11195 * batch:try-chopped-command: Batch.
11196 * batch:try-command: Batch.
11197 * bit-extract: Bit-Twiddling.
11198 * bit-field: Bit-Twiddling.
11199 * bitwise-if: Bit-Twiddling.
11200 * break: Breakpoints.
11201 * break-all: Debug.
11202 * breakf: Breakpoints.
11203 * breakpoint: Breakpoints.
11204 * browse: Database Browser.
11205 * browse-url-netscape: System Interface.
11206 * butlast: Lists as sequences.
11207 * butnthcdr: Lists as sequences.
11208 * byte-ref: Byte.
11209 * byte-set!: Byte.
11210 * bytes: Byte.
11211 * bytes->list: Byte.
11212 * bytes-length: Byte.
11213 * call-with-dynamic-binding: Dynamic Data Type.
11214 * call-with-input-string: String Ports.
11215 * call-with-output-string: String Ports.
11216 * call-with-tmpnam: System Interface.
11217 * call-with-values: Values.
11218 * capture-syntactic-environment: Syntactic Closures.
11219 * cart-prod-tables: Relational Database Operations.
11220 * catalog->html: HTML Tables. |
11221 * cgi:serve-query: HTTP and CGI.
11222 * chap:next-string: Chapter Ordering.
11223 * chap:string<=?: Chapter Ordering.
11224 * chap:string<?: Chapter Ordering.
11225 * chap:string>=?: Chapter Ordering.
11226 * chap:string>?: Chapter Ordering.
11227 * check-parameters: Parameter lists.
11228 * close-base: Base Table.
11229 * close-database: Relational Database Operations.
11230 * close-table: Table Operations.
11231 * coerce: Type Coercion. |
11232 * collection?: Collections.
11233 * combined-rulesets: Commutative Rings.
11234 * command->p-specs: HTML. |
11235 * command:make-editable-table: HTML Tables. |
11236 * command:modify-table: HTML Tables. |
11237 * continue: Breakpoints.
11238 * copy-bit: Bit-Twiddling.
11239 * copy-bit-field: Bit-Twiddling.
11240 * copy-list: List construction.
11241 * copy-random-state: Random Numbers.
11242 * copy-tree: Tree Operations.
11243 * create-database <1>: Database Utilities.
11244 * create-database: Creating and Opening Relational Databases.
11245 * create-report: Database Reports.
11246 * create-table: Relational Database Operations.
11247 * create-view: Relational Database Operations.
11248 * cring:define-rule: Commutative Rings.
11249 * ctime: Posix Time.
11250 * current-directory: System Interface.
11251 * current-error-port: Input/Output.
11252 * current-input-port <1>: Byte.
11253 * current-input-port: Ruleset Definition and Use.
11254 * current-output-port: Byte.
11255 * current-time: Time and Date.
11256 * db->html-directory: HTML Tables. |
11257 * db->html-files: HTML Tables. |
11258 * db->netscape: HTML Tables.
11259 * decode-universal-time: Common-Lisp Time.
11260 * define-access-operation: Setters.
11261 * define-operation: Yasos interface.
11262 * define-predicate: Yasos interface.
11263 * define-record: Structures.
11264 * define-syntax: Macro by Example.
11265 * define-tables: Database Utilities.
11266 * defmacro: Defmacro.
11267 * defmacro:eval: Defmacro.
11268 * defmacro:expand*: Defmacro.
11269 * defmacro:load: Defmacro.
11270 * defmacro?: Defmacro.
11271 * delete <1>: Destructive list operations.
11272 * delete: Base Table.
11273 * delete*: Base Table.
11274 * delete-domain: Database Utilities.
11275 * delete-file: Input/Output.
11276 * delete-if: Destructive list operations.
11277 * delete-if-not: Destructive list operations.
11278 * delete-table: Relational Database Operations.
11279 * dequeue!: Queues.
11280 * determinant: Determinant. |
11281 * difftime: Time and Date.
11282 * display-file: Line I/O.
11283 * do-elts: Collections.
11284 * do-keys: Collections.
11285 * domain-checker: Database Utilities.
11286 * dynamic-ref: Dynamic Data Type.
11287 * dynamic-set!: Dynamic Data Type.
11288 * dynamic-wind: Dynamic-Wind.
11289 * dynamic?: Dynamic Data Type.
11290 * empty?: Collections.
11291 * encode-universal-time: Common-Lisp Time.
11292 * enquque!: Queues.
11293 * equal?: Byte.
11294 * eval: Eval.
11295 * every: Lists as sets.
11296 * every?: Collections.
11297 * extended-euclid: Modular Arithmetic.
11298 * factor: Prime Numbers.
11299 * fft: Fast Fourier Transform.
11300 * fft-1: Fast Fourier Transform.
11301 * file-exists?: Input/Output.
11302 * filename:match-ci??: Filenames.
11303 * filename:match??: Filenames.
11304 * filename:substitute-ci??: Filenames.
11305 * filename:substitute??: Filenames.
11306 * fill-empty-parameters: Parameter lists.
11307 * find-if: Lists as sets.
11308 * find-ratio: Rationalize.
11309 * find-ratio-between: Rationalize.
11310 * find-string-from-port?: String Search.
11311 * fluid-let: Fluid-Let.
11312 * for-each-elt: Collections.
11313 * for-each-key <1>: Collections.
11314 * for-each-key: Base Table.
11315 * for-each-row: Table Operations.
11316 * force-output: Input/Output.
11317 * form:delimited: HTML. |
11318 * form:element: HTML. |
11319 * form:image: HTML. |
11320 * form:reset: HTML. |
11321 * form:submit: HTML. |
11322 * format: Format Interface.
11323 * fprintf: Standard Formatted Output.
11324 * fscanf: Standard Formatted Input.
11325 * ftp-upload: System Interface.
11326 * generic-write: Generic-Write.
11327 * gentemp: Defmacro.
11328 * get: Table Operations.
11329 * get*: Table Operations.
11330 * get-decoded-time: Common-Lisp Time.
11331 * get-method: Object.
11332 * get-universal-time: Common-Lisp Time.
11333 * getenv: System Interface.
11334 * getopt: Getopt.
11335 * getopt--: Getopt.
11336 * getopt->arglist: Getopt Parameter lists.
11337 * getopt->parameter-list: Getopt Parameter lists.
11338 * glob-pattern?: System Interface.
11339 * gmktime: Posix Time.
11340 * gmtime: Posix Time.
11341 * golden-section-search: Minimizing.
11342 * gtime: Posix Time.
11343 * has-duplicates?: Lists as sets.
11344 * hash: Hashing.
11345 * hash-associator: Hash Tables.
11346 * hash-for-each: Hash Tables.
11347 * hash-inquirer: Hash Tables.
11348 * hash-map: Hash Tables.
11349 * hash-remover: Hash Tables.
11350 * hashq: Hashing.
11351 * hashv: Hashing.
11352 * heap-extract-max!: Priority Queues.
11353 * heap-insert!: Priority Queues.
11354 * heap-length: Priority Queues.
11355 * home-vicinity: Vicinity.
11356 * html:anchor: URI. |
11357 * html:atval: HTML.
11358 * html:base: URI. |
11359 * html:body: HTML.
11360 * html:buttons: HTML. |
11361 * html:caption: HTML Tables. |
11362 * html:checkbox: HTML. |
11363 * html:comment: HTML.
11364 * html:editable-row-converter: HTML Tables. |
11365 * html:form: HTML.
11366 * html:head: HTML.
11367 * html:heading: HTML Tables.
11368 * html:hidden: HTML. |
11369 * html:href-heading: HTML Tables.
11370 * html:http-equiv: HTML. |
11371 * html:isindex: URI. |
11372 * html:link: URI. |
11373 * html:linked-row-converter: HTML Tables. |
11374 * html:meta: HTML. |
11375 * html:meta-refresh: HTML. |
11376 * html:plain: HTML.
11377 * html:pre: HTML.
11378 * html:select: HTML. |
11379 * html:table: HTML Tables.
11380 * html:text: HTML. |
11381 * html:text-area: HTML. |
11382 * http:content: HTTP and CGI.
11383 * http:error-page: HTTP and CGI.
11384 * http:forwarding-page: HTTP and CGI. |
11385 * http:header: HTTP and CGI.
11386 * http:serve-query: HTTP and CGI.
11387 * identifier=?: Syntactic Closures.
11388 * identifier?: Syntactic Closures.
11389 * identity: Legacy.
11390 * implementation-vicinity: Vicinity.
11391 * in-vicinity: Vicinity.
11392 * init-debug: Breakpoints.
11393 * integer-expt: Bit-Twiddling.
11394 * integer-length: Bit-Twiddling.
11395 * integer-sqrt: Root Finding.
11396 * interaction-environment: Eval.
11397 * intersection: Lists as sets.
11398 * jacobi-symbol: Prime Numbers.
11399 * kill-process!: Multi-Processing.
11400 * kill-table: Base Table.
11401 * laguerre:find-polynomial-root: Root Finding.
11402 * laguerre:find-root: Root Finding.
11403 * last: Lists as sequences.
11404 * last-pair: Legacy.
11405 * library-vicinity: Vicinity.
11406 * list*: List construction.
11407 * list->bytes: Byte.
11408 * list->string: Rev4 Optional Procedures.
11409 * list->vector: Rev4 Optional Procedures.
11410 * list-of??: Lists as sets. |
11411 * list-table-definition: Database Utilities. |
11412 * list-tail: Rev4 Optional Procedures.
11413 * load-option: Weight-Balanced Trees.
11414 * localtime: Posix Time.
11415 * logand: Bit-Twiddling.
11416 * logbit?: Bit-Twiddling.
11417 * logcount: Bit-Twiddling.
11418 * logior: Bit-Twiddling.
11419 * lognot: Bit-Twiddling.
11420 * logtest: Bit-Twiddling.
11421 * logxor: Bit-Twiddling.
11422 * macro:eval <1>: Syntax-Case Macros.
11423 * macro:eval <2>: Syntactic Closures.
11424 * macro:eval <3>: Macros That Work.
11425 * macro:eval: R4RS Macros.
11426 * macro:expand <1>: Syntax-Case Macros.
11427 * macro:expand <2>: Syntactic Closures.
11428 * macro:expand <3>: Macros That Work.
11429 * macro:expand: R4RS Macros.
11430 * macro:load <1>: Syntax-Case Macros.
11431 * macro:load <2>: Syntactic Closures.
11432 * macro:load <3>: Macros That Work.
11433 * macro:load: R4RS Macros.
11434 * macroexpand: Defmacro.
11435 * macroexpand-1: Defmacro.
11436 * macwork:eval: Macros That Work.
11437 * macwork:expand: Macros That Work.
11438 * macwork:load: Macros That Work.
11439 * make-: Structures.
11440 * make-array: Arrays.
11441 * make-base: Base Table.
11442 * make-bytes: Byte.
11443 * make-command-server: Database Utilities.
11444 * make-directory: System Interface.
11445 * make-dynamic: Dynamic Data Type.
11446 * make-generic-method: Object.
11447 * make-generic-predicate: Object.
11448 * make-getter: Base Table.
11449 * make-hash-table: Hash Tables.
11450 * make-heap: Priority Queues.
11451 * make-key->list: Base Table.
11452 * make-key-extractor: Base Table.
11453 * make-keyifier-1: Base Table.
11454 * make-list: List construction.
11455 * make-list-keyifier: Base Table.
11456 * make-method!: Object.
11457 * make-object: Object.
11458 * make-parameter-list: Parameter lists.
11459 * make-port-crc: Cyclic Checksum.
11460 * make-predicate!: Object.
11461 * make-promise: Promises.
11462 * make-putter: Base Table.
11463 * make-query-alist-command-server: HTTP and CGI. |
11464 * make-queue: Queues.
11465 * make-random-state: Random Numbers.
11466 * make-record-type: Records.
11467 * make-relational-system: Creating and Opening Relational Databases.
11468 * make-ruleset: Commutative Rings.
11469 * make-shared-array: Arrays.
11470 * make-sierpinski-indexer: Hashing.
11471 * make-syntactic-closure: Syntactic Closures.
11472 * make-table: Base Table.
11473 * make-uri: URI. |
11474 * make-vicinity: Vicinity.
11475 * make-wt-tree: Construction of Weight-Balanced Trees.
11476 * make-wt-tree-type: Construction of Weight-Balanced Trees.
11477 * map-elts: Collections.
11478 * map-key: Base Table.
11479 * map-keys: Collections.
11480 * member-if: Lists as sets.
11481 * merge: Sorting.
11482 * merge!: Sorting.
11483 * mktime: Posix Time.
11484 * modular:: Modular Arithmetic.
11485 * modular:*: Modular Arithmetic.
11486 * modular:+: Modular Arithmetic.
11487 * modular:expt: Modular Arithmetic.
11488 * modular:invert: Modular Arithmetic.
11489 * modular:invertable?: Modular Arithmetic.
11490 * modular:negate: Modular Arithmetic.
11491 * modular:normalize: Modular Arithmetic.
11492 * modulus->integer: Modular Arithmetic.
11493 * must-be-first: Batch.
11494 * must-be-last: Batch.
11495 * nconc: Destructive list operations.
11496 * newton:find-root: Root Finding.
11497 * newtown:find-integer-root: Root Finding.
11498 * notany: Lists as sets.
11499 * notevery: Lists as sets.
11500 * nreverse: Destructive list operations.
11501 * nthcdr: Lists as sequences.
11502 * null-directory?: System Interface.
11503 * null-environment: Eval.
11504 * object: Yasos interface.
11505 * object->limited-string: Object-To-String.
11506 * object->string: Object-To-String.
11507 * object-with-ancestors: Yasos interface.
11508 * object?: Object.
11509 * offset-time: Time and Date.
11510 * open-base: Base Table.
11511 * open-database <1>: Database Utilities.
11512 * open-database: Creating and Opening Relational Databases.
11513 * open-database!: Database Utilities.
11514 * open-table <1>: Relational Database Operations.
11515 * open-table: Base Table.
11516 * operate-as: Yasos interface.
11517 * or?: Non-List functions.
11518 * ordered-for-each-key: Base Table.
11519 * os->batch-dialect: Batch.
11520 * output-port-height: Input/Output.
11521 * output-port-width: Input/Output.
11522 * parameter-list->arglist: Parameter lists.
11523 * parameter-list-expand: Parameter lists.
11524 * parameter-list-ref: Parameter lists.
11525 * parse-ftp-address: System Interface.
11526 * path->uri: System Interface. |
11527 * plot!: Plotting.
11528 * plot-function!: Plotting.
11529 * pnm:array-write: Portable Image Files.
11530 * pnm:image-file->array: Portable Image Files.
11531 * pnm:type-dimensions: Portable Image Files.
11532 * position: Lists as sequences.
11533 * pprint-file: Pretty-Print.
11534 * pprint-filter-file: Pretty-Print.
11535 * prec:commentfix: Grammar Rule Definition.
11536 * prec:define-grammar: Ruleset Definition and Use.
11537 * prec:delim: Grammar Rule Definition.
11538 * prec:infix: Grammar Rule Definition.
11539 * prec:inmatchfix: Grammar Rule Definition.
11540 * prec:make-led: Nud and Led Definition.
11541 * prec:make-nud: Nud and Led Definition.
11542 * prec:matchfix: Grammar Rule Definition.
11543 * prec:nary: Grammar Rule Definition.
11544 * prec:nofix: Grammar Rule Definition.
11545 * prec:parse: Ruleset Definition and Use.
11546 * prec:postfix: Grammar Rule Definition.
11547 * prec:prefix: Grammar Rule Definition.
11548 * prec:prestfix: Grammar Rule Definition.
11549 * predicate->asso: Association Lists.
11550 * predicate->hash: Hash Tables.
11551 * predicate->hash-asso: Hash Tables.
11552 * present?: Base Table.
11553 * pretty-print: Pretty-Print.
11554 * pretty-print->string: Pretty-Print. |
11555 * prime?: Prime Numbers.
11556 * primes<: Prime Numbers.
11557 * primes>: Prime Numbers.
11558 * print: Yasos interface.
11559 * print-call-stack: Trace.
11560 * printf: Standard Formatted Output.
11561 * process:schedule!: Multi-Processing.
11562 * program-vicinity: Vicinity.
11563 * project-table: Relational Database Operations.
11564 * provide <1>: Require.
11565 * provide: Feature.
11566 * provided? <1>: Require.
11567 * provided?: Feature.
11568 * qp: Quick Print.
11569 * qpn: Quick Print.
11570 * qpr: Quick Print.
11571 * queue-empty?: Queues.
11572 * queue-front: Queues.
11573 * queue-pop!: Queues.
11574 * queue-push!: Queues.
11575 * queue-rear: Queues.
11576 * queue?: Queues.
11577 * random: Random Numbers.
11578 * random:exp: Random Numbers.
11579 * random:hollow-sphere!: Random Numbers.
11580 * random:normal: Random Numbers.
11581 * random:normal-vector!: Random Numbers.
11582 * random:solid-sphere!: Random Numbers.
11583 * random:uniform: Random Numbers.
11584 * rationalize: Rationalize.
11585 * read-byte: Byte.
11586 * read-command: Command Line.
11587 * read-line: Line I/O.
11588 * read-line!: Line I/O.
11589 * read-options-file: Command Line.
11590 * record-accessor: Records.
11591 * record-constructor: Records.
11592 * record-modifier: Records.
11593 * record-predicate: Records.
11594 * reduce <1>: Lists as sequences.
11595 * reduce: Collections.
11596 * reduce-init: Lists as sequences.
11597 * remove: Lists as sets.
11598 * remove-duplicates: Lists as sets.
11599 * remove-if: Lists as sets.
11600 * remove-if-not: Lists as sets.
11601 * remove-parameter: Parameter lists.
11602 * remove-setter-for: Setters.
11603 * repl:quit: Repl.
11604 * repl:top-level: Repl.
11605 * replace-suffix: Filenames.
11606 * require <1>: Require.
11607 * require <2>: Catalog Compilation.
11608 * require: Requesting Features.
11609 * require:feature->path <1>: Require.
11610 * require:feature->path: Requesting Features.
11611 * restrict-table: Relational Database Operations.
11612 * row:delete: Table Operations.
11613 * row:delete*: Table Operations.
11614 * row:insert: Table Operations.
11615 * row:insert*: Table Operations.
11616 * row:remove: Table Operations.
11617 * row:remove*: Table Operations.
11618 * row:retrieve: Table Operations.
11619 * row:retrieve*: Table Operations.
11620 * row:update: Table Operations.
11621 * row:update*: Table Operations.
11622 * scanf: Standard Formatted Input.
11623 * scanf-read-list: Standard Formatted Input.
11624 * scheme-report-environment: Eval.
11625 * schmooz: Schmooz.
11626 * secant:find-bracketed-root: Root Finding.
11627 * secant:find-root: Root Finding.
11628 * seed->random-state: Random Numbers.
11629 * set: Setters.
11630 * set-: Structures.
11631 * set-difference: Lists as sets.
11632 * Setter: Collections.
11633 * setter: Setters.
11634 * si:conversion-factor: Metric Units. |
11635 * singleton-wt-tree: Construction of Weight-Balanced Trees.
11636 * size <1>: Collections.
11637 * size: Yasos interface.
11638 * slib:error: System.
11639 * slib:eval: System.
11640 * slib:eval-load: System.
11641 * slib:exit: System.
11642 * slib:load: System.
11643 * slib:load-compiled: System.
11644 * slib:load-source: System.
11645 * slib:report: Configuration.
11646 * slib:report-version: Configuration.
11647 * slib:warn: System.
11648 * software-type: Configuration.
11649 * some: Lists as sets.
11650 * sort: Sorting.
11651 * sort!: Sorting.
11652 * sorted?: Sorting.
11653 * soundex: Hashing.
11654 * sprintf: Standard Formatted Output.
11655 * sscanf: Standard Formatted Input.
11656 * stack: Trace.
11657 * stack-all: Debug.
11658 * string->list: Rev4 Optional Procedures.
11659 * string-capitalize: String-Case.
11660 * string-captialize!: String-Case.
11661 * string-ci->symbol: String-Case.
11662 * string-copy: Rev4 Optional Procedures.
11663 * string-downcase: String-Case.
11664 * string-downcase!: String-Case.
11665 * string-fill!: Rev4 Optional Procedures.
11666 * string-index: String Search.
11667 * string-index-ci: String Search.
11668 * string-join: Batch.
11669 * string-null?: Rev2 Procedures.
11670 * string-reverse-index: String Search.
11671 * string-reverse-index-ci: String Search.
11672 * string-subst: String Search.
11673 * string-upcase: String-Case.
11674 * string-upcase!: String-Case.
11675 * sub-vicinity: Vicinity.
11676 * subst: Tree Operations.
11677 * substq: Tree Operations.
11678 * substring-ci?: String Search.
11679 * substring-fill!: Rev2 Procedures.
11680 * substring-move-left!: Rev2 Procedures.
11681 * substring-move-right!: Rev2 Procedures.
11682 * substring?: String Search.
11683 * substv: Tree Operations.
11684 * supported-key-type?: Base Table.
11685 * supported-type?: Base Table.
11686 * symbol-append: String-Case. |
11687 * symmetric:modulus: Modular Arithmetic.
11688 * sync-base: Base Table.
11689 * sync-database: Relational Database Operations. |
11690 * syncase:eval: Syntax-Case Macros.
11691 * syncase:expand: Syntax-Case Macros.
11692 * syncase:load: Syntax-Case Macros.
11693 * synclo:eval: Syntactic Closures.
11694 * synclo:expand: Syntactic Closures.
11695 * synclo:load: Syntactic Closures.
11696 * syntax-rules: Macro by Example.
11697 * system: System Interface.
11698 * table->linked-html: HTML Tables. |
11699 * table->linked-page: HTML Tables. |
11700 * table-exists?: Relational Database Operations.
11701 * table-name->filename: HTML Tables.
11702 * TAG: Structures.
11703 * tek40:draw: Tektronix Graphics Support.
11704 * tek40:graphics: Tektronix Graphics Support.
11705 * tek40:init: Tektronix Graphics Support.
11706 * tek40:linetype: Tektronix Graphics Support.
11707 * tek40:move: Tektronix Graphics Support.
11708 * tek40:put-text: Tektronix Graphics Support.
11709 * tek40:reset: Tektronix Graphics Support.
11710 * tek40:text: Tektronix Graphics Support.
11711 * tek41:draw: Tektronix Graphics Support.
11712 * tek41:encode-int: Tektronix Graphics Support.
11713 * tek41:encode-x-y: Tektronix Graphics Support.
11714 * tek41:graphics: Tektronix Graphics Support.
11715 * tek41:init: Tektronix Graphics Support.
11716 * tek41:move: Tektronix Graphics Support.
11717 * tek41:point: Tektronix Graphics Support.
11718 * tek41:reset: Tektronix Graphics Support.
11719 * time-zone: Time Zone.
11720 * tmpnam: Input/Output.
11721 * tok:char-group: Token definition.
11722 * topological-sort: Topological Sort.
11723 * trace: Trace.
11724 * trace-all: Debug.
11725 * tracef: Trace.
11726 * track: Trace.
11727 * track-all: Debug.
11728 * transcript-off: Transcripts.
11729 * transcript-on: Transcripts.
11730 * transformer: Syntactic Closures.
11731 * truncate-up-to: Batch.
11732 * tsort: Topological Sort.
11733 * two-arg:-: Multi-argument / and -.
11734 * two-arg:/: Multi-argument / and -.
11735 * two-arg:apply: Multi-argument Apply.
11736 * type-of: Type Coercion. |
11737 * tz:params: Time Zone.
11738 * tzset: Time Zone.
11739 * unbreak: Breakpoints.
11740 * unbreakf: Breakpoints.
11741 * union: Lists as sets.
11742 * unmake-method!: Object.
11743 * unstack: Trace.
11744 * untrace: Trace.
11745 * untracef: Trace.
11746 * untrack: Trace.
11747 * uri->tree: URI. |
11748 * uric:decode: URI. |
11749 * uric:encode: URI. |
11750 * user-email-address: System Interface.
11751 * user-vicinity: Vicinity.
11752 * values: Values.
11753 * variant-case: Structures.
11754 * vector->list: Rev4 Optional Procedures.
11755 * vector-fill!: Rev4 Optional Procedures.
11756 * with-input-from-file: With-File.
11757 * with-output-to-file: With-File.
11758 * write-base: Base Table.
11759 * write-byte: Byte.
11760 * write-database: Relational Database Operations.
11761 * write-line: Line I/O.
11762 * wt-tree/add: Basic Operations on Weight-Balanced Trees.
11763 * wt-tree/add!: Basic Operations on Weight-Balanced Trees.
11764 * wt-tree/delete: Basic Operations on Weight-Balanced Trees.
11765 * wt-tree/delete!: Basic Operations on Weight-Balanced Trees.
11766 * wt-tree/delete-min: Indexing Operations on Weight-Balanced Trees.
11767 * wt-tree/delete-min!: Indexing Operations on Weight-Balanced Trees.
11768 * wt-tree/difference: Advanced Operations on Weight-Balanced Trees.
11769 * wt-tree/empty?: Basic Operations on Weight-Balanced Trees.
11770 * wt-tree/fold: Advanced Operations on Weight-Balanced Trees.
11771 * wt-tree/for-each: Advanced Operations on Weight-Balanced Trees.
11772 * wt-tree/index: Indexing Operations on Weight-Balanced Trees.
11773 * wt-tree/index-datum: Indexing Operations on Weight-Balanced Trees.
11774 * wt-tree/index-pair: Indexing Operations on Weight-Balanced Trees.
11775 * wt-tree/intersection: Advanced Operations on Weight-Balanced Trees.
11776 * wt-tree/lookup: Basic Operations on Weight-Balanced Trees.
11777 * wt-tree/member?: Basic Operations on Weight-Balanced Trees.
11778 * wt-tree/min: Indexing Operations on Weight-Balanced Trees.
11779 * wt-tree/min-datum: Indexing Operations on Weight-Balanced Trees.
11780 * wt-tree/min-pair: Indexing Operations on Weight-Balanced Trees.
11781 * wt-tree/rank: Indexing Operations on Weight-Balanced Trees.
11782 * wt-tree/set-equal?: Advanced Operations on Weight-Balanced Trees.
11783 * wt-tree/size: Basic Operations on Weight-Balanced Trees.
11784 * wt-tree/split<: Advanced Operations on Weight-Balanced Trees.
11785 * wt-tree/split>: Advanced Operations on Weight-Balanced Trees.
11786 * wt-tree/subset?: Advanced Operations on Weight-Balanced Trees.
11787 * wt-tree/union: Advanced Operations on Weight-Balanced Trees.
11788 * wt-tree?: Basic Operations on Weight-Balanced Trees.
11789
11790 Variable Index
11791 **************
11792
11793 This is an alphabetical list of all the global variables in SLIB.
11794
11795 * Menu:
11796
11797 * *catalog*: Require.
11798 * *features*: Require.
11799 * *http:byline*: HTTP and CGI.
11800 * *modules*: Require.
11801 * *optarg*: Getopt.
11802 * *optind*: Getopt.
11803 * *qp-width*: Quick Print.
11804 * *random-state*: Random Numbers.
11805 * *ruleset*: Commutative Rings.
11806 * *syn-defs*: Ruleset Definition and Use.
11807 * *syn-ignore-whitespace*: Ruleset Definition and Use.
11808 * *timezone*: Time Zone.
11809 * batch:platform: Batch.
11810 * catalog-id: Base Table.
11811 * char-code-limit: Configuration.
11812 * charplot:height: Plotting.
11813 * charplot:width: Plotting.
11814 * column-domains: Table Operations.
11815 * column-foreigns: Table Operations.
11816 * column-names: Table Operations.
11817 * column-types: Table Operations.
11818 * daylight?: Time Zone.
11819 * debug:max-count: Trace.
11820 * distribute*: Commutative Rings.
11821 * distribute/: Commutative Rings.
11822 * most-positive-fixnum: Configuration.
11823 * nil: Legacy.
11824 * number-wt-type: Construction of Weight-Balanced Trees.
11825 * primary-limit: Table Operations.
11826 * prime:prngs: Prime Numbers.
11827 * prime:trials: Prime Numbers.
11828 * slib:form-feed: Configuration.
11829 * slib:tab: Configuration.
11830 * stderr: Standard Formatted I/O.
11831 * stdin: Standard Formatted I/O.
11832 * stdout: Standard Formatted I/O.
11833 * string-wt-type: Construction of Weight-Balanced Trees.
11834 * t: Legacy.
11835 * tok:decimal-digits: Token definition.
11836 * tok:lower-case: Token definition.
11837 * tok:upper-case: Token definition.
11838 * tok:whitespaces: Token definition.
11839 * tzname: Time Zone.
11840
11841 Concept and Feature Index
11842 *************************
11843
11844 * Menu:
11845
11846 * alist: Association Lists.
11847 * alist-table <1>: Creating and Opening Relational Databases.
11848 * alist-table: Base Table.
11849 * ange-ftp: System Interface.
11850 * array: Arrays.
11851 * array-for-each: Array Mapping.
11852 * attribute-value: HTML.
11853 * balanced binary trees: Weight-Balanced Trees.
11854 * base: URI. |
11855 * batch: Batch.
11856 * binary trees: Weight-Balanced Trees.
11857 * binary trees, as discrete maps: Weight-Balanced Trees.
11858 * binary trees, as sets: Weight-Balanced Trees.
11859 * break: Breakpoints.
11860 * byte: Byte.
11861 * calendar time <1>: Posix Time.
11862 * calendar time: Time and Date.
11863 * Calendar-Time: Posix Time.
11864 * caltime: Posix Time.
11865 * careful: Commutative Rings.
11866 * catalog: Requesting Features.
11867 * Catalog File: Library Catalogs.
11868 * chapter-order: Chapter Ordering.
11869 * charplot: Plotting.
11870 * coerce: Type Coercion. |
11871 * collect: Collections.
11872 * command line: Command Line.
11873 * commentfix: Precedence Parsing Overview.
11874 * common-list-functions <1>: Common List Functions.
11875 * common-list-functions: Collections.
11876 * commutative-ring: Commutative Rings.
11877 * Coordinated Universal Time: Posix Time.
11878 * database-utilities <1>: Database Utilities.
11879 * database-utilities: Batch.
11880 * debug <1>: Breakpoints.
11881 * debug: Debug.
11882 * defmacroexpand <1>: Pretty-Print.
11883 * defmacroexpand: Defmacro.
11884 * delim: Precedence Parsing Overview.
11885 * discrete maps, using binary trees: Weight-Balanced Trees.
11886 * DrScheme: Installation.
11887 * dynamic: Dynamic Data Type.
11888 * dynamic-wind: Dynamic-Wind.
11889 * escaped: URI. |
11890 * Euclidean Domain: Commutative Rings.
11891 * factor: Prime Numbers.
11892 * feature <1>: About this manual.
11893 * feature <2>: Requesting Features.
11894 * feature: Feature.
11895 * fft: Fast Fourier Transform.
11896 * fluid-let <1>: Database Utilities.
11897 * fluid-let: Fluid-Let.
11898 * form: HTML.
11899 * format: Format.
11900 * generic-write: Generic-Write.
11901 * getit: System Interface.
11902 * getopt <1>: Database Utilities.
11903 * getopt: Getopt.
11904 * glob <1>: Batch.
11905 * glob: Filenames.
11906 * hash: Hashing.
11907 * hash-table: Hash Tables.
11908 * HOME <1>: Vicinity.
11909 * HOME: Library Catalogs.
11910 * homecat: Catalog Compilation.
11911 * implcat: Catalog Compilation.
11912 * infix: Precedence Parsing Overview.
11913 * inmatchfix: Precedence Parsing Overview.
11914 * Left Denotation, led: Nud and Led Definition.
11915 * line-i: Line I/O.
11916 * logical: Bit-Twiddling.
11917 * macro <1>: Repl.
11918 * macro: R4RS Macros.
11919 * macro-by-example: Macro by Example.
11920 * macros-that-work: Macros That Work.
11921 * make-crc: Cyclic Checksum.
11922 * match: Base Table.
11923 * match-keys <1>: Table Operations.
11924 * match-keys: Base Table.
11925 * matchfix: Precedence Parsing Overview.
11926 * metric-units: Metric Units. |
11927 * minimize: Minimizing.
11928 * minimum field width (printf): Standard Formatted Output.
11929 * mkimpcat.scm: Catalog Compilation.
11930 * mklibcat.scm: Catalog Compilation.
11931 * modular: Modular Arithmetic.
11932 * multiarg-apply: Multi-argument Apply.
11933 * mutliarg: Multi-argument / and -.
11934 * MzScheme: Installation.
11935 * nary: Precedence Parsing Overview.
11936 * net-clients: System Interface.
11937 * new-catalog: Catalog Compilation. |
11938 * nofix: Precedence Parsing Overview.
11939 * null: HTML Tables. |
11940 * Null Denotation, nud: Nud and Led Definition.
11941 * object: Object.
11942 * object->string: Object-To-String.
11943 * oop: Yasos.
11944 * option, run-time-loadable: Weight-Balanced Trees.
11945 * options file: Command Line.
11946 * parameters <1>: Database Utilities.
11947 * parameters <2>: Batch.
11948 * parameters: Parameter lists.
11949 * parse: Precedence Parsing.
11950 * plain-text: HTML.
11951 * PLT Scheme: Installation.
11952 * posix-time: Posix Time.
11953 * postfix: Precedence Parsing Overview.
11954 * pprint-file: Pretty-Print.
11955 * PRE: HTML.
11956 * precedence: Precedence Parsing.
11957 * precision (printf): Standard Formatted Output.
11958 * prefix: Precedence Parsing Overview.
11959 * prestfix: Precedence Parsing Overview.
11960 * pretty-print: Pretty-Print.
11961 * primes: Prime Numbers.
11962 * printf: Standard Formatted Output.
11963 * priority-queue: Priority Queues.
11964 * PRNG: Random Numbers.
11965 * process: Multi-Processing.
11966 * promise: Promises.
11967 * qp <1>: Quick Print.
11968 * qp: Getopt.
11969 * query-string: HTTP and CGI.
11970 * queue: Queues.
11971 * random: Random Numbers.
11972 * rationalize: Rationalize.
11973 * read-command: Command Line.
11974 * record: Records.
11975 * relational-database: Relational Database.
11976 * repl <1>: Repl.
11977 * repl: Syntax-Case Macros.
11978 * reset: HTML.
11979 * rev2-procedures: Rev2 Procedures.
11980 * rev3-report: Coding Guidelines.
11981 * rev4-optional-procedures: Rev4 Optional Procedures.
11982 * ring, commutative: Commutative Rings.
11983 * RNG: Random Numbers.
11984 * root: Root Finding.
11985 * run-time-loadable option: Weight-Balanced Trees.
11986 * scanf: Standard Formatted Input.
11987 * Scheme48: Installation.
11988 * schmooz: Schmooz.
11989 * SCM: Installation.
11990 * Server-based Naming Authority: URI. |
11991 * session: Feature.
11992 * sets, using binary trees: Weight-Balanced Trees.
11993 * sierpinski: Hashing.
11994 * sitecat: Catalog Compilation.
11995 * slibcat: Catalog Compilation.
11996 * sort: Sorting.
11997 * soundex: Hashing.
11998 * stdio: Standard Formatted I/O.
11999 * string-case: String-Case.
12000 * string-port: String Ports.
12001 * string-search: String Search.
12002 * struct: Structures.
12003 * syntactic-closures: Syntactic Closures.
12004 * syntax-case: Syntax-Case Macros.
12005 * time: Time and Date.
12006 * time-zone: Time Zone.
12007 * topological-sort: Topological Sort.
12008 * trace: Trace.
12009 * transcript: Transcripts.
12010 * tree: Tree Operations.
12011 * trees, balanced binary: Weight-Balanced Trees.
12012 * tsort: Topological Sort.
12013 * TZ-string: Time Zone.
12014 * Uniform Resource Identifiers: URI. |
12015 * Uniform Resource Locator: System Interface.
12016 * Unique Factorization: Commutative Rings.
12017 * unsafe: URI. |
12018 * URI: HTTP and CGI.
12019 * usercat: Catalog Compilation.
12020 * UTC: Posix Time.
12021 * values: Values.
12022 * VSCM: Installation.
12023 * weight-balanced binary trees: Weight-Balanced Trees.
12024 * wild-card: Base Table.
12025 * with-file: With-File.
12026 * wt-tree: Weight-Balanced Trees.
12027 * yasos: Yasos.
12028
12029
12030 \1f
12031 Tag Table:
12032 Node: Top\7f1026
12033 Node: The Library System\7f1740
12034 Node: Feature\7f2054
12035 Node: Requesting Features\7f3004
12036 Node: Library Catalogs\7f4363
12037 Node: Catalog Compilation\7f6815
12038 Node: Built-in Support\7f9624
12039 Node: Require\7f10255
12040 Node: Vicinity\7f12747
12041 Node: Configuration\7f15714
12042 Node: Input/Output\7f18655
12043 Node: Legacy\7f20254
12044 Node: System\7f21096
12045 Node: About this manual\7f23588
12046 Node: Scheme Syntax Extension Packages\7f24145
12047 Node: Defmacro\7f24830
12048 Node: R4RS Macros\7f26781
12049 Node: Macro by Example\7f28036
12050 Node: Macros That Work\7f30913
12051 Node: Syntactic Closures\7f36971
12052 Node: Syntax-Case Macros\7f54405
12053 Node: Fluid-Let\7f58531
12054 Node: Yasos\7f59472
12055 Node: Yasos terms\7f60265
12056 Node: Yasos interface\7f61289
12057 Node: Setters\7f63364
12058 Node: Yasos examples\7f66005
12059 Node: Textual Conversion Packages\7f68999
12060 Node: Precedence Parsing\7f69697
12061 Node: Precedence Parsing Overview\7f70360
12062 Ref: Precedence Parsing Overview-Footnote-1\7f72358
12063 Node: Ruleset Definition and Use\7f72561
12064 Node: Token definition\7f74942
12065 Node: Nud and Led Definition\7f77211
12066 Node: Grammar Rule Definition\7f79660
12067 Node: Format\7f87234
12068 Node: Format Interface\7f87482
12069 Node: Format Specification\7f89219
12070 Node: Standard Formatted I/O\7f99349
12071 Node: Standard Formatted Output\7f99915
12072 Node: Standard Formatted Input\7f109182
12073 Node: Programs and Arguments\7f115842
12074 Node: Getopt\7f116342
12075 Node: Command Line\7f122184
12076 Node: Parameter lists\7f125373
12077 Node: Getopt Parameter lists\7f129358
12078 Node: Filenames\7f133527
12079 Node: Batch\7f136757
12080 Node: HTML\7f144550
12081 Node: HTML Tables\7f155838
12082 Node: HTTP and CGI\7f166135
12083 Node: URI\7f171452
12084 Node: Printing Scheme\7f177162
12085 Node: Generic-Write\7f177550
12086 Node: Object-To-String\7f178953
12087 Node: Pretty-Print\7f179357
12088 Node: Time and Date\7f184343
12089 Node: Time Zone\7f185370
12090 Node: Posix Time\7f189931
12091 Node: Common-Lisp Time\7f192067
12092 Node: Vector Graphics\7f193646
12093 Node: Tektronix Graphics Support\7f193835
12094 Node: Schmooz\7f195209
12095 Node: Mathematical Packages\7f199435
12096 Node: Bit-Twiddling\7f200069
12097 Node: Modular Arithmetic\7f204660
12098 Node: Prime Numbers\7f206794
12099 Node: Random Numbers\7f208477
12100 Node: Fast Fourier Transform\7f213113
12101 Node: Cyclic Checksum\7f214031
12102 Node: Plotting\7f216292
12103 Node: Root Finding\7f219151
12104 Node: Minimizing\7f223138
12105 Ref: Minimizing-Footnote-1\7f208597
12106 Node: Commutative Rings\7f225178
12107 Node: Determinant\7f236562
12108 Node: Database Packages\7f237120
12109 Node: Base Table\7f237384
12110 Node: Relational Database\7f247798
12111 Node: Motivations\7f248582
12112 Node: Creating and Opening Relational Databases\7f253629
12113 Node: Relational Database Operations\7f256061
12114 Node: Table Operations\7f259258
12115 Node: Catalog Representation\7f267136
12116 Node: Unresolved Issues\7f270034
12117 Node: Database Utilities\7f272985
12118 Node: Database Reports\7f289598
12119 Node: Database Browser\7f292352
12120 Node: Weight-Balanced Trees\7f293413
12121 Node: Construction of Weight-Balanced Trees\7f297284
12122 Node: Basic Operations on Weight-Balanced Trees\7f300734
12123 Node: Advanced Operations on Weight-Balanced Trees\7f303699
12124 Node: Indexing Operations on Weight-Balanced Trees\7f309721
12125 Node: Other Packages\7f313635
12126 Node: Data Structures\7f314034
12127 Node: Arrays\7f314790
12128 Node: Array Mapping\7f317744
12129 Node: Association Lists\7f319661
12130 Node: Byte\7f321912
12131 Node: Portable Image Files\7f324152
12132 Node: Collections\7f325699
12133 Node: Dynamic Data Type\7f331817
12134 Node: Hash Tables\7f333078
12135 Node: Hashing\7f335195
12136 Node: Object\7f339989
12137 Node: Priority Queues\7f348225
12138 Node: Queues\7f349068
12139 Node: Records\7f350194
12140 Node: Structures\7f353705
12141 Node: Procedures\7f355005
12142 Node: Common List Functions\7f355852
12143 Node: List construction\7f356276
12144 Node: Lists as sets\7f357939
12145 Node: Lists as sequences\7f365060
12146 Node: Destructive list operations\7f370366
12147 Node: Non-List functions\7f373029
12148 Node: Tree Operations\7f374174
12149 Node: Type Coercion\7f375796
12150 Node: Chapter Ordering\7f377022
12151 Node: Sorting\7f378719
12152 Node: Topological Sort\7f384496
12153 Node: String-Case\7f386183
12154 Node: String Ports\7f387284
12155 Node: String Search\7f388048
12156 Node: Line I/O\7f390415
12157 Node: Multi-Processing\7f392065
12158 Node: Metric Units\7f393248
12159 Node: Standards Support\7f408689
12160 Node: With-File\7f409423
12161 Node: Transcripts\7f409699
12162 Node: Rev2 Procedures\7f410020
12163 Node: Rev4 Optional Procedures\7f411727
12164 Node: Multi-argument / and -\7f412297
12165 Node: Multi-argument Apply\7f412948
12166 Node: Rationalize\7f413434
12167 Node: Promises\7f414876
12168 Node: Dynamic-Wind\7f415293
12169 Node: Eval\7f416547
12170 Node: Values\7f419884
12171 Node: Session Support\7f420671
12172 Node: Repl\7f421139
12173 Node: Quick Print\7f422422
12174 Node: Debug\7f423535
12175 Node: Breakpoints\7f424421
12176 Node: Trace\7f426444
12177 Node: System Interface\7f429555
12178 Node: Extra-SLIB Packages\7f433443
12179 Node: About SLIB\7f435743
12180 Node: Installation\7f436407
12181 Node: Porting\7f439635
12182 Ref: Porting-Footnote-1\7f413781
12183 Node: Coding Guidelines\7f441153
12184 Node: Copyrights\7f443234
12185 Node: Index\7f446519
12186 \1f
12187 End Tag Table