Gauche Users' Reference
Total Page:16
File Type:pdf, Size:1020Kb
Gauche Users' Reference version 0.9.8 Shiro Kawai ([email protected]) Copyright c 2001-2017 Shiro Kawai ([email protected]) i Table of Contents 1 Introduction :::::::::::::::::::::::::::::::::::::::::::::::::::: 1 1.1 Overview of Gauche:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 1 1.2 Notations :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 2 1.2.1 Entry format:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 2 1.2.2 Names and namespaces ::::::::::::::::::::::::::::::::::::::::::::::::::::::: 4 2 Concepts :::::::::::::::::::::::::::::::::::::::::::::::::::::::: 5 2.1 Standard conformance ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 5 2.2 Multibyte strings ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 10 2.3 Multibyte scripts ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 11 2.4 Case-sensitivity ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 12 2.5 Integrated object system :::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 12 2.6 Module system ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 13 2.7 Compilation :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 14 3 Programming in Gauche ::::::::::::::::::::::::::::::::::::: 15 3.1 Invoking Gosh :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 15 3.2 Interactive development::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 19 3.2.1 Working in REPL:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 20 3.3 Writing Scheme scripts:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 24 3.4 Debugging :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 26 3.5 Using platform-dependent features :::::::::::::::::::::::::::::::::::::::::::::::: 28 3.6 Profiling and tuning :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 29 3.6.1 Using profiler :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 29 3.6.2 Performance tips ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 30 3.7 Writing Gauche modules :::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 31 3.8 Using extension packages ::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 32 3.9 Building standalone executables::::::::::::::::::::::::::::::::::::::::::::::::::: 34 4 Core syntax ::::::::::::::::::::::::::::::::::::::::::::::::::: 37 4.1 Lexical structure:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 37 4.1.1 Sharp syntax :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 38 4.1.2 Hash-bang token ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 40 4.2 Literals ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 40 4.3 Making procedures:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 41 4.4 Assignments :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 46 4.5 Conditionals :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 48 4.6 Binding constructs :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 51 4.7 Sequencing ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 54 4.8 Iteration:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 55 4.9 Quasiquotation ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 58 4.10 Definitions::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 60 4.11 Inclusions ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 64 4.12 Feature conditional :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 65 4.13 Modules ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 68 4.13.1 Module semantics::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 68 4.13.2 Modules and libraries ::::::::::::::::::::::::::::::::::::::::::::::::::::::: 70 ii 4.13.3 Defining and selecting modules :::::::::::::::::::::::::::::::::::::::::::::: 70 4.13.4 Using modules :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 71 4.13.5 Module inheritance ::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 73 4.13.6 Module introspection ::::::::::::::::::::::::::::::::::::::::::::::::::::::: 73 4.13.7 Predefined modules ::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 75 5 Macros ::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 77 5.1 Why hygienic? :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 77 5.2 Hygienic macros :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 80 5.2.1 Syntax-rules macro transformer :::::::::::::::::::::::::::::::::::::::::::::: 81 5.2.2 Explicit-renaming macro transformer ::::::::::::::::::::::::::::::::::::::::: 83 5.3 Traditional macros:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 87 5.4 Macro expansion:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 87 5.5 Macro utilities :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 88 6 Core library ::::::::::::::::::::::::::::::::::::::::::::::::::: 89 6.1 Types and classes ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 89 6.2 Equality and comparison:::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 90 6.2.1 Equality ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 90 6.2.2 Comparison:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 92 6.2.3 Hashing ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 93 6.2.4 Basic comparators ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 96 6.2.4.1 Comparator class and constructors :::::::::::::::::::::::::::::::::::::: 96 6.2.4.2 Comparator predicates and accessors :::::::::::::::::::::::::::::::::::: 97 6.2.4.3 Predefined comparators ::::::::::::::::::::::::::::::::::::::::::::::::: 99 6.2.4.4 Combining comparators :::::::::::::::::::::::::::::::::::::::::::::::: 101 6.3 Numbers :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 101 6.3.1 Number classes ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 102 6.3.2 Numerical predicates:::::::::::::::::::::::::::::::::::::::::::::::::::::::: 102 6.3.3 Numerical comparison :::::::::::::::::::::::::::::::::::::::::::::::::::::: 104 6.3.4 Arithmetics ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 105 6.3.5 Numerical conversions :::::::::::::::::::::::::::::::::::::::::::::::::::::: 111 6.3.6 Basic bitwise operations::::::::::::::::::::::::::::::::::::::::::::::::::::: 114 6.3.7 Endianness ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 116 6.4 Booleans :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 117 6.5 Undefined values :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 117 6.6 Pairs and lists ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 117 6.6.1 Pair and null class :::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 118 6.6.2 List predicates :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 118 6.6.3 List constructors :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 118 6.6.4 List accessors and modifiers ::::::::::::::::::::::::::::::::::::::::::::::::: 120 6.6.5 Walking over lists ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 123 6.6.6 Other list procedures ::::::::::::::::::::::::::::::::::::::::::::::::::::::: 127 6.6.7 Association lists :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 128 6.7 Symbols ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 130 6.8 Keywords ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 132 6.8.1 Keyword and symbol integration :::::::::::::::::::::::::::::::::::::::::::: 133 6.9 Identifiers ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 135 6.10 Characters ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 135 6.11 Character Set :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 140 6.12 Strings ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 142 6.12.1 String syntax :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 142 6.12.2 String Predicates :::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 144 iii 6.12.3 String Constructors :::::::::::::::::::::::::::::::::::::::::::::::::::::::: 144 6.12.4 String interpolation :::::::::::::::::::::::::::::::::::::::::::::::::::::::: 144 6.12.5 String Accessors & Modifiers::::::::::::::::::::::::::::::::::::::::::::::: 146 6.12.6 String Comparison::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 147 6.12.7 String utilities ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 147 6.12.8 Incomplete strings ::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 150 6.13 Regular expressions::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 151 6.13.1 Regular expression syntax ::::::::::::::::::::::::::::::::::::::::::::::::: 151 6.13.2 Using regular expressions :::::::::::::::::::::::::::::::::::::::::::::::::: 154 6.13.3 Inspecting and assembling regular expressions :::::::::::::::::::::::::::::: 161 6.14 Vectors ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 162 6.15 Hashtables ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 165 6.16 Treemaps:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::