#
PLT MzScheme: Language Manual

Matthew Flatt (mflatt@plt-scheme.org)

Version 204
May 2003

1 Introduction
1.1 MrEd, DrScheme, and `mzc`
1.2 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 Global Variables
2.8.2 Local Variables
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

3 Basic Data Extensions
3.1 Void and Undefined
3.2 Booleans
3.3 Numbers
3.4 Characters
3.5 Strings
3.6 Symbols
3.7 Vectors
3.8 Lists
3.9 Boxes
3.10 Procedures
3.10.1 Arity
3.10.2 Primitives
3.10.3 Procedure Names
3.11 Promises
3.12 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 Waitable Objects
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 Synchronizing Multiple Objects with Timeout
7.7 Parameters
7.7.1 Built-in Parameters
7.7.1.1 Current Directory
7.7.1.2 Ports
7.7.1.3 Parsing
7.7.1.4 Printing
7.7.1.5 Read-Eval-Print
7.7.1.6 Loading
7.7.1.7 Exceptions
7.7.1.8 Security
7.7.1.9 Exiting
7.7.1.10 Random Numbers
7.7.1.11 Locale
7.7.1.12 Modules
7.7.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

10 Regular Expressions

11 Input and Output
11.1 Ports
11.1.1 Current Ports
11.1.2 Opening File Ports
11.1.3 Pipes
11.1.4 String Ports
11.1.5 File-Stream Ports
11.1.6 Custom Ports
11.1.6.1 Custom Input
11.1.6.2 Custom Output
11.2 Reading and Writing
11.2.1 Reading
11.2.2 Writing
11.2.3 Counting Positions, Lines, and Columns
11.2.4 Customizing Read
11.2.5 Customizing Display, Write, and Print
11.3 Filesystem Utilities
11.3.1 Pathnames
11.3.2 Files
11.3.3 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 and Fluid 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 Information on Structure Types
12.6.4 Information on Expanded and Compiled Modules

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

14 Support Facilities
14.1 Eval and Load
14.2 Exiting
14.3 Input Parsing
14.4 Output Printing
14.5 Data Sharing in Input and Output
14.6 Compilation
14.7 Dynamic Extensions
14.8 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

## Copyright notice

Copyright ©1995-2003 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 typest 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 Wednesday, April 30th, 2003.

Last modified: Wed, April 30, 2003, 4:02 pm US/Eastern
HTML conversion by TeX2page 4r8f