MIT/GNU Scheme Reference Manual
Total Page:16
File Type:pdf, Size:1020Kb
MIT/GNU Scheme Reference Manual Edition 1.105 for release 9.2 2014-05-05 by Chris Hanson the MIT Scheme Team and a cast of thousands This manual documents MIT/GNU Scheme 9.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 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 :::::::::::::::::::::::::::::::: 55 4 Numbers ::::::::::::::::::::::::::::::::::::::::::: 61 5 Characters :::::::::::::::::::::::::::::::::::::::::: 79 6 Strings ::::::::::::::::::::::::::::::::::::::::::::: 91 7 Lists :::::::::::::::::::::::::::::::::::::::::::::: 109 8 Vectors:::::::::::::::::::::::::::::::::::::::::::: 125 9 Bit Strings ::::::::::::::::::::::::::::::::::::::::: 129 10 Miscellaneous Datatypes:::::::::::::::::::::::::::::: 133 11 Associations:::::::::::::::::::::::::::::::::::::::: 147 12 Procedures::::::::::::::::::::::::::::::::::::::::: 173 13 Environments :::::::::::::::::::::::::::::::::::::: 183 14 Input/Output :::::::::::::::::::::::::::::::::::::: 187 15 Operating-System Interface ::::::::::::::::::::::::::: 231 16 Error System ::::::::::::::::::::::::::::::::::::::: 265 17 Graphics :::::::::::::::::::::::::::::::::::::::::: 289 18 Win32 Package Reference ::::::::::::::::::::::::::::: 303 A GNU Free Documentation License :::::::::::::::::::::: 313 B Binding Index :::::::::::::::::::::::::::::::::::::: 321 C Concept Index :::::::::::::::::::::::::::::::::::::: 339 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 ::::::::::::::::::::::::::::::::::::::::::::: 18 2.4 Definitions :::::::::::::::::::::::::::::::::::::::::::::::::::: 20 2.4.1 Top-Level Definitions::::::::::::::::::::::::::::::::::::: 21 2.4.2 Internal Definitions::::::::::::::::::::::::::::::::::::::: 21 2.5 Assignments :::::::::::::::::::::::::::::::::::::::::::::::::: 22 2.6 Quoting::::::::::::::::::::::::::::::::::::::::::::::::::::::: 22 2.7 Conditionals :::::::::::::::::::::::::::::::::::::::::::::::::: 24 2.8 Sequencing:::::::::::::::::::::::::::::::::::::::::::::::::::: 26 2.9 Iteration :::::::::::::::::::::::::::::::::::::::::::::::::::::: 27 iv MIT/GNU Scheme 9.2 2.10 Structure Definitions ::::::::::::::::::::::::::::::::::::::::: 29 2.11 Macros :::::::::::::::::::::::::::::::::::::::::::::::::::::: 34 2.11.1 Binding Constructs for Syntactic Keywords :::::::::::::: 35 2.11.2 Pattern Language ::::::::::::::::::::::::::::::::::::::: 38 2.11.3 Syntactic Closures :::::::::::::::::::::::::::::::::::::: 40 2.11.3.1 Syntax Terminology :::::::::::::::::::::::::::::::: 40 2.11.3.2 Transformer Definition ::::::::::::::::::::::::::::: 41 2.11.3.3 Identifiers :::::::::::::::::::::::::::::::::::::::::: 45 2.11.4 Explicit Renaming :::::::::::::::::::::::::::::::::::::: 47 2.12 SRFI syntax ::::::::::::::::::::::::::::::::::::::::::::::::: 49 2.12.1 cond-expand (SRFI 0)::::::::::::::::::::::::::::::::::: 50 2.12.2 receive (SRFI 8) :::::::::::::::::::::::::::::::::::::::: 51 2.12.3 and-let* (SRFI 2) ::::::::::::::::::::::::::::::::::::::: 52 2.12.4 define-record-type (SRFI 9) ::::::::::::::::::::::::::::: 52 3 Equivalence Predicates:::::::::::::::::::::::: 55 4 Numbers ::::::::::::::::::::::::::::::::::::::: 61 4.1 Numerical types::::::::::::::::::::::::::::::::::::::::::::::: 61 4.2 Exactness ::::::::::::::::::::::::::::::::::::::::::::::::::::: 62 4.3 Implementation restrictions ::::::::::::::::::::::::::::::::::: 62 4.4 Syntax of numerical constants ::::::::::::::::::::::::::::::::: 64 4.5 Numerical operations:::::::::::::::::::::::::::::::::::::::::: 64 4.6 Numerical input and output ::::::::::::::::::::::::::::::::::: 71 4.7 Fixnum and Flonum Operations ::::::::::::::::::::::::::::::: 74 4.7.1 Fixnum Operations::::::::::::::::::::::::::::::::::::::: 74 4.7.2 Flonum Operations::::::::::::::::::::::::::::::::::::::: 76 4.8 Random Numbers::::::::::::::::::::::::::::::::::::::::::::: 77 5 Characters ::::::::::::::::::::::::::::::::::::: 79 5.1 External Representation of Characters::::::::::::::::::::::::: 79 5.2 Comparison of Characters ::::::::::::::::::::::::::::::::::::: 81 5.3 Miscellaneous Character Operations ::::::::::::::::::::::::::: 81 5.4 Internal Representation of Characters ::::::::::::::::::::::::: 82 5.5 ISO-8859-1 Characters :::::::::::::::::::::::::::::::::::::::: 84 5.6 Character Sets :::::::::::::::::::::::::::::::::::::::::::::::: 84 5.7 Unicode::::::::::::::::::::::::::::::::::::::::::::::::::::::: 87 5.7.1 Wide Strings ::::::::::::::::::::::::::::::::::::::::::::: 87 5.7.2 Unicode Representations ::::::::::::::::::::::::::::::::: 88 v 6 Strings:::::::::::::::::::::::::::::::::::::::::: 91 6.1 Construction of Strings:::::::::::::::::::::::::::::::::::::::: 92 6.2 Selecting String Components :::::::::::::::::::::::::::::::::: 92 6.3 Comparison of Strings::::::::::::::::::::::::::::::::::::::::: 93 6.4 Alphabetic Case in Strings :::::::::::::::::::::::::::::::::::: 94 6.5 Cutting and Pasting Strings ::::::::::::::::::::::::::::::::::: 95 6.6 Searching Strings ::::::::::::::::::::::::::::::::::::::::::::: 97 6.7 Matching Strings:::::::::::::::::::::::::::::::::::::::::::::: 99 6.8 Regular Expressions ::::::::::::::::::::::::::::::::::::::::: 100 6.8.1 Regular-expression procedures ::::::::::::::::::::::::::: 100 6.8.2 REXP abstraction :::::::::::::::::::::::::::::::::::::: 102 6.9 Modification of Strings ::::::::::::::::::::::::::::::::::::::: 104 6.10 Variable-Length Strings ::::::::::::::::::::::::::::::::::::: 106 6.11 Byte Vectors:::::::::::::::::::::::::::::::::::::::::::::::: 106 7 Lists ::::::::::::::::::::::::::::::::::::::::::: 109 7.1 Pairs :::::::::::::::::::::::::::::::::::::::::::::::::::::::: 110 7.2 Construction of Lists::::::::::::::::::::::::::::::::::::::::: 112 7.3 Selecting List Components ::::::::::::::::::::::::::::::::::: 114 7.4 Cutting and Pasting Lists :::::::::::::::::::::::::::::::::::: 115 7.5 Filtering Lists:::::::::::::::::::::::::::::::::::::::::::::::: 117 7.6 Searching Lists::::::::::::::::::::::::::::::::::::::::::::::: 119 7.7 Mapping of Lists ::::::::::::::::::::::::::::::::::::::::::::: 120 7.8 Reduction of Lists ::::::::::::::::::::::::::::::::::::::::::: 121 7.9 Miscellaneous List Operations :::::::::::::::::::::::::::::::: 123 8 Vectors :::::::::::::::::::::::::::::::::::::::: 125 8.1 Construction of Vectors :::::::::::::::::::::::::::::::::::::: 125 8.2 Selecting Vector Components::::::::::::::::::::::::::::::::: 126 8.3 Cutting Vectors :::::::::::::::::::::::::::::::::::::::::::::: 127 8.4 Modifying Vectors ::::::::::::::::::::::::::::::::::::::::::: 127 9 Bit Strings :::::::::::::::::::::::::::::::::::: 129 9.1 Construction of Bit Strings::::::::::::::::::::::::::::::::::: 129 9.2 Selecting Bit String Components ::::::::::::::::::::::::::::: 130 9.3 Cutting and Pasting Bit Strings :::::::::::::::::::::::::::::: 130 9.4 Bitwise Operations on Bit Strings :::::::::::::::::::::::::::: 131 9.5