This guide is intended for programmers who are new to Scheme, new to PLT
Scheme, or new to some part of PLT Scheme. It assumes
programming experience, so if you are new to programming, consider
instead reading How to Design Programs. If you want a brief introduction to PLT
Scheme, start with Quick: An Introduction to PLT Scheme with Pictures.
1 Welcome to PLT Scheme |
1.1 Interacting with Scheme |
1.2 Definitions and Interactions |
1.3 Creating Executables |
1.4 A Note to Readers with Scheme/Lisp Experience |
|
2 Scheme Essentials |
2.1 Simple Values |
2.2 Simple Definitions and Expressions |
2.2.1 Definitions |
2.2.2 An Aside on Indenting Code |
2.2.3 Identifiers |
2.2.4 Function Calls (Procedure Applications) |
2.2.5 Conditionals with if, and, or, and cond |
2.2.6 Function Calls, Again |
2.2.7 Anonymous Functions with lambda |
2.2.8 Local Binding with
define, let, and let* |
2.3 Lists, Iteration, and Recursion |
2.3.1 Predefined List Loops |
2.3.2 List Iteration from Scratch |
2.3.3 Tail Recursion |
2.3.4 Recursion versus Iteration |
2.4 Pairs, Lists, and Scheme Syntax |
2.4.1 Quoting Pairs and Symbols with quote |
2.4.2 Abbreviating quote with ’ |
2.4.3 Lists and Scheme Syntax |
|
3 Built-In Datatypes |
3.1 Booleans |
3.2 Numbers |
3.3 Characters |
3.4 Strings (Unicode) |
3.5 Bytes and Byte Strings |
3.6 Symbols |
3.7 Keywords |
3.8 Pairs and Lists |
3.9 Vectors |
3.10 Hash Tables |
3.11 Boxes |
3.12 Void and Undefined |
|
4 Expressions and Definitions |
4.1 Notation |
4.2 Identifiers and Binding |
4.3 Function Calls (Procedure Applications) |
4.3.1 Evaluation Order and Arity |
4.3.2 Keyword Arguments |
4.3.3 The apply Function |
4.4 Functions (Procedures): lambda |
4.4.1 Declaring a Rest Argument |
4.4.2 Declaring Optional Arguments |
4.4.3 Declaring Keyword Arguments |
4.4.4 Arity-Sensitive Functions: case-lambda |
4.5 Definitions: define |
4.5.1 Function Shorthand |
4.5.2 Curried Function Shorthand |
4.5.3 Multiple Values and define-values |
4.5.4 Internal Definitions |
4.6 Local Binding |
4.6.1 Parallel Binding: let |
4.6.2 Sequential Binding: let* |
4.6.3 Recursive Binding: letrec |
4.6.4 Named let |
4.6.5 Multiple Values: let-values, let*-values, letrec-values |
4.7 Conditionals |
4.7.1 Simple Branching: if |
4.7.2 Combining Tests: and and or |
4.7.3 Chaining Tests: cond |
4.8 Sequencing |
4.8.1 Effects Before: begin |
4.8.2 Effects After: begin0 |
4.8.3 Effects If...: when and unless |
4.9 Assignment: set! |
4.9.1 Guidelines for Using Assignment |
4.9.2 Multiple Values: set!-values |
4.10 Quoting: quote and ’ |
4.11 Quasiquoting: quasiquote and ` |
4.12 Simple Dispatch: case |
|
5 Programmer-Defined Datatypes |
5.1 Simple Structure Types: define-struct |
5.2 Copying and Update |
5.3 Structure Subtypes |
5.4 Opaque versus Transparent Stucture Types |
5.5 Structure Type Generativity |
5.6 Prefab Stucture Types |
5.7 More Structure Type Options |
|
6 Modules |
6.1 Module Basics |
6.2 Module Syntax |
6.2.1 The module Form |
6.2.2 The #lang Shorthand |
6.3 Module Paths |
6.4 Imports: require |
6.5 Exports: provide |
6.6 Assignment and Redefinition |
|
7 Contracts |
7.1 Contracts and Boundaries |
7.1.1 A First Contract Violation |
7.1.2 A Subtle Contract Violation |
7.1.3 Imposing Obligations on a Module’s Clients |
7.2 Simple Contracts on Functions |
7.2.1 Restricting the Arguments of a Function |
7.2.2 Arrows |
7.2.3 Infix Contract Notation |
7.2.4 Rolling Your Own Contracts for Function Arguments |
7.2.5 The and/c, or/c, and listof Contract Combinators |
7.2.6 Restricting the Range of a Function |
7.2.7 The Difference Between any and any/c |
7.3 Contracts on Functions in General |
7.3.1 Contract Error Messages that Contain “???” |
7.3.2 Optional Arguments |
7.3.3 Rest Arguments |
7.3.4 Keyword Arguments |
7.3.5 Optional Keyword Arguments |
7.3.6 When a Function’s Result Depends on its Arguments |
7.3.7 When Contract Arguments Depend on Each Other |
7.3.8 Ensuring that a Function Properly Modifies State |
7.3.9 Contracts for case-lambda |
7.3.10 Multiple Result Values |
7.3.11 Procedures of Some Fixed, but Statically Unknown Arity |
7.4 Contracts on Structures |
7.4.1 Promising Something About a Specific Structure |
7.4.2 Promising Something About a Specific Vector |
7.4.3 Ensuring that All Structs are Well-Formed |
7.4.4 Checking Properties of Data Structures |
7.5 Examples |
7.5.1 A Customer Manager Component for Managing Customer Relationships |
7.5.2 A Parameteric (Simple) Stack |
7.5.3 A Dictionary |
7.5.4 A Queue |
7.6 Gotchas |
7.6.1 Using set! to Assign to Variables Provided via provide/contract |
|
8 Input and Output |
8.1 Varieties of Ports |
8.2 Default Ports |
8.3 Reading and Writing Scheme Data |
8.4 Datatypes and Serialization |
8.5 Bytes, Characters, and Encodings |
8.6 I/O Patterns |
|
9 Regular Expressions |
9.1 Writing Regexp Patterns |
9.2 Matching Regexp Patterns |
9.3 Basic Assertions |
9.4 Characters and Character Classes |
9.4.1 Some Frequently Used Character Classes |
9.4.2 POSIX character classes |
9.5 Quantifiers |
9.6 Clusters |
9.6.1 Backreferences |
9.6.2 Non-capturing Clusters |
9.6.3 Cloisters |
9.7 Alternation |
9.8 Backtracking |
9.9 Looking Ahead and Behind |
9.9.1 Lookahead |
9.9.2 Lookbehind |
9.10 An Extended Example |
|
10 Exceptions and Control |
10.1 Exceptions |
10.2 Prompts and Aborts |
10.3 Continuations |
|
11 Iterations and Comprehensions |
11.1 Sequence Constructors |
11.2 for and for* |
11.3 for/list and for*/list |
11.4 for/and and for/or |
11.5 for/first and for/last |
11.6 for/fold and for*/fold |
11.7 Multiple-Valued Sequences |
11.8 Iteration Performance |
|
12 Pattern Matching |
|
13 Classes and Objects |
13.1 Methods |
13.2 Initialization Arguments |
13.3 Internal and External Names |
13.4 Interfaces |
13.5 Final, Augment, and Inner |
13.6 Controlling the Scope of External Names |
13.7 Mixins |
13.7.1 Mixins and Interfaces |
13.7.2 The mixin Form |
13.7.3 Parameterized Mixins |
13.8 Traits |
13.8.1 Traits as Sets of Mixins |
13.8.2 Inherit and Super in Traits |
13.8.3 The trait Form |
|
14 Units (Components) |
14.1 Signatures and Units |
14.2 Invoking Units |
14.3 Linking Units |
14.4 First-Class Units |
14.5 Whole-module Signatures and Units |
14.6 unit versus module |
|
15 Reflection and Dynamic Evaluation |
15.1 eval |
15.1.1 Local Scopes |
15.1.2 Namespaces |
15.1.3 Namespaces and Modules |
15.2 Manipulating Namespaces |
15.2.1 Creating and Installing Namespaces |
15.2.2 Sharing Data and Code Across Namespaces |
|
16 Macros |
16.1 Pattern-Based Macros |
16.1.1 define-syntax-rule |
16.1.2 Lexical Scope |
16.1.3 define-syntax and syntax-rules |
16.1.4 Matching Sequences |
16.1.5 Identifier Macros |
16.1.6 Macro-Generating Macros |
16.1.7 Extended Example: Call-by-Reference Functions |
16.2 General Macro Transformers |
16.2.1 Syntax Objects |
16.2.2 Mixing Patterns and Expressions: syntax-case |
16.2.3 with-syntax and generate-temporaries |
16.2.4 Compile and Run-Time Phases |
16.2.5 Syntax Certificates |
|
17 Performance |
17.1 The Bytecode and Just-in-Time (JIT) Compilers |
17.2 Modules and Performance |
17.3 Function-Call Optimizations |
17.4 Mutation and Performance |
17.5 letrec Performance |
17.6 Fixnum and Flonum Optimizations |
17.7 Memory Management |
|
18 Running and Creating Executables |
18.1 Running mzscheme and mred |
18.1.1 Interactive Mode |
18.1.2 Module Mode |
18.1.3 Load Mode |
18.2 Unix Scripts |
18.3 Creating Stand-Alone Executables |
|
19 Compilation and Configuration |
|
20 More Libraries |
|
Bibliography |
|
Index |