1 Language Model
2 Syntactic Forms
3 Datatypes
4 Structures
5 Classes and Objects
6 Units
7 Contracts
8 Pattern Matching
9 Control Flow
10 Concurrency
11 Macros
12 Input and Output
13 Reflection and Security
14 Operating System
15 Memory Management
16 Running PLT Scheme
Bibliography
Index
Version: 4.0.2

 

Reference: PLT Scheme

This manual defines the core PLT Scheme language and describes its most prominent libraries. The companion manual Guide: PLT Scheme provides a friendlier (though less precise and less complete) overview of the language.

 #lang scheme/base

 #lang scheme

Unless otherwise noted, the bindings defined in this manual are exported by the scheme/base and scheme languages.

The scheme library combines scheme/base, scheme/bool, scheme/class, scheme/cmdline, scheme/contract, scheme/dict, scheme/enter, scheme/file, scheme/function, scheme/include, scheme/list, scheme/local, scheme/match, scheme/math, scheme/nest, scheme/path, scheme/port, scheme/pretty, scheme/promise, scheme/shared, scheme/string, scheme/tcp, scheme/udp, and scheme/unit.

    1 Language Model

      1.1 Evaluation Model

        1.1.1 Sub-expression Evaluation and Continuations

        1.1.2 Tail Position

        1.1.3 Multiple Return Values

        1.1.4 Top-Level Variables

        1.1.5 Objects and Imperative Update

        1.1.6 Object Identity and Comparisons

        1.1.7 Garbage Collection

        1.1.8 Procedure Applications and Local Variables

        1.1.9 Variables and Locations

        1.1.10 Modules and Module-Level Variables

          1.1.10.1 Module Phases

          1.1.10.2 Module Re-declarations

        1.1.11 Continuation Frames and Marks

        1.1.12 Prompts, Delimited Continuations, and Barriers

        1.1.13 Threads

        1.1.14 Parameters

        1.1.15 Exceptions

        1.1.16 Custodians

      1.2 Syntax Model

        1.2.1 Identifiers and Binding

        1.2.2 Syntax Objects

        1.2.3 Expansion (Parsing)

          1.2.3.1 Fully Expanded Programs

          1.2.3.2 Expansion Steps

          1.2.3.3 Expansion Context

          1.2.3.4 Introducing Bindings

          1.2.3.5 Transformer Bindings

          1.2.3.6 Partial Expansion

          1.2.3.7 Internal Definitions

          1.2.3.8 Module Phases

        1.2.4 Compilation

        1.2.5 Namespaces

        1.2.6 Inferred Value Names

    2 Syntactic Forms

      2.1 Modules: module, ...

      2.2 Importing and Exporting: require and provide

        2.2.1 Additional require Forms

        2.2.2 Additional provide Forms

      2.3 Literals: quote and #%datum

      2.4 Expression Wrapper: #%expression

      2.5 Variable References and #%top

      2.6 Locations: #%variable-reference

      2.7 Procedure Applications and #%app

      2.8 Procedure Expressions: lambda and case-lambda

      2.9 Local Binding: let, let*, letrec, ...

      2.10 Local Definitions: local

      2.11 Constructing Graphs: shared

      2.12 Conditionals: if, cond, and, and or

      2.13 Dispatch: case

      2.14 Definitions: define, define-syntax, ...

        2.14.1 require Macros

        2.14.2 provide Macros

      2.15 Sequencing: begin, begin0, and begin-for-syntax

      2.16 Guarded Evaluation: when and unless

      2.17 Assignment: set! and set!-values

      2.18 Iterations and Comprehensions: for, for/list, ...

        2.18.1 Iteration and Comprehension Forms

        2.18.2 Deriving New Iteration Forms

        2.18.3 Do Loops

      2.19 Continuation Marks: with-continuation-mark

      2.20 Quasiquoting: quasiquote, unquote, and unquote-splicing

      2.21 Syntax Quoting: quote-syntax

      2.22 Interaction Wrapper: #%top-interaction

      2.23 Flattening Syntactic Sequences: nest

    3 Datatypes

      3.1 Booleans and Equality

        3.1.1 Boolean Synonyms

      3.2 Numbers

        3.2.1 Number Types

        3.2.2 Arithmetic

        3.2.3 Number Comparison

        3.2.4 Powers and Roots

        3.2.5 Trignometric Functions

        3.2.6 Complex Numbers

        3.2.7 Bitwise Operations

        3.2.8 Random Numbers

        3.2.9 Number–String Conversions

        3.2.10 Extra Constants and Functions

      3.3 Strings

        3.3.1 String Constructors, Selectors, and Mutators

        3.3.2 String Comparisons

        3.3.3 String Conversions

        3.3.4 Locale-Specific String Operations

        3.3.5 Additional String Functions

      3.4 Byte Strings

        3.4.1 Byte String Constructors, Selectors, and Mutators

        3.4.2 Byte String Comparisons

        3.4.3 Bytes to/from Characters, Decoding and Encoding

        3.4.4 Bytes to Bytes Encoding Conversion

      3.5 Characters

        3.5.1 Characters and Scalar Values

        3.5.2 Character Comparisons

        3.5.3 Classifications

        3.5.4 Character Conversions

      3.6 Symbols

      3.7 Regular Expressions

        3.7.1 Regexp Syntax

        3.7.2 Additional Syntactic Constraints

        3.7.3 Regexp Constructors

        3.7.4 Regexp Matching

        3.7.5 Regexp Splitting

        3.7.6 Regexp Substitution

      3.8 Keywords

      3.9 Pairs and Lists

        3.9.1 Pair Constructors and Selectors

        3.9.2 List Operations

        3.9.3 List Iteration

        3.9.4 List Filtering

        3.9.5 List Searching

        3.9.6 Pair Accessor Shorthands

        3.9.7 Additional List Functions and Synonyms

        3.9.8 Immutable Cyclic Data

      3.10 Mutable Pairs and Lists

        3.10.1 Mutable Pair Constructors and Selectors

        3.10.2 Mutable List Functions

      3.11 Vectors

      3.12 Boxes

      3.13 Hash Tables

      3.14 Sequences

        3.14.1 Sequence Predicate and Constructors

        3.14.2 Sequence Generators

      3.15 Dictionaries

      3.16 Procedures

        3.16.1 Keywords and Arity

        3.16.2 Reflecting on Primitives

        3.16.3 Additional Procedure Functions

      3.17 Void and Undefined

    4 Structures

      4.1 Defining Structure Types: define-struct

      4.2 Creating Structure Types

      4.3 Structure Type Properties

      4.4 Copying and Updating Structures

      4.5 Structure Utilities

      4.6 Structure Type Transformer Binding

    5 Classes and Objects

      5.1 Creating Interfaces

      5.2 Creating Classes

        5.2.1 Initialization Variables

        5.2.2 Fields

        5.2.3 Methods

          5.2.3.1 Method Definitions

          5.2.3.2 Inherited and Superclass Methods

          5.2.3.3 Internal and External Names

      5.3 Creating Objects

      5.4 Field and Method Access

        5.4.1 Methods

        5.4.2 Fields

        5.4.3 Generics

      5.5 Mixins

      5.6 Traits

      5.7 Object and Class Contracts

      5.8 Object Serialization

      5.9 Object, Class, and Interface Utilities

      5.10 Surrogates

    6 Units

      6.1 Creating Units

      6.2 Invoking Units

      6.3 Linking Units and Creating Compound Units

      6.4 Inferred Linking

      6.5 Generating A Unit from Context

      6.6 Structural Matching

      6.7 Extending the Syntax of Signatures

      6.8 Unit Utilities

      6.9 Single-Unit Modules

      6.10 Single-Signature Modules

      6.11 Transformer Helpers

    7 Contracts

      7.1 Data-structure Contracts

      7.2 Function Contracts

      7.3 Lazy Data-structure Contracts

      7.4 Attaching Contracts to Values

      7.5 Building New Contract Combinators

      7.6 Contract Utilities

    8 Pattern Matching

      8.1 Combined Matching Forms

      8.2 Extending match

    9 Control Flow

      9.1 Multiple Values

      9.2 Exceptions

        9.2.1 Raising Exceptions

        9.2.2 Handling Exceptions

        9.2.3 Configuring Default Handling

        9.2.4 Built-in Exception Types

      9.3 Delayed Evaluation

      9.4 Continuations

        9.4.1 Classical Control Operators

      9.5 Continuation Marks

      9.6 Breaks

      9.7 Exiting

    10 Concurrency

      10.1 Threads

        10.1.1 Creating Threads

        10.1.2 Suspending, Resuming, and Killing Threads

        10.1.3 Synchronizing Thread State

        10.1.4 Thread Mailboxes

      10.2 Synchronization

        10.2.1 Events

        10.2.2 Channels

        10.2.3 Semaphores

        10.2.4 Buffered Asynchronous Channels

      10.3 Thread-Local Storage

        10.3.1 Thread Cells

        10.3.2 Parameters

    11 Macros

      11.1 Pattern-Based Syntax Matching

      11.2 Syntax Object Content

      11.3 Syntax Object Bindings

      11.4 Syntax Transformers

        11.4.1 require Transformers

        11.4.2 provide Transformers

      11.5 Syntax Parameters

        11.5.1 Syntax Parameter Inspection

      11.6 Syntax Object Properties

      11.7 Syntax Certificates

      11.8 Expanding Top-Level Forms

        11.8.1 Information on Expanded Modules

      11.9 File Inclusion

    12 Input and Output

      12.1 Ports

        12.1.1 Encodings and Locales

        12.1.2 Managing Ports

        12.1.3 Port Buffers and Positions

        12.1.4 Counting Positions, Lines, and Columns

        12.1.5 File Ports

        12.1.6 String Ports

        12.1.7 Pipes

        12.1.8 Structures as Ports

        12.1.9 Custom Ports

        12.1.10 More Port Constructors and Events

          12.1.10.1 Creating Ports

          12.1.10.2 Port Events

          12.1.10.3 Copying Streams

      12.2 Byte and String Input

      12.3 Byte and String Output

      12.4 Reading

      12.5 Writing

      12.6 The Reader

      12.7 The Printer

      12.8 Pretty Printing

        12.8.1 Basic Pretty-Print Options

        12.8.2 Per-Symbol Special Printing

        12.8.3 Line-Output Hook

        12.8.4 Value Output Hook

        12.8.5 Additional Custom-Output Support

      12.9 Reader Extension

        12.9.1 Readtables

        12.9.2 Reader-Extension Procedures

        12.9.3 Special Comments

      12.10 Printer Extension

      12.11 Serialization

    13 Reflection and Security

      13.1 Namespaces

      13.2 Evaluation and Compilation

      13.3 The scheme/load Language

      13.4 Module Names and Loading

        13.4.1 Resolving Module Names

        13.4.2 Compiled Modules and References

        13.4.3 Dynamic Module Access

      13.5 Security Guards

      13.6 Custodians

      13.7 Thread Groups

      13.8 Structure Inspectors

      13.9 Code Inspectors

      13.10 Sandboxed Evaluation

        13.10.1 Customizing Evaluators

        13.10.2 Interacting with Evaluators

        13.10.3 Miscellaneous

    14 Operating System

      14.1 Paths

        14.1.1 Manipulating Paths

        14.1.2 More Path Utilities

        14.1.3 Unix and Mac OS X Paths

        14.1.4 Windows Path Conventions

      14.2 Filesystem

        14.2.1 Locating Paths

        14.2.2 Files

        14.2.3 Directories

        14.2.4 Declaring Paths Needed at Run Time

        14.2.5 More File and Directory Utilities

      14.3 Networking

        14.3.1 TCP

        14.3.2 UDP

      14.4 Processes

        14.4.1 Simple Subprocesses

      14.5 Time

        14.5.1 Date Utilities

      14.6 Environment and Runtime Information

      14.7 Command-Line Parsing

    15 Memory Management

      15.1 Weak Boxes

      15.2 Ephemerons

      15.3 Wills and Executors

      15.4 Garbage Collection

    16 Running PLT Scheme

      16.1 Starting MzScheme or MrEd

        16.1.1 Initialization

        16.1.2 Init Libraries

        16.1.3 Command Line

      16.2 Libraries and Collections

      16.3 Interactive Help

      16.4 Interactive Module Loading

    Bibliography

    Index