Chicken-Setup Reference Reference-Pg151 Reference-Sntsection 7.6
Total Page:16
File Type:pdf, Size:1020Kb
reference-titlechicken-setup reference reference-pg151 reference-sntSection 7.6 CHICKEN A practical and portable Scheme system User’s Manual Version 1 Build 62 Felix L. Winkelmann 1 Copyright c 2000-2004, Felix L. Winkelmann All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: • Redistributions of source code must retain the above copyright notice, this list of con- ditions and the following disclaimer. • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. • Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBU- TORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAM- AGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES LOSS OF USE, DATA, OR PROFITS OR BUSINESS INTER- RUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. i Table of Contents 1 Introduction ............................... 2 2 Basic mode of operation.................... 3 3 Using the compiler......................... 4 3.1 Command line format ................................... 4 3.2 Runtime options ....................................... 10 3.3 An example............................................ 11 3.4 Extending the compiler ................................. 13 3.5 Distributing compiled C files ............................ 14 4 Using the interpreter ..................... 15 4.1 Command line format .................................. 15 4.2 Writing Scheme scripts ................................. 16 4.3 Toplevel commands .................................... 18 4.4 Macros and procedures implemented in the interpreter .... 18 5 Supported language ....................... 21 5.1 Deviations from the standard ........................... 21 5.2 Extensions to the standard.............................. 22 5.3 Non standard read syntax............................... 24 5.4 Non-standard macros and special forms .................. 25 5.4.1 Making extra libraries and extensions available... 25 5.4.2 Binding forms for optional arguments ........... 26 5.4.3 Other binding forms ........................... 27 5.4.4 Substitution forms and macros.................. 28 5.4.5 Conditional forms ............................. 29 5.4.6 Record structures.............................. 30 5.4.7 Other forms ................................... 31 5.5 Declarations ........................................... 32 5.6 Parameters ............................................ 35 5.7 Unit library............................................ 36 5.7.1 Arithmetic .................................... 36 5.7.2 File Input/Output ............................. 38 5.7.3 Files .......................................... 38 5.7.4 String ports ................................... 39 5.7.5 Feature identifiers ............................. 39 5.7.6 Keywords ..................................... 40 5.7.7 Exceptions .................................... 40 5.7.8 Environment information and system interface ... 42 5.7.9 Execution time ................................ 44 5.7.10 Interrupts and error-handling .................. 44 ii 5.7.11 Garbage collection ............................ 45 5.7.12 Other control structures....................... 46 5.7.13 String utilities ................................ 46 5.7.14 Generating uninterned symbols ................ 46 5.7.15 Standard Input/Output ....................... 46 5.7.16 User-defined named characters................. 47 5.7.17 Vectors ...................................... 47 5.7.18 The unspecified value ......................... 47 5.7.19 call/cc ....................................... 48 5.8 Unit eval .............................................. 48 5.8.1 Loading code .................................. 48 5.8.2 Read-eval-print loop ........................... 49 5.8.3 Macros ....................................... 49 5.8.4 Loading extension libraries ..................... 50 5.8.5 Reader extensions ............................. 51 5.8.6 Eval .......................................... 51 5.9 Unit extras ............................................ 52 5.9.1 Lists.......................................... 52 5.9.2 String-port extensions.......................... 53 5.9.3 Formatted output ............................. 54 5.9.4 Hash tables ................................... 54 5.9.5 Queues ....................................... 55 5.9.6 Sorting ....................................... 56 5.9.7 Random numbers .............................. 57 5.9.8 Input/Output extensions ....................... 57 5.9.9 Strings........................................ 59 5.9.10 Combinators ................................. 60 5.9.11 Binary searching.............................. 62 5.10 Unit srfi-1 ............................................ 62 5.11 Unit srfi-4 ............................................ 62 5.12 Unit srfi-13 ........................................... 63 5.13 Unit srfi-14 ........................................... 64 5.14 Unit srfi-25 ........................................... 64 5.15 Unit match ........................................... 64 5.16 Unit regex ............................................ 65 5.17 Unit syntax-case ...................................... 67 5.18 Unit srfi-18 ........................................... 68 5.19 Unit format........................................... 69 5.20 Unit posix ............................................ 70 5.20.1 Directories ................................... 70 5.20.2 Pipes ........................................ 71 5.20.3 Fifos ........................................ 72 5.20.4 File descriptors and low-level I/O .............. 72 5.20.5 Retrieving file attributes ...................... 74 5.20.6 Changing file attributes ....................... 75 5.20.7 Processes .................................... 75 5.20.8 Symbolic links................................ 76 5.20.9 Permissions, owners, users and groups .......... 77 iii 5.20.10 Record locking .............................. 79 5.20.11 Signal handling.............................. 79 5.20.12 Environment access .......................... 80 5.20.13 Memory mapped I/O ........................ 81 5.20.14 Time routines ............................... 81 5.20.15 Raw exit.................................... 82 5.20.16 ERRNO values .............................. 82 5.20.17 Finding files................................. 83 5.20.18 Getting the hostname and system information.. 83 5.20.19 Setting a files buffering mode ................. 84 5.20.20 Terminal ports .............................. 84 5.20.21 How Scheme procedures relate to UNIX C functions ........................................ 84 5.21 Unit utils ............................................. 88 5.21.1 Pathname operations ......................... 88 5.21.2 Temporary files............................... 89 5.21.3 Deleting a file without signalling an error ....... 89 5.21.4 Iterating over input lines and files.............. 89 5.21.5 Executing shell commands with formatstring and error checking ................................... 90 5.21.6 Reading a file’s contents....................... 90 5.22 Unit tcp .............................................. 90 5.23 Unit srfi-37 ........................................... 92 5.24 Unit lolevel ........................................... 93 5.24.1 Foreign pointers .............................. 93 5.24.2 Tagged pointers .............................. 95 5.24.3 Extending procedures with data ............... 96 5.24.4 Bytevectors .................................. 96 5.24.5 Data in unmanaged memory................... 99 5.24.6 Locatives ................................... 100 5.24.7 Accessing toplevel variables .................. 101 5.24.8 Low-level data access ........................ 101 5.24.9 Procedure-call- and variable reference hooks ... 102 5.24.10 Magic ..................................... 103 5.25 Unit tinyclos......................................... 103 5.25.1 Defining forms .............................. 103 5.25.2 Base language ............................... 104 5.25.3 Introspection ................................ 105 5.25.4 Intercessory protocol......................... 106 5.25.5 Additional protocol .......................... 107 5.25.6 Utility procedures ........................... 107 5.25.7 Builtin classes ............................... 108 iv 6 Interface to external functions and variables ....................................... 112 6.1 Accessing external objects ............................. 112 6.2 Foreign type specifiers ................................. 114 6.3 Entry points .......................................... 118 6.4 Callbacks ............................................. 124 6.5 Locations............................................. 126 6.6