MIT/GNU Scheme Reference Manual
Total Page:16
File Type:pdf, Size:1020Kb
MIT/GNU Scheme Reference Manual for release 11.2 2020-06-16 by Chris Hanson the MIT Scheme Team and a cast of thousands This manual documents MIT/GNU Scheme 11.2. Copyright c 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Massachusetts Institute of Technology Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts and no Back-Cover Texts. A copy of the license is included in the section entitled \GNU Free Documentation License." i Short Contents Acknowledgements :::::::::::::::::::::::::::::::::::::::: 1 1 Overview :::::::::::::::::::::::::::::::::::::::::::: 3 2 Special Forms:::::::::::::::::::::::::::::::::::::::: 15 3 Equivalence Predicates :::::::::::::::::::::::::::::::: 57 4 Numbers:::::::::::::::::::::::::::::::::::::::::::: 63 5 Characters :::::::::::::::::::::::::::::::::::::::::: 99 6 Strings :::::::::::::::::::::::::::::::::::::::::::: 107 7 Lists :::::::::::::::::::::::::::::::::::::::::::::: 129 8 Vectors :::::::::::::::::::::::::::::::::::::::::::: 147 9 Bit Strings ::::::::::::::::::::::::::::::::::::::::: 151 10 Miscellaneous Datatypes :::::::::::::::::::::::::::::: 155 11 Associations :::::::::::::::::::::::::::::::::::::::: 169 12 Procedures ::::::::::::::::::::::::::::::::::::::::: 203 13 Environments ::::::::::::::::::::::::::::::::::::::: 211 14 Input/Output::::::::::::::::::::::::::::::::::::::: 215 15 Operating-System Interface:::::::::::::::::::::::::::: 263 16 Error System ::::::::::::::::::::::::::::::::::::::: 297 17 Graphics ::::::::::::::::::::::::::::::::::::::::::: 321 18 Win32 Package Reference ::::::::::::::::::::::::::::: 335 19 Standards Support::::::::::::::::::::::::::::::::::: 345 A GNU Free Documentation License :::::::::::::::::::::: 359 B Binding Index :::::::::::::::::::::::::::::::::::::: 367 C Concept Index :::::::::::::::::::::::::::::::::::::: 389 iii Table of Contents Acknowledgements :::::::::::::::::::::::::::::::::: 1 1 Overview ::::::::::::::::::::::::::::::::::::::::: 3 1.1 Notational Conventions ::::::::::::::::::::::::::::::::::::::::: 4 1.1.1 Errors ::::::::::::::::::::::::::::::::::::::::::::::::::::: 4 1.1.2 Examples :::::::::::::::::::::::::::::::::::::::::::::::::: 4 1.1.3 Entry Format:::::::::::::::::::::::::::::::::::::::::::::: 5 1.2 Scheme Concepts ::::::::::::::::::::::::::::::::::::::::::::::: 6 1.2.1 Variable Bindings :::::::::::::::::::::::::::::::::::::::::: 6 1.2.2 Environment Concepts ::::::::::::::::::::::::::::::::::::: 6 1.2.3 Initial and Current Environments :::::::::::::::::::::::::: 7 1.2.4 Static Scoping ::::::::::::::::::::::::::::::::::::::::::::: 7 1.2.5 True and False::::::::::::::::::::::::::::::::::::::::::::: 8 1.2.6 External Representations :::::::::::::::::::::::::::::::::: 8 1.2.7 Disjointness of Types :::::::::::::::::::::::::::::::::::::: 9 1.2.8 Storage Model ::::::::::::::::::::::::::::::::::::::::::::: 9 1.3 Lexical Conventions :::::::::::::::::::::::::::::::::::::::::::: 9 1.3.1 Whitespace :::::::::::::::::::::::::::::::::::::::::::::::: 9 1.3.2 Delimiters :::::::::::::::::::::::::::::::::::::::::::::::: 10 1.3.3 Identifiers :::::::::::::::::::::::::::::::::::::::::::::::: 10 1.3.4 Uppercase and Lowercase ::::::::::::::::::::::::::::::::: 10 1.3.5 Naming Conventions:::::::::::::::::::::::::::::::::::::: 10 1.3.6 Comments:::::::::::::::::::::::::::::::::::::::::::::::: 11 1.3.7 Additional Notations ::::::::::::::::::::::::::::::::::::: 11 1.4 Expressions ::::::::::::::::::::::::::::::::::::::::::::::::::: 12 1.4.1 Literal Expressions ::::::::::::::::::::::::::::::::::::::: 13 1.4.2 Variable References ::::::::::::::::::::::::::::::::::::::: 13 1.4.3 Special Form Syntax :::::::::::::::::::::::::::::::::::::: 13 1.4.4 Procedure Call Syntax :::::::::::::::::::::::::::::::::::: 13 2 Special Forms :::::::::::::::::::::::::::::::::: 15 2.1 Lambda Expressions::::::::::::::::::::::::::::::::::::::::::: 15 2.2 Lexical Binding:::::::::::::::::::::::::::::::::::::::::::::::: 17 2.3 Dynamic Binding:::::::::::::::::::::::::::::::::::::::::::::: 20 2.3.1 Fluid-Let ::::::::::::::::::::::::::::::::::::::::::::::::: 22 2.4 Definitions :::::::::::::::::::::::::::::::::::::::::::::::::::: 22 2.4.1 Top-Level Definitions ::::::::::::::::::::::::::::::::::::: 23 2.4.2 Internal Definitions ::::::::::::::::::::::::::::::::::::::: 23 2.5 Assignments::::::::::::::::::::::::::::::::::::::::::::::::::: 24 2.6 Quoting ::::::::::::::::::::::::::::::::::::::::::::::::::::::: 24 2.7 Conditionals::::::::::::::::::::::::::::::::::::::::::::::::::: 26 2.8 Sequencing :::::::::::::::::::::::::::::::::::::::::::::::::::: 28 iv MIT/GNU Scheme 11.2 2.9 Iteration :::::::::::::::::::::::::::::::::::::::::::::::::::::: 29 2.10 Structure Definitions ::::::::::::::::::::::::::::::::::::::::: 31 2.11 Macros ::::::::::::::::::::::::::::::::::::::::::::::::::::::: 36 2.11.1 Binding Constructs for Syntactic Keywords :::::::::::::: 37 2.11.2 Pattern Language ::::::::::::::::::::::::::::::::::::::: 40 2.11.3 Syntactic Closures ::::::::::::::::::::::::::::::::::::::: 42 2.11.3.1 Syntax Terminology :::::::::::::::::::::::::::::::: 42 2.11.3.2 Transformer Definition:::::::::::::::::::::::::::::: 43 2.11.3.3 Identifiers :::::::::::::::::::::::::::::::::::::::::: 47 2.11.4 Explicit Renaming::::::::::::::::::::::::::::::::::::::: 49 2.12 SRFI syntax ::::::::::::::::::::::::::::::::::::::::::::::::: 51 2.12.1 cond-expand (SRFI 0) ::::::::::::::::::::::::::::::::::: 52 2.12.2 receive (SRFI 8) ::::::::::::::::::::::::::::::::::::::::: 53 2.12.3 and-let* (SRFI 2) ::::::::::::::::::::::::::::::::::::::: 54 2.12.4 define-record-type (SRFI 9) :::::::::::::::::::::::::::::: 54 3 Equivalence Predicates :::::::::::::::::::::::: 57 4 Numbers :::::::::::::::::::::::::::::::::::::::: 63 4.1 Numerical types ::::::::::::::::::::::::::::::::::::::::::::::: 63 4.2 Exactness ::::::::::::::::::::::::::::::::::::::::::::::::::::: 64 4.3 Implementation restrictions :::::::::::::::::::::::::::::::::::: 64 4.4 Syntax of numerical constants ::::::::::::::::::::::::::::::::: 66 4.5 Numerical operations :::::::::::::::::::::::::::::::::::::::::: 66 4.6 Numerical input and output ::::::::::::::::::::::::::::::::::: 78 4.7 Fixnum and Flonum Operations ::::::::::::::::::::::::::::::: 81 4.7.1 Fixnum Operations ::::::::::::::::::::::::::::::::::::::: 81 4.7.2 Flonum Operations ::::::::::::::::::::::::::::::::::::::: 83 4.7.3 Floating-Point Environment :::::::::::::::::::::::::::::: 91 4.7.4 Floating-Point Exceptions :::::::::::::::::::::::::::::::: 92 4.7.5 Floating-Point Rounding Mode ::::::::::::::::::::::::::: 95 4.8 Random Number Generation :::::::::::::::::::::::::::::::::: 96 5 Characters :::::::::::::::::::::::::::::::::::::: 99 5.1 Character implementation :::::::::::::::::::::::::::::::::::: 102 5.2 Unicode :::::::::::::::::::::::::::::::::::::::::::::::::::::: 103 5.3 Character Sets ::::::::::::::::::::::::::::::::::::::::::::::: 105 6 Strings ::::::::::::::::::::::::::::::::::::::::: 107 6.1 Searching and Matching Strings :::::::::::::::::::::::::::::: 119 6.2 Regular Expressions :::::::::::::::::::::::::::::::::::::::::: 122 6.2.1 Regular S-Expressions ::::::::::::::::::::::::::::::::::: 122 6.2.2 Regsexp Procedures ::::::::::::::::::::::::::::::::::::: 127 v 7 Lists:::::::::::::::::::::::::::::::::::::::::::: 129 7.1 Pairs ::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 130 7.2 Construction of Lists ::::::::::::::::::::::::::::::::::::::::: 132 7.3 Selecting List Components:::::::::::::::::::::::::::::::::::: 134 7.4 Cutting and Pasting Lists :::::::::::::::::::::::::::::::::::: 135 7.5 Filtering Lists :::::::::::::::::::::::::::::::::::::::::::::::: 137 7.6 Searching Lists ::::::::::::::::::::::::::::::::::::::::::::::: 138 7.7 Mapping of Lists ::::::::::::::::::::::::::::::::::::::::::::: 139 7.8 Folding of Lists::::::::::::::::::::::::::::::::::::::::::::::: 142 7.9 Miscellaneous List Operations :::::::::::::::::::::::::::::::: 144 8 Vectors :::::::::::::::::::::::::::::::::::::::: 147 8.1 Construction of Vectors :::::::::::::::::::::::::::::::::::::: 147 8.2 Selecting Vector Components ::::::::::::::::::::::::::::::::: 148 8.3 Cutting Vectors :::::::::::::::::::::::::::::::::::::::::::::: 149 8.4 Modifying Vectors :::::::::::::::::::::::::::::::::::::::::::: 150 9 Bit Strings::::::::::::::::::::::::::::::::::::: 151 9.1 Construction of Bit Strings ::::::::::::::::::::::::::::::::::: 151 9.2 Selecting Bit String Components ::::::::::::::::::::::::::::: 152 9.3 Cutting and Pasting Bit Strings :::::::::::::::::::::::::::::: 152 9.4 Bitwise Operations on Bit Strings :::::::::::::::::::::::::::: 153 9.5 Modification of Bit Strings ::::::::::::::::::::::::::::::::::: 153 9.6 Integer Conversions of Bit Strings :::::::::::::::::::::::::::: 154 10 Miscellaneous Datatypes :::::::::::::::::::: 155 10.1 Booleans :::::::::::::::::::::::::::::::::::::::::::::::::::: 155 10.2 Symbols::::::::::::::::::::::::::::::::::::::::::::::::::::: 156 10.3 Parameters:::::::::::::::::::::::::::::::::::::::::::::::::: 159 10.3.1 Cells ::::::::::::::::::::::::::::::::::::::::::::::::::: 160 10.4 Records ::::::::::::::::::::::::::::::::::::::::::::::::::::: 160 10.5 Promises :::::::::::::::::::::::::::::::::::::::::::::::::::: 162 10.6 Streams :::::::::::::::::::::::::::::::::::::::::::::::::::::