summaryrefslogtreecommitdiffstats
path: root/slib.info-1
blob: 89c4fce1501a861e29bae9eac6d7aed868aaf48a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
This is Info file slib.info, produced by Makeinfo-1.64 from the input
file slib.texi.

  This file documents SLIB, the portable Scheme library.

  Copyright (C) 1993 Todd R. Eigenschink Copyright (C) 1993, 1994, 1995
Aubrey Jaffer

  Permission is granted to make and distribute verbatim copies of this
manual provided the copyright notice and this permission notice are
preserved on all copies.

  Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided that the
entire resulting derived work is distributed under the terms of a
permission notice identical to this one.

  Permission is granted to copy and distribute translations of this
manual into another language, under the above conditions for modified
versions, except that this permission notice may be stated in a
translation approved by the author.


File: slib.info,  Node: Top,  Next: Overview,  Prev: (dir),  Up: (dir)

  This file documents SLIB, the portable Scheme library.

Good Engineering is 1% inspiration and 99% documentation.
=========================================================

  Herein lies the good part.  Many thanks to Todd Eigenschink
<eigenstr@CS.Rose-Hulman.Edu> (who thanks Dave Love <D.Love@dl.ac.uk>)
for creating `slib.texi'.  I have learned much from their example.

  Aubrey Jaffer jaffer@ai.mit.edu

* Menu:

* Overview::                    What is SLIB?

* Data Structures::             Various data structures.
* Macros::                      Extensions to Scheme syntax.
* Numerics::
* Procedures::                  Miscellaneous utility procedures.
* Standards Support::           Support for Scheme Standards.
* Session Support::             Debugging, Pathnames, Require, etc.

* Optional SLIB Packages::
* Procedure and Macro Index::
* Variable Index::


File: slib.info,  Node: Overview,  Next: Data Structures,  Prev: Top,  Up: Top

Overview
********

  SLIB is a portable Scheme library meant to provide compatibility and
utility functions for all standard Scheme implementations, and fixes
several implementations which are non-conforming.  SLIB conforms to
`Revised^4 Report on the Algorithmic Language Scheme' and the IEEE
P1178 specification.  SLIB supports Unix and similar systems, VMS, and
MS-DOS.

  For a summary of what each file contains, see the file `README'.  For
a list of the features that have changed since the last SLIB release,
see the file `ANNOUNCE'.  For a list of the features that have changed
over time, see the file `ChangeLog'.

  The maintainer can be reached as `jaffer@ai.mit.edu'.

* Menu:

* Installation::                How to install SLIB on your system.
* Porting::                     SLIB to new platforms
* Coding Standards::            How to write modules for SLIB.
* Copyrights::                  Intellectual propery issues.
* Manual Conventions::          Conventions used in this manual.


File: slib.info,  Node: Installation,  Next: Porting,  Prev: Overview,  Up: Overview

Installation
============

  Check the manifest in `README' to find a configuration file for your
Scheme implementation.  Initialization files for most IEEE P1178
compliant Scheme Implementations are included with this distribution.

  If the Scheme implementation supports `getenv', then the value of the
shell environment variable SCHEME_LIBRARY_PATH will be used for
`(library-vicinity)' if it is defined.  Currently, Chez, Elk,
MITScheme, scheme->c, VSCM, and SCM support `getenv'.

  You should check the definitions of `software-type',
`scheme-implementation-version', `implementation-vicinity', and
`library-vicinity' in the initialization file.  There are comments in
the file for how to configure it.

  Once this is done you can modify the startup file for your Scheme
implementation to `load' this initialization file.  SLIB is then
installed.

  Multiple implementations of Scheme can all use the same SLIB
directory.  Simply configure each implementation's initialization file
as outlined above.

  The SCM implementation does not require any initialization file as
SLIB support is already built in to SCM.  See the documentation with
SCM for installation instructions.

  SLIB includes methods to create heap images for the VSCM and Scheme48
implementations.  The instructions for creating a VSCM image are in
comments in `vscm.init'.  To make a Scheme48 image, `cd' to the SLIB
directory and type `make slib48'.  This will also create a shell script
with the name `slib48' which will invoke the saved image.


File: slib.info,  Node: Porting,  Next: Coding Standards,  Prev: Installation,  Up: Overview

Porting
=======

  If there is no initialization file for your Scheme implementation, you
will have to create one.  Your Scheme implementation must be largely
compliant with `IEEE Std 1178-1990' or `Revised^4 Report on the
Algorithmic Language Scheme' to support SLIB.

  `Template.scm' is an example configuration file.  The comments inside
will direct you on how to customize it to reflect your system.  Give
your new initialization file the implementation's name with `.init'
appended.  For instance, if you were porting `foo-scheme' then the
initialization file might be called `foo.init'.

  Your customized version should then be loaded as part of your scheme
