1.1 Manual (Pdf)
Total Page:16
File Type:pdf, Size:1020Kb
The Incomplete Scheme 48 Reference Manual for release 1.1 Richard Kelsey Jonathan Rees Mike Sperber A line may take us hours, yet if it does not seem a moment’s thought All our stitching and unstitching has been as nought. Yeats Adam’s Curse ii Acknowledgements Thanks to Scheme 48’s users for their suggestions, bug reports, and forbearance. Thanks also to Deborah Tatar for providing the Yeats quotation. iii Contents 1 Introduction 1 2 User’s guide 2 2.1 Command line arguments . 2 2.2 Command processor . 3 2.3 Editing . 3 2.4 Performance . 3 2.5 Disassembler . 4 2.6 Module system . 4 2.7 Library . 5 3 Command processor 7 3.1 Current focus value and ## .......................... 7 3.2 Command levels . 8 3.3 Logistical commands . 8 3.4 Module commands . 9 3.5 Debugging commands . 9 3.6 Switches . 10 3.7 Inspection mode . 12 3.8 Command programs . 13 3.9 Building images . 14 3.10 Resource query and control . 14 3.11 Threads . 15 3.12 Quite obscure . 16 4 Module system 17 4.1 Introduction . 17 4.2 The configuration language . 18 4.3 Interfaces . 20 4.4 Macros . 21 4.5 Higher-order modules . 21 4.6 Compiling and linking . 21 4.7 Semantics of configuration mutation . 22 4.8 Command processor support . 23 4.9 Configuration packages . 25 4.10 Discussion . 27 iv 5 Libraries 29 5.1 General utilities . 29 5.2 Pretty-printing . 30 5.3 ASCII character encoding . 31 5.4 Bitwise integer operations . 31 5.5 Byte vectors . 31 5.6 Sparse vectors . 32 5.7 Cells . 32 5.8 Queues . 32 5.9 Arrays . 33 5.10 Records . 34 5.10.1 Low-level access to records . 35 5.10.2 Record types . 36 5.11 Finite record types . 37 5.12 Sets over finite types . 38 5.13 Hash tables . 39 5.14 Port extensions . 40 5.15 Fluid bindings . 41 5.16 Shell commands . 42 5.17 Sockets . 43 5.18 Macros for writing loops . 44 5.18.1 Iterate ................................. 44 5.18.2 Reduce ................................. 45 5.18.3 Sequence types . 45 5.18.4 Synchronous sequences . 46 5.18.5 Examples . 47 5.18.6 Defining sequence types . 48 5.18.7 Expanded code . 48 5.19 Sorting lists and vectors . 49 5.19.1 Design rules . 49 5.19.2 Procedure specification . 52 5.19.3 Algorithmic properties . 59 5.20 Regular expressions . 60 5.20.1 Character sets . 60 5.20.2 Anchoring . 61 5.20.3 Composite expressions . 61 5.20.4 Case sensitivity . 61 5.20.5 Submatches and matching . 62 5.21 SRFIs . 63 6 Threads 66 6.1 Creating and controlling threads . 66 6.2 Advanced thread handling . 67 6.3 Debugging multithreaded programs . 67 6.4 Optimistic concurrency . 67 6.5 Condition variables . 70 6.6 Mutual exclusion . 71 v 6.6.1 Locks . 71 6.6.2 Placeholders . 72 6.7 Writing custom synchronization abstractions . 72 7 Mixing Scheme 48 and C 74 7.1 Available facilities . 74 7.1.1 Scheme structures . 74 7.1.2 C naming conventions . 74 7.1.3 Garbage collection . 75 7.2 Shared bindings . 75 7.2.1 Exporting Scheme values to C . 75 7.2.2 Exporting C values to Scheme . 75 7.2.3 Complete shared binding interface . 76 7.3 Calling C functions from Scheme . 77 7.4 Adding external modules to the Makefile . 77 7.5 Dynamic loading . 78 7.6 Compatibility . 79 7.7 Accessing Scheme data from C . 79 7.7.1 Constants . 79 7.7.2 Converting values . 79 7.7.3 C versions of Scheme procedures . 80 7.8 Calling Scheme functions from C . 81 7.9 Interacting with the Scheme heap . 82 7.9.1 Registering objects with the GC . 82 7.9.2 Keeping C data structures in the Scheme heap . 82 7.9.3 C code and heap images . 83 7.10 Using Scheme records in C code . 83 7.11 Raising exceptions from external code . 84 7.12 Unsafe functions and macros . 85 8 Access to POSIX 87 8.1 Process primitives . 87 8.1.1 Process creation and termination . 87 8.1.2 Exec ................................... 88 8.2 Signals . 89 8.2.1 POSIX signals . 89 8.2.2 Other signals . 90 8.2.3 Sending signals . 91.