#
PLT MzScheme: Language Manual

Matthew Flatt (mflatt@plt-scheme.org)

301
Released December 2006

1 Introduction
1.1 MrEd, DrScheme, and `mzc`
1.2 Unicode, Locales, Strings, and Ports
1.2.1 Unicode
1.2.2 Locale
1.2.3 Encodings and Ports
1.3 Notation

2 Basic Syntax Extensions
2.1 Evaluation Order
2.2 Multiple Return Values
2.3 Cond and Case
2.4 When and Unless
2.5 And and Or
2.6 Sequences
2.7 Quote and Quasiquote
2.8 Binding Forms
2.8.1 Definitions
2.8.2 Local Bindings
2.8.3 Assignments
2.8.4 Fluid-Let
2.8.5 Syntax Expansion and Internal Definitions
2.9 Case-Lambda
2.10 Procedure Application
2.11 Variable Reference

3 Basic Data Extensions
3.1 Void and Undefined
3.2 Booleans
3.3 Numbers
3.4 Characters
3.5 Strings
3.6 Byte Strings
3.7 Symbols
3.8 Keywords
3.9 Vectors
3.10 Lists
3.11 Boxes
3.12 Procedures
3.12.1 Arity
3.12.2 Primitives
3.12.3 Procedure Names
3.13 Promises
3.14 Hash Tables

4 Structures
4.1 Defining Structure Types
4.2 Creating Subtypes
4.3 Structure Types with Automatic Fields, Immutable Fields, and Properties
4.4 Structure Type Properties
4.5 Structure Inspectors
4.6 Structures as Procedures
4.7 Structures as Synchronizable Events
4.8 Structure Utilities

5 Modules
5.1 Module Expansion and Execution
5.2 Module Bodies
5.3 Modules and Macros
5.4 Module Paths
5.4.1 Module Name Resolver
5.4.2 Module Names and Compilation
5.5 Dynamic Module Access
5.6 Re-declaring Modules
5.7 Built-in Modules
5.8 Modules and Load Handlers

6 Exceptions and Control Flow
6.1 Exceptions
6.1.1 Primitive Exceptions
6.2 Errors
6.2.1 Application Type Errors
6.2.2 Application Mismatch Errors
6.2.3 Syntax Errors
6.2.4 Inferred Value Names
6.3 Continuations
6.4 Dynamic Wind
6.5 Continuation Marks
6.6 Breaks
6.7 Error Escape Handler

7 Threads
7.1 Suspending, Resuming, and Killing Threads
7.2 Synchronizing Thread State
7.3 Additional Thread Utilities
7.4 Semaphores
7.5 Channels
7.6 Alarms
7.7 Synchronizing Events
7.8 Thread-Local Storage Cells
7.9 Parameters
7.9.1 Built-in Parameters
7.9.1.1 Current Directory
7.9.1.2 Ports
7.9.1.3 Parsing
7.9.1.4 Printing
7.9.1.5 Read-Eval-Print
7.9.1.6 Loading
7.9.1.7 Exceptions
7.9.1.8 Security
7.9.1.9 Exiting
7.9.1.10 Random Numbers
7.9.1.11 Locale
7.9.1.12 Modules
7.9.2 Parameter Utilities

8 Namespaces
8.1 Identifier Resolution in Namespaces
8.2 Initial Namespace
8.3 Namespace Utilities

9 Security
9.1 Security Guards
9.2 Custodians
9.3 Thread Groups
9.4 Inspectors and Modules

10 Regular Expressions

11 Input and Output
11.1 Ports
11.1.1 End-of-File Constant
11.1.2 Current Ports
11.1.3 Opening File Ports
11.1.4 Pipes
11.1.5 String Ports
11.1.6 File-Stream Ports
11.1.7 Custom Ports
11.1.7.1 Custom Input
11.1.7.2 Custom Output
11.2 Reading and Writing
11.2.1 Reading Bytes, Characters, and Strings
11.2.1.1 Counting Positions, Lines, and Columns
11.2.2 Writing Bytes, Characters, and Strings
11.2.3 Writing Structured Data
11.2.4 Default Reader
11.2.5 Default Printer
11.2.5.1 Sharing Structure in Input and Output
11.2.6 Replacing the Reader
11.2.7 Replacing the Printer
11.2.8 Customizing the Reader through Readtables
11.2.9 Reader-Extension Procedures
11.2.9.1 Special Comments
11.2.9.2 Recursive Reads
11.2.10 Customizing the Printer through Custom-Write Procedures
11.3 Filesystem Utilities
11.3.1 Paths
11.3.2 Locating Paths
11.3.3 Files
11.3.4 Directories
11.4 Networking
11.4.1 TCP
11.4.2 UDP