implementation's initialization.  It will load `require.scm' (*Note
Require::) from the library; this will allow the use of `provide',
`provided?', and `require' along with the "vicinity" functions
(`vicinity' functions are documented in the section on Require.  *Note
Require::).  The rest of the library will then be accessible in a
system independent fashion.

  Please mail new working configuration files to `jaffer@ai.mit.edu' so
that they can be included in the SLIB distribution.


File: slib.info,  Node: Coding Standards,  Next: Copyrights,  Prev: Porting,  Up: Overview

Coding Standards
================

  All library packages are written in IEEE P1178 Scheme and assume that
a configuration file and `require.scm' package have already been
loaded.  Other versions of Scheme can be supported in library packages
as well by using, for example, `(provided? 'rev3-report)' or `(require
'rev3-report)' (*Note Require::).

  `require.scm' defines `*catalog*', an association list of module
names and filenames.  When a new package is added to the library, an
entry should be added to `require.scm'.  Local packages can also be
added to `*catalog*' and even shadow entries already in the table.

  The module name and `:' should prefix each symbol defined in the
package.  Definitions for external use should then be exported by having
`(define foo module-name:foo)'.

  Submitted code should not duplicate routines which are already in SLIB
files.  Use `require' to force those features to be supported in your
package.  Care should be taken that there are no circularities in the
`require's and `load's between the library packages.

  Documentation should be provided in Emacs Texinfo format if possible,
But documentation must be provided.

  Your package will be released sooner with SLIB if you send me a file
which tests your code.  Please run this test *before* you send me the
code!

Modifications
-------------

  Please document your changes.  A line or two for `ChangeLog' is
sufficient for simple fixes or extensions.  Look at the format of
`ChangeLog' to see what information is desired.  Please send me `diff'
files from the latest SLIB distribution (remember to send `diff's of
`slib.texi' and `ChangeLog').  This makes for less email traffic and
makes it easier for me to integrate when more than one person is
changing a file (this happens a lot with `slib.texi' and `*.init'
files).

  If someone else wrote a package you want to significantly modify,
please try to contact the author, who may be working on a new version.
This will insure against wasting effort on obsolete versions.

  Please *do not* reformat the source code with your favorite
beautifier, make 10 fixes, and send me the resulting source code.  I do
not have the time to fish through 10000 diffs to find your 10 real
fixes.


File: slib.info,  Node: Copyrights,  Next: Manual Conventions,  Prev: Coding Standards,  Up: Overview

Copyrights
==========

  This section has instructions for SLIB authors regarding copyrights.

  Each package in SLIB must either be in the public domain, or come
with a statement of terms permitting users to copy, redistribute and
modify it.  The comments at the beginning of `require.scm' and
`macwork.scm' illustrate copyright and appropriate terms.

  If your code or changes amount to less than about 10 lines, you do not
need to add your copyright or send a disclaimer.

Putting code into the Public Domain
-----------------------------------

  In order to put code in the public domain you should sign a copyright
disclaimer and send it to the SLIB maintainer.  Contact
jaffer@ai.mit.edu for the address to mail the disclaimer to.

     I, NAME, hereby affirm that I have placed the software package
     NAME in the public domain.

     I affirm that I am the sole author and sole copyright holder for
     the software package, that I have the right to place this software
     package in the public domain, and that I will do nothing to
     undermine this status in the future.

                                                     SIGNATURE AND DATE

  This wording assumes that you are the sole author.  If you are not the
sole author, the wording needs to be different.  If you don't want to be
bothered with sending a letter every time you release or modify a
module, make your letter say that it also applies to your future
revisions of that module.

  Make sure no employer has any claim to the copyright on the work you
are submitting.  If there is any doubt, create a copyright disclaimer
and have your employer sign it.  Mail the signed disclaimer to the SLIB
maintainer.  Contact jaffer@ai.mit.edu for the address to mail the
disclaimer to.  An example disclaimer follows.

Explicit copying terms
----------------------

If you submit more than about 10 lines of code which you are not placing
into the Public Domain (by sending me a disclaimer) you need to:

   * Arrange that your name appears in a copyright line for the
     appropriate year.   Multiple copyright lines are acceptable.

   * With your copyright line, specify any terms you require to be
     different from those already in the file.

   * Make sure no employer has any claim to the copyright on the work
     you are submitting.  If there is any doubt, create a copyright
     disclaimer and have your employer sign it.  Mail the signed
     disclaim to the SLIB maintainer.  Contact jaffer@ai.mit.edu for
     the address to mail the disclaimer to.

Example: Company Copyright Disclaimer
-------------------------------------

  This disclaimer should be signed by a vice president or general
manager of the company.  If you can't get at them, anyone else
authorized to license out software produced there will do.  Here is a
sample wording:

     EMPLOYER Corporation hereby disclaims all copyright interest in
     the program PROGRAM written by NAME.

     EMPLOYER Corporation affirms that it has no other intellectual
     property interest that would undermine this release, and will do
     nothing to undermine it in the future.

     SIGNATURE AND DATE,
     NAME, TITLE, EMPLOYER Corporation


File: slib.info,  Node: Manual Conventions,  Prev: Copyrights,  Up: Overview

Manual Conventions
==================

  Things that are labeled as Functions are called for their return
values.  Things that are labeled as Procedures are called primarily for
their side effects.

  All examples throughout this text were produced using the `scm'
Scheme implementation.

  At the beginning of each section, there is a line that looks something
like

  `(require 'feature)'.

This means that, in order to use `feature', you must include the line
`(require 'feature)' somewhere in your code prior to the use of that
feature.  `require' will make sure that the feature is loaded.


File: slib.info,  Node: Data Structures,  Next: Macros,  Prev: Overview,  Up: Top

Data Structures
***************

* Menu:

* Arrays::                      'array
* Array Mapping::               'array-for-each
* Association Lists::           'alist
* Collections::                 'collect
* Dynamic Data Type::           'dynamic
* Hash Tables::                 'hash-table
* Hashing::                     'hash, 'sierpinski, 'soundex
* Chapter Ordering::            'chapter-order
* Object::                      'object
* Parameter lists::             'parameters
* Priority Queues::             'priority-queue
* Queues::                      'queue
* Records::                     'record
* Base Table::
* Relational Database::         'relational-database
* Weight-Balanced Trees::       'wt-tree
* Structures::                  'struct, 'structure


File: slib.info,  Node: Arrays,  Next: Array Mapping,  Prev: Data Structures,  Up: Data Structures

Arrays
======

  `(require 'array)'

 - Function: array? OBJ
     Returns `#t' if the OBJ is an array, and `#f' if not.

 - Function: make-array INITIAL-VALUE BOUND1 BOUND2 ...
     Creates and returns an array that has as many dimensins as there
     are BOUNDs and fills it with INITIAL-VALUE.

  When constructing an array, BOUND is either an inclusive range of
indices expressed as a two element list, or an upper bound expressed as
a single integer.  So
     (make-array 'foo 3 3) == (make-array 'foo '(0 2) '(0 2))

 - Function: make-shared-array ARRAY MAPPER BOUND1 BOUND2 ...
     `make-shared-array' can be used to create shared subarrays of other
     arrays.  The MAPPER is a function that translates coordinates in
     the new array into coordinates in the old array.  A MAPPER must be
     linear, and its range must stay within the bounds of the old
     array, but it can be otherwise arbitrary.  A simple example:
          (define fred (make-array #f 8 8))
          (define freds-diagonal
            (make-shared-array fred (lambda (i) (list i i)) 8))
          (array-set! freds-diagonal 'foo 3)
          (array-ref fred 3 3)
             => FOO
          (define freds-center
            (make-shared-array fred (lambda (i j) (list (+ 3 i) (+ 3 j)))
                               2 2))
          (array-ref freds-center 0 0)
             => FOO

 - Function: array-rank OBJ
     Returns the number of dimensions of OBJ.  If OBJ is not an array,
     0 is returned.

 - Function: array-shape ARRAY
     `array-shape' returns a list of inclusive bounds.  So:
          (array-shape (make-array 'foo 3 5))
             => ((0 2) (0 4))

 - Function: array-dimensions ARRAY
     `array-dimensions' is similar to `array-shape' but replaces
     elements with a 0 minimum with one greater than the maximum. So:
          (array-dimensions (make-array 'foo 3 5))
             => (3 5)

 - Procedure: array-in-bounds? ARRAY INDEX1 INDEX2 ...
     Returns `#t' if its arguments would be acceptable to `array-ref'.

 - Function: array-ref ARRAY INDEX1 INDEX2 ...
     Returns the element at the `(INDEX1, INDEX2)' element in ARRAY.

 - Procedure: array-set! ARRAY NEW-VALUE INDEX1 INDEX2 ...

 - Function: array-1d-ref ARRAY INDEX
 - Function: array-2d-ref ARRAY INDEX INDEX
 - Function: array-3d-ref ARRAY INDEX INDEX INDEX

 - Procedure: array-1d-set! ARRAY NEW-VALUE INDEX
 - Procedure: array-2d-set! ARRAY NEW-VALUE INDEX INDEX
 - Procedure: array-3d-set! ARRAY NEW-VALUE INDEX INDEX INDEX

  The functions are just fast versions of `array-ref' and `array-set!'
that take a fixed number of arguments, and perform no bounds checking.

  If you comment out the bounds checking code, this is about as
efficient as you could ask for without help from the compiler.

  An exercise left to the reader: implement the rest of APL.


File: slib.info,  Node: Array Mapping,  Next: Association Lists,  Prev: Arrays,  Up: Data Structures

Array Mapping
=============

  `(require 'array-for-each)'

 - Function: array-map! ARRAY0 PROC ARRAY1 ...
     ARRAY1, ... must have the same number of dimensions as ARRAY0 and
     have a range for each index which includes the range for the
     corresponding index in ARRAY0.  PROC is applied to each tuple of
     elements of ARRAY1 ... and the result is stored as the
     corresponding element in ARRAY0.  The value returned is
     unspecified.  The order of application is unspecified.

 - Function: array-for-each PROC ARRAY0 ...
     PROC is applied to each tuple of elements of ARRAY0 ...  in
     row-major order.  The value returned is unspecified.

 - Function: array-indexes ARRAY
     Returns an array of lists of indexes for ARRAY such that, if LI is
     a list of indexes for which ARRAY is defined, (equal?  LI (apply
     array-ref (array-indexes ARRAY) LI)).

 - Function: array-copy! SOURCE DESTINATION
     Copies every element from vector or array SOURCE to the
     corresponding element of DESTINATION.  DESTINATION must have the
     same rank as SOURCE, and be at least as large in each dimension.
     The order of copying is unspecified.


File: slib.info,  Node: Association Lists,  Next: Collections,  Prev: Array Mapping,  Up: Data Structures

Association Lists
=================

  `(require 'alist)'

  Alist functions provide utilities for treating a list of key-value
pairs as an associative database.  These functions take an equality
predicate, PRED, as an argument.  This predicate should be repeatable,
symmetric, and transitive.

  Alist functions can be used with a secondary index method such as hash
tables for improved performance.

 - Function: predicate->asso PRED
     Returns an "association function" (like `assq', `assv', or
     `assoc') corresponding to PRED.  The returned function returns a
     key-value pair whose key is `pred'-equal to its first argument or
     `#f' if no key in the alist is PRED-equal to the first argument.

 - Function: alist-inquirer PRED
     Returns a procedure of 2 arguments, ALIST and KEY, which returns
     the value associated with KEY in ALIST or `#f' if KEY does not
     appear in ALIST.

 - Function: alist-associator PRED
     Returns a procedure of 3 arguments, ALIST, KEY, and VALUE, which
     returns an alist with KEY and VALUE associated.  Any previous
     value associated with KEY will be lost.  This returned procedure
     may or may not have side effects on its ALIST argument.  An
     example of correct usage is:
          (define put (alist-associator string-ci=?))
          (define alist '())
          (set! alist (put alist "Foo" 9))

 - Function: alist-remover PRED
     Returns a procedure of 2 arguments, ALIST and KEY, which returns
     an alist with an association whose KEY is key removed.  This
     returned procedure may or may not have side effects on its ALIST
     argument.  An example of correct usage is:
          (define rem (alist-remover string-ci=?))
          (set! alist (rem alist "foo"))

 - Function: alist-map PROC ALIST
     Returns a new association list formed by mapping PROC over the
     keys and values of ALIST.   PROC must be a function of 2 arguments
     which returns the new value part.

 - Function: alist-for-each PROC ALIST
     Applies PROC to each pair of keys and values of ALIST.  PROC must
     be a function of 2 arguments.  The returned value is unspecified.


File: slib.info,  Node: Collections,  Next: Dynamic Data Type,  Prev: Association Lists,  Up: Data Structures

Collections
===========

  `(require 'collect)'

  Routines for managing collections.  Collections are aggregate data
structures supporting iteration over their elements, similar to the
Dylan(TM) language, but with a different interface.  They have
"elements" indexed by corresponding "keys", although the keys may be
implicit (as with lists).

  New types of collections may be defined as YASOS objects (*Note
Yasos::).  They must support the following operations:
   * `(collection? SELF)' (always returns `#t');

   * `(size SELF)' returns the number of elements in the collection;

   * `(print SELF PORT)' is a specialized print operation for the
     collection which prints a suitable representation on the given
     PORT or returns it as a string if PORT is `#t';

   * `(gen-elts SELF)' returns a thunk which on successive invocations
     yields elements of SELF in order or gives an error if it is
     invoked more than `(size SELF)' times;

   * `(gen-keys SELF)' is like `gen-elts', but yields the collection's
     keys in order.

  They might support specialized `for-each-key' and `for-each-elt'
operations.

 - Function: collection? OBJ
     A predicate, true initially of lists, vectors and strings.  New
     sorts of collections must answer `#t' to `collection?'.

 - Procedure: map-elts PROC . COLLECTIONS
 - Procedure: do-elts PROC . COLLECTIONS
     PROC is a procedure taking as many arguments as there are
     COLLECTIONS (at least one).  The COLLECTIONS are iterated over in
     their natural order and PROC is applied to the elements yielded by
     each iteration in turn.  The order in which the arguments are
     supplied corresponds to te order in which the COLLECTIONS appear.
     `do-elts' is used when only side-effects of PROC are of interest
     and its return value is unspecified.  `map-elts' returns a
     collection (actually a vector) of the results of the applications
     of PROC.

     Example:
          (map-elts + (list 1 2 3) (vector 1 2 3))
             => #(2 4 6)

 - Procedure: map-keys PROC . COLLECTIONS
 - Procedure: do-keys PROC . COLLECTIONS
     These are analogous to `map-elts' and `do-elts', but each
     iteration is over the COLLECTIONS' *keys* rather than their
     elements.

     Example:
          (map-keys + (list 1 2 3) (vector 1 2 3))
             => #(0 2 4)

 - Procedure: for-each-key COLLECTION PROC
 - Procedure: for-each-elt COLLECTION PROC
     These are like `do-keys' and `do-elts' but only for a single
     collection; they are potentially more efficient.

 - Function: reduce PROC SEED . COLLECTIONS
     A generalization of the list-based `comlist:reduce-init' (*Note
     Lists as sequences::) to collections which will shadow the
     list-based version if `(require 'collect)' follows `(require
     'common-list-functions)' (*Note Common List Functions::).

     Examples:
          (reduce + 0 (vector 1 2 3))
             => 6
          (reduce union '() '((a b c) (b c d) (d a)))
             => (c b d a).

 - Function: any? PRED . COLLECTIONS
     A generalization of the list-based `some' (*Note Lists as
     sequences::) to collections.

     Example:
          (any? odd? (list 2 3 4 5))
             => #t

 - Function: every? PRED . COLLECTIONS
     A generalization of the list-based `every' (*Note Lists as
     sequences::) to collections.

     Example:
          (every? collection? '((1 2) #(1 2)))
             => #t

 - Function: empty? COLLECTION
     Returns `#t' iff there are no elements in COLLECTION.

     `(empty? COLLECTION) == (zero? (size COLLECTION))'

 - Function: size COLLECTION
     Returns the number of elements in COLLECTION.

 - Function: Setter LIST-REF
     See *Note Setters:: for a definition of "setter".  N.B.  `(setter
     list-ref)' doesn't work properly for element 0 of a list.

  Here is a sample collection: `simple-table' which is also a `table'.
     (define-predicate TABLE?)
     (define-operation (LOOKUP table key failure-object))
     (define-operation (ASSOCIATE! table key value)) ;; returns key
     (define-operation (REMOVE! table key))          ;; returns value
     
     (define (MAKE-SIMPLE-TABLE)
       (let ( (table (list)) )
         (object
          ;; table behaviors
          ((TABLE? self) #t)
          ((SIZE self) (size table))
          ((PRINT self port) (format port "#<SIMPLE-TABLE>"))
          ((LOOKUP self key failure-object)
           (cond
            ((assq key table) => cdr)
            (else failure-object)
            ))
          ((ASSOCIATE! self key value)
           (cond
            ((assq key table)
             => (lambda (bucket) (set-cdr! bucket value) key))
            (else
             (set! table (cons (cons key value) table))
             key)
            ))
          ((REMOVE! self key);; returns old value
           (cond
            ((null? table) (slib:error "TABLE:REMOVE! Key not found: " key))
            ((eq? key (caar table))
             (let ( (value (cdar table)) )
               (set! table (cdr table))
               value)
             )
            (else
             (let loop ( (last table) (this (cdr table)) )
               (cond
                ((null? this)
                 (slib:error "TABLE:REMOVE! Key not found: " key))
                ((eq? key (caar this))
                 (let ( (value (cdar this)) )
                   (set-cdr! last (cdr this))
                   value)
                 )
                (else
                 (loop (cdr last) (cdr this)))
                ) ) )
            ))
          ;; collection behaviors
          ((COLLECTION? self) #t)
          ((GEN-KEYS self) (collect:list-gen-elts (map car table)))
          ((GEN-ELTS self) (collect:list-gen-elts (map cdr table)))
          ((FOR-EACH-KEY self proc)
           (for-each (lambda (bucket) (proc (car bucket))) table)
           )
          ((FOR-EACH-ELT self proc)
           (for-each (lambda (bucket) (proc (cdr bucket))) table)
           )
          ) ) )


File: slib.info,  Node: Dynamic Data Type,  Next: Hash Tables,  Prev: Collections,  Up: Data Structures

Dynamic Data Type
=================

  `(require 'dynamic)'

 - Function: make-dynamic OBJ
     Create and returns a new "dynamic" whose global value is OBJ.

 - Function: dynamic? OBJ
     Returns true if and only if OBJ is a dynamic.  No object
     satisfying `dynamic?' satisfies any of the other standard type
     predicates.

 - Function: dynamic-ref DYN
     Return the value of the given dynamic in the current dynamic
     environment.

 - Procedure: dynamic-set! DYN OBJ
     Change the value of the given dynamic to OBJ in the current
     dynamic environment.  The returned value is unspecified.

 - Function: call-with-dynamic-binding DYN OBJ THUNK
     Invoke and return the value of the given thunk in a new, nested
     dynamic environment in which the given dynamic has been bound to a
     new location whose initial contents are the value OBJ.  This
     dynamic environment has precisely the same extent as the
     invocation of the thunk and is thus captured by continuations
     created within that invocation and re-established by those
     continuations when they are invoked.

  The `dynamic-bind' macro is not implemented.


File: slib.info,  Node: Hash Tables,  Next: Hashing,  Prev: Dynamic Data Type,  Up: Data Structures

Hash Tables
===========

  `(require 'hash-table)'

 - Function: predicate->hash PRED
     Returns a hash function (like `hashq', `hashv', or `hash')
     corresponding to the equality predicate PRED.  PRED should be
     `eq?', `eqv?', `equal?', `=', `char=?', `char-ci=?', `string=?', or
     `string-ci=?'.

  A hash table is a vector of association lists.

 - Function: make-hash-table K
     Returns a vector of K empty (association) lists.

  Hash table functions provide utilities for an associative database.
These functions take an equality predicate, PRED, as an argument.  PRED
should be `eq?', `eqv?', `equal?', `=', `char=?', `char-ci=?',
`string=?', or `string-ci=?'.

 - Function: predicate->hash-asso PRED
     Returns a hash association function of 2 arguments, KEY and
     HASHTAB, corresponding to PRED.  The returned function returns a
     key-value pair whose key is PRED-equal to its first argument or
     `#f' if no key in HASHTAB is PRED-equal to the first argument.

 - Function: hash-inquirer PRED
     Returns a procedure of 3 arguments, `hashtab' and `key', which
     returns the value associated with `key' in `hashtab' or `#f' if
     key does not appear in `hashtab'.

 - Function: hash-associator PRED
     Returns a procedure of 3 arguments, HASHTAB, KEY, and VALUE, which
     modifies HASHTAB so that KEY and VALUE associated.  Any previous
     value associated with KEY will be lost.

 - Function: hash-remover PRED
     Returns a procedure of 2 arguments, HASHTAB and KEY, which
     modifies HASHTAB so that the association whose key is KEY is
     removed.

 - Function: hash-map PROC HASH-TABLE
     Returns a new hash table formed by mapping PROC over the keys and
     values of HASH-TABLE.  PROC must be a function of 2 arguments
     which returns the new value part.

 - Function: hash-for-each PROC HASH-TABLE
     Applies PROC to each pair of keys and values of HASH-TABLE.  PROC
     must be a function of 2 arguments.  The returned value is
     unspecified.


File: slib.info,  Node: Hashing,  Next: Chapter Ordering,  Prev: Hash Tables,  Up: Data Structures

Hashing
=======

  `(require 'hash)'

  These hashing functions are for use in quickly classifying objects.
Hash tables use these functions.

 - Function: hashq OBJ K
 - Function: hashv OBJ K
 - Function: hash OBJ K
     Returns an exact non-negative integer less than K.  For each
     non-negative integer less than K there are arguments OBJ for which
     the hashing functions applied to OBJ and K returns that integer.

     For `hashq', `(eq? obj1 obj2)' implies `(= (hashq obj1 k) (hashq
     obj2))'.

     For `hashv', `(eqv? obj1 obj2)' implies `(= (hashv obj1 k) (hashv
     obj2))'.

     For `hash', `(equal? obj1 obj2)' implies `(= (hash obj1 k) (hash
     obj2))'.

     `hash', `hashv', and `hashq' return in time bounded by a constant.
     Notice that items having the same `hash' implies the items have
     the same `hashv' implies the items have the same `hashq'.

  `(require 'sierpinski)'

 - Function: make-sierpinski-indexer MAX-COORDINATE
     Returns a procedure (eg hash-function) of 2 numeric arguments which
     preserves *nearness* in its mapping from NxN to N.

     MAX-COORDINATE is the maximum coordinate (a positive integer) of a
     population of points.  The returned procedures is a function that
     takes the x and y coordinates of a point, (non-negative integers)
     and returns an integer corresponding to the relative position of
     that point along a Sierpinski curve.  (You can think of this as
     computing a (pseudo-) inverse of the Sierpinski spacefilling
     curve.)

     Example use: Make an indexer (hash-function) for integer points
     lying in square of integer grid points [0,99]x[0,99]:
          (define space-key (make-sierpinski-indexer 100))
     Now let's compute the index of some points:
          (space-key 24 78)               => 9206
          (space-key 23 80)               => 9172

     Note that locations (24, 78) and (23, 80) are near in index and
     therefore, because the Sierpinski spacefilling curve is
     continuous, we know they must also be near in the plane.  Nearness
     in the plane does not, however, necessarily correspond to nearness
     in index, although it *tends* to be so.

     Example applications:

          Sort points by Sierpinski index to get heuristic solution to
          *travelling salesman problem*.  For details of performance,
          see L. Platzman and J. Bartholdi, "Spacefilling curves and the
          Euclidean travelling salesman problem", JACM 36(4):719-737
          (October 1989) and references therein.


          Use Sierpinski index as key by which to store 2-dimensional
          data in a 1-dimensional data structure (such as a table).
          Then locations that are near each other in 2-d space will
          tend to be near each other in 1-d data structure; and
          locations that are near in 1-d data structure will be near in
          2-d space.  This can significantly speed retrieval from
          secondary storage because contiguous regions in the plane
          will tend to correspond to contiguous regions in secondary
          storage.  (This is a standard technique for managing CAD/CAM
          or geographic data.)


  `(require 'soundex)'

 - Function: soundex NAME
     Computes the *soundex* hash of NAME.  Returns a string of an
     initial letter and up to three digits between 0 and 6.  Soundex
     supposedly has the property that names that sound similar in normal
     English pronunciation tend to map to the same key.

     Soundex was a classic algorithm used for manual filing of personal
     records before the advent of computers.  It performs adequately for
     English names but has trouble with other nationalities.

     See Knuth, Vol. 3 `Sorting and searching', pp 391-2

     To manage unusual inputs, `soundex' omits all non-alphabetic
     characters.  Consequently, in this implementation:

          (soundex <string of blanks>)    => ""
          (soundex "")                    => ""

     Examples from Knuth:

          (map soundex '("Euler" "Gauss" "Hilbert" "Knuth"
                                 "Lloyd" "Lukasiewicz"))
                  => ("E460" "G200" "H416" "K530" "L300" "L222")
          
          (map soundex '("Ellery" "Ghosh" "Heilbronn" "Kant"
                                  "Ladd" "Lissajous"))
                  => ("E460" "G200" "H416" "K530" "L300" "L222")

     Some cases in which the algorithm fails (Knuth):

          (map soundex '("Rogers" "Rodgers"))     => ("R262" "R326")
          
          (map soundex '("Sinclair" "St. Clair")) => ("S524" "S324")
          
          (map soundex '("Tchebysheff" "Chebyshev")) => ("T212" "C121")


File: slib.info,  Node: Chapter Ordering,  Next: Object,  Prev: Hashing,  Up: Data Structures

Chapter Ordering
================

  `(require 'chapter-order)'

  The `chap:' functions deal with strings which are ordered like
chapter numbers (or letters) in a book.  Each section of the string
consists of consecutive numeric or consecutive aphabetic characters of
like case.

 - Function: chap:string<? STRING1 STRING2
     Returns #t if the first non-matching run of alphabetic upper-case
     or the first non-matching run of alphabetic lower-case or the first
     non-matching run of numeric characters of STRING1 is `string<?'
     than the corresponding non-matching run of characters of STRING2.

          (chap:string<? "a.9" "a.10")                    => #t
          (chap:string<? "4c" "4aa")                      => #t
          (chap:string<? "Revised^{3.99}" "Revised^{4}")  => #t

 - Function: chap:string>? STRING1 STRING2
 - Function: chap:string<=? STRING1 STRING2
 - Function: chap:string>=? STRING1 STRING2
     Implement the corresponding chapter-order predicates.

 - Function: chap:next-string STRING
     Returns the next string in the *chapter order*.  If STRING has no
     alphabetic or numeric characters, `(string-append STRING "0")' is
     returnd.  The argument to chap:next-string will always be
     `chap:string<?' than the result.

          (chap:next-string "a.9")                => "a.10"
          (chap:next-string "4c")                 => "4d"
          (chap:next-string "4z")                 => "4aa"
          (chap:next-string "Revised^{4}")        => "Revised^{5}"


File: slib.info,  Node: Object,  Next: Parameter lists,  Prev: Chapter Ordering,  Up: Data Structures

Macroless Object System
=======================

  `(require 'object)'

  This is the Macroless Object System written by Wade Humeniuk
(whumeniu@datap.ca).  Conceptual Tributes: *Note Yasos::, MacScheme's
%object, CLOS, Lack of R4RS macros.

Concepts
--------

OBJECT
     An object is an ordered association-list (by `eq?') of methods
     (procedures).  Methods can be added (`make-method!'), deleted
     (`unmake-method!') and retrieved (`get-method').  Objects may
     inherit methods from other objects.  The object binds to the
     environment it was created in, allowing closures to be used to
     hide private procedures and data.

GENERIC-METHOD
     A generic-method associates (in terms of `eq?') object's method.
     This allows scheme function style to be used for objects.  The
     calling scheme for using a generic method is `(generic-method
     object param1 param2 ...)'.

METHOD
     A method is a procedure that exists in the object.  To use a method
     get-method must be called to look-up the method.  Generic methods
     implement the get-method functionality.  Methods may be added to an
     object associated with any scheme obj in terms of eq?

GENERIC-PREDICATE
     A generic method that returns a boolean value for any scheme obj.

PREDICATE
     A object's method asscociated with a generic-predicate. Returns
     `#t'.

Procedures
----------

 - Function: make-object ANCESTOR ...
     Returns an object.  Current object implementation is a tagged
     vector.  ANCESTORs are optional and must be objects in terms of
     object?.  ANCESTORs methods are included in the object.  Multiple
     ANCESTORs might associate the same generic-method with a method.
     In this case the method of the ANCESTOR first appearing in the
     list is the one returned by `get-method'.

 - Function: object? OBJ
     Returns boolean value whether OBJ was created by make-object.

 - Function: make-generic-method EXCEPTION-PROCEDURE
     Returns a procedure which be associated with an object's methods.
     If EXCEPTION-PROCEDURE is specified then it is used to process
     non-objects.

 - Function: make-generic-predicate
     Returns a boolean procedure for any scheme object.

 - Function: make-method! OBJECT GENERIC-METHOD METHOD
     Associates METHOD to the GENERIC-METHOD in the object.  The METHOD
     overrides any previous association with the GENERIC-METHOD within
     the object.  Using `unmake-method!' will restore the object's
     previous association with the GENERIC-METHOD.  METHOD must be a
     procedure.

 - Function: make-predicate! OBJECT GENERIC-PRECIATE
     Makes a predicate method associated with the GENERIC-PREDICATE.

 - Function: unmake-method! OBJECT GENERIC-METHOD
     Removes an object's association with a GENERIC-METHOD .

 - Function: get-method OBJECT GENERIC-METHOD
     Returns the object's method associated (if any) with the
     GENERIC-METHOD.  If no associated method exists an error is
     flagged.

Examples
--------

     (require 'object)
     
     (define instantiate (make-generic-method))
     
     (define (make-instance-object . ancestors)
       (define self (apply make-object
                           (map (lambda (obj) (instantiate obj)) ancestors)))
       (make-method! self instantiate (lambda (self) self))
       self)
     
     (define who (make-generic-method))
     (define imigrate! (make-generic-method))
     (define emigrate! (make-generic-method))
     (define describe (make-generic-method))
     (define name (make-generic-method))
     (define address (make-generic-method))
     (define members (make-generic-method))
     
     (define society
       (let ()
         (define self (make-instance-object))
         (define population '())
         (make-method! self imigrate!
                       (lambda (new-person)
                         (if (not (eq? new-person self))
                             (set! population (cons new-person population)))))
         (make-method! self emigrate!
                       (lambda (person)
                         (if (not (eq? person self))
                             (set! population
                                   (comlist:remove-if (lambda (member)
                                                        (eq? member person))
                                                      population)))))
         (make-method! self describe
                       (lambda (self)
                         (map (lambda (person) (describe person)) population)))
         (make-method! self who
                       (lambda (self) (map (lambda (person) (name person))
                                           population)))
         (make-method! self members (lambda (self) population))
         self))
     
     (define (make-person %name %address)
       (define self (make-instance-object society))
       (make-method! self name (lambda (self) %name))
       (make-method! self address (lambda (self) %address))
       (make-method! self who (lambda (self) (name self)))
       (make-method! self instantiate
                     (lambda (self)
                       (make-person (string-append (name self) "-son-of")
                                    %address)))
       (make-method! self describe
                     (lambda (self) (list (name self) (address self))))
       (imigrate! self)
       self)

Inverter Documentation
......................

  Inheritance:
             <inverter>::(<number> <description>)
  Generic-methods
             <inverter>::value      => <number>::value
             <inverter>::set-value! => <number>::set-value!
             <inverter>::describe   => <description>::describe
             <inverter>::help
             <inverter>::invert
             <inverter>::inverter?

Number Documention
..................

  Inheritance
             <number>::()
  Slots
             <number>::<x>
  Generic Methods
             <number>::value
             <number>::set-value!

Inverter code
.............

     (require 'object)
     
     (define value (make-generic-method (lambda (val) val)))
     (define set-value! (make-generic-method))
     (define invert (make-generic-method
                     (lambda (val)
                       (if (number? val)
                           (/ 1 val)
                           (error "Method not supported:" val)))))
     (define noop (make-generic-method))
     (define inverter? (make-generic-predicate))
     (define describe (make-generic-method))
     (define help (make-generic-method))
     
     (define (make-number x)
       (define self (make-object))
       (make-method! self value (lambda (this) x))
       (make-method! self set-value!
                     (lambda (this new-value) (set! x new-value)))
       self)
     
     (define (make-description str)
       (define self (make-object))
       (make-method! self describe (lambda (this) str))
       (make-method! self help (lambda (this) "Help not available"))
       self)
     
     (define (make-inverter)
       (define self (make-object
                     (make-number 1)
                     (make-description "A number which can be inverted")))
       (define <value> (get-method self value))
       (make-method! self invert (lambda (self) (/ 1 (<value> self))))
       (make-predicate! self inverter?)
       (unmake-method! self help)
       (make-method! self help
                     (lambda (self)
                       (display "Inverter Methods:") (newline)
                       (display "  (value inverter) ==> n") (newline)))
       self)
     
     ;;;; Try it out
     
     (define invert! (make-generic-method))
     
     (define x (make-inverter))
     
     (make-method! x invert! (lambda () (set-value! x (/ 1 (value x)))))
     
     (value x)                       => 1
     (set-value! x 33)               => undefined
     (invert! x)                     => undefined
     (value x)                       => 1/33
     
     (unmake-method! x invert!)      => undefined
     
     (invert! x)                     error-->  ERROR: Method not supported: x


File: slib.info,  Node: Parameter lists,  Next: Priority Queues,  Prev: Object,  Up: Data Structures

Parameter lists
===============

  `(require 'parameters)'

Arguments to procedures in scheme are distinguished from each other by
their position in the procedure call.  This can be confusing when a
procedure takes many arguments, many of which are not often used.

A "parameter-list" is a way of passing named information to a
procedure.  Procedures are also defined to set unused parameters to
default values, check parameters, and combine parameter lists.

A PARAMETER has the form `(parameter-name value1 ...)'.  This format
allows for more than one value per parameter-name.

A PARAMETER-LIST is a list of PARAMETERs, each with a different
PARAMETER-NAME.

 - Function: make-parameter-list PARAMETER-NAMES
     Returns an empty parameter-list with slots for PARAMETER-NAMES.

 - Function: parameter-list-ref PARAMETER-LIST PARAMETER-NAME
     PARAMETER-NAME must name a valid slot of PARAMETER-LIST.
     `parameter-list-ref' returns the value of parameter PARAMETER-NAME
     of PARAMETER-LIST.

 - Procedure: adjoin-parameters! PARAMETER-LIST PARAMETER1 ...
     Returns PARAMETER-LIST with PARAMETER1 ... merged in.

 - Procedure: parameter-list-expand EXPANDERS PARAMETER-LIST
     EXPANDERS is a list of procedures whose order matches the order of
     the PARAMETER-NAMEs in the call to `make-parameter-list' which
     created PARAMETER-LIST.  For each non-false element of EXPANDERS
     that procedure is mapped over the corresponding parameter value
     and the returned parameter lists are merged into PARAMETER-LIST.

     This process is repeated until PARAMETER-LIST stops growing.  The
     value returned from `parameter-list-expand' is unspecified.

 - Function: fill-empty-parameters DEFAULTS PARAMETER-LIST
     DEFAULTS is a list of lists whose order matches the order of the
     PARAMETER-NAMEs in the call to `make-parameter-list' which created
     PARAMETER-LIST.  `fill-empty-parameters' returns a new
     parameter-list with each empty parameter filled with the
     corresponding DEFAULT.

 - Function: check-parameters CHECKS PARAMETER-LIST
     CHECKS is a list of procedures whose order matches the order of
     the PARAMETER-NAMEs in the call to `make-parameter-list' which
     created PARAMETER-LIST.

     `check-parameters' returns PARAMETER-LIST if each CHECK of the
     corresponding PARAMETER-LIST returns non-false.  If some CHECK
     returns `#f' an error is signaled.

In the following procedures ARITIES is a list of symbols.  The elements
of `arities' can be:

`single'
     Requires a single parameter.

`optional'
     A single parameter or no parameter is acceptable.

`boolean'
     A single boolean parameter or zero parameters is acceptable.

`nary'
     Any number of parameters are acceptable.

`nary1'
     One or more of parameters are acceptable.

 - Function: parameter-list->arglist POSITIONS ARITIES TYPES
          PARAMETER-LIST
     Returns PARAMETER-LIST converted to an argument list.  Parameters
     of ARITY type `single' and `boolean' are converted to the single
     value associated with them.  The other ARITY types are converted
     to lists of the value(s) of type TYPES.

     POSITIONS is a list of positive integers whose order matches the
     order of the PARAMETER-NAMEs in the call to `make-parameter-list'
     which created PARAMETER-LIST.  The integers specify in which
     argument position the corresponding parameter should appear.

 - Function: getopt->parameter-list ARGC ARGV OPTNAMES ARITIES TYPES
          ALIASES
     Returns ARGV converted to a parameter-list.  OPTNAMES are the
     parameter-names.  ALIASES is a list of lists of strings and
     elements of OPTNAMES.  Each of these strings which have length of
     1 will be treated as a single - option by `getopt'.  Longer
     strings will be treated as long-named options (*note getopt-:
     Getopt.).

 - Function: getopt->arglist ARGC ARGV OPTNAMES POSITIONS ARITIES TYPES
          DEFAULTS CHECKS ALIASES
     Like `getopt->parameter-list', but converts ARGV to an
     argument-list as specified by OPTNAMES, POSITIONS, ARITIES, TYPES,
     DEFAULTS, CHECKS, and ALIASES.

  These `getopt' functions can be used with SLIB relational databases.
For an example, *Note make-command-server: Database Utilities.


File: slib.info,  Node: Priority Queues,  Next: Queues,  Prev: Parameter lists,  Up: Data Structures

Priority Queues
===============

  `(require 'priority-queue)'

 - Function: make-heap PRED<?
     Returns a binary heap suitable which can be used for priority queue
     operations.

 - Function: heap-length HEAP
     Returns the number of elements in HEAP.

 - Procedure: heap-insert! HEAP ITEM
     Inserts ITEM into HEAP.  ITEM can be inserted multiple times.  The
     value returned is unspecified.

 - Function: heap-extract-max! HEAP
     Returns the item which is larger than all others according to the
     PRED<? argument to `make-heap'.  If there are no items in HEAP, an
     error is signaled.

  The algorithm for priority queues was taken from `Introduction to
Algorithms' by T. Cormen, C. Leiserson, R. Rivest.  1989 MIT Press.


File: slib.info,  Node: Queues,  Next: Records,  Prev: Priority Queues,  Up: Data Structures

Queues
======

  `(require 'queue)'

  A "queue" is a list where elements can be added to both the front and
rear, and removed from the front (i.e., they are what are often called
"dequeues").  A queue may also be used like a stack.

 - Function: make-queue
     Returns a new, empty queue.

 - Function: queue? OBJ
     Returns `#t' if OBJ is a queue.

 - Function: queue-empty? Q
     Returns `#t' if the queue Q is empty.

 - Procedure: queue-push! Q DATUM
     Adds DATUM to the front of queue Q.

 - Procedure: enquque! Q DATUM
     Adds DATUM to the rear of queue Q.

  All of the following functions raise an error if the queue Q is empty.

 - Function: queue-front Q
     Returns the datum at the front of the queue Q.

 - Function: queue-rear Q
     Returns the datum at the rear of the queue Q.

 - Prcoedure: queue-pop! Q
 - Procedure: dequeue! Q
     Both of these procedures remove and return the datum at the front
     of the queue.  `queue-pop!' is used to suggest that the queue is
     being used like a stack.