12 Syntax and Macros
12.1 `syntax-rules` Extensions
12.2 Syntax Objects
12.2.1 Syntax Patterns
12.2.1.1 Binding Pattern Variables
12.2.1.2 Quasiquoting Templates
12.2.1.3 Assigning Source Location
12.2.2 Syntax Object Content
12.3 Syntax and Lexical Scope
12.3.1 Syntax Object Comparisons
12.3.2 Syntax Object Bindings
12.3.3 Transformer Environments
12.3.4 Module Environments
12.3.5 Macro-Generated Top-Level and Module Definitions
12.4 Binding Multiple Syntax Identifiers
12.5 Special Syntax Identifiers
12.6 Macro Expansion
12.6.1 Expanding Expressions to Primitive Syntax
12.6.2 Syntax Object Properties
12.6.3 Certificates for Protected References
12.6.3.1 Certificate Propagation
12.6.3.2 Internal Certificates
12.6.3.3 Checking and Transferring Certificates
12.6.4 Information on Structure Types
12.6.5 Information on Expanded and Compiled Modules

13 Memory Management
13.1 Weak Boxes
13.2 Ephemerons
13.3 Will Executors
13.4 Garbage Collection

14 Support Facilities
14.1 Eval and Load
14.2 Exiting
14.3 Compilation
14.4 Dynamic Extensions
14.5 Saving and Restoring Program Images

15 System Utilities
15.1 Time
15.1.1 Real Time and Date
15.1.2 Machine Time
15.1.3 Timing Execution
15.2 Operating System Processes
15.3 Windows Actions
15.4 Operating System Environment Variables
15.5 Runtime Information

16 Library Collections and MzLib

17 Running MzScheme
17.1 Flag Conventions
17.2 Executable Name
17.3 Initialization

18 Writing and Running Scripts

19 Honu
19.1 Honu Input Parsing
19.1.1 Numbers
19.1.2 Identifiers
19.1.3 Strings
19.1.4 Characters
19.1.5 Parentheses, Brackets, and Braces
19.1.6 Comments
19.2 Honu Output Printing

20 Windows Path Syntax

## Copyright notice

Copyright ©1995-2005 Matthew Flatt

Permission to make digital/hard copies and/or distribute this documentation for any purpose is hereby granted without fee, provided that the above copyright notice, author, and this permission notice appear in all copies of this documentation.

libscheme: Copyright ©1994 Brent Benson. All rights reserved.

Conservative garbage collector: Copyright ©1988, 1989 Hans-J. Boehm, Alan J. Demers. Copyright ©1991-1996 by Xerox Corporation. Copyright ©1996-1999 by Silicon Graphics. Copyright ©1999-2001 by Hewlett Packard Company. All rights reserved.

Collector C++ extension by Jesse Hull and John Ellis: Copyright ©1994 by Xerox Corporation. All rights reserved. GNU MP Library: Copyright ©1992, 1993, 1994, 1996 by Free Software Foundation, Inc.

## Send us your Web links

If you use any parts or all of the PLT Scheme package (software, lecture notes) for one of your courses, for your research, or for your work, we would like to know about it. Furthermore, if you use it and publicize the fact on some Web page, we would like to link to that page. Please drop us a line at scheme@plt-scheme.org. Evidence of interest helps the DrScheme Project to maintain the necessary intellectual and financial support. We appreciate your help.

## Thanks

Thanks to Brent Benson for `libscheme`, and to Hans Boehm for the conservative garbage collector and their help.

This manual was typeset using LATEX, SLaTeX, and `tex2page`. Some typesetting macros were originally taken from Julian Smart's Reference Manual for wxWindows 1.60: a portable C++ GUI toolkit.

This manual was typeset on Thursday, January 12th, 2006.

Last modified: Thursday, January 12th, 2006 3:26:15pm
HTML conversion by TeX2page 20050501