► |  | Reference: PLT Scheme

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 | Unsafe Operations
17 | Running PLT Scheme
| Bibliography
| Index

▼ | 2 | Syntactic Forms

2.1 | Modules: module, ...
2.2 | Importing and Exporting: require and provide
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.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.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 | Limiting Scope: define-package, open-package, ...
2.24 | Flattening Syntactic Sequences: nest

On this page:

nest

top ← prev up next →

#### 2.24`` Flattening Syntactic Sequences: nest

( require scheme/nest )

The bindings documented in this section are provided by the scheme/nest and scheme libraries, but not scheme/base.

( nest ([datum ...+] ...) body ...+)

Combines nested expressions that syntactically drift to the right into a more linear textual format, much in the same way that let* linearizes a sequence of nested let expressions.

For example,

( nest ([ let ([x 10]
[y 6])]
[ with-handlers ([ exn:fail? ( lambda (x) 15)])]
[ parameterize ([ current-output-port ( current-error-port )])]
[ let-values ([(d r) ( quotient/remainder x y)])])
( display ( + d r)))

is equivalent to

( let ([x 10]
[y 6])
( with-handlers ([ exn:fail? ( lambda (x) 15)])
( parameterize ([ current-output-port ( current-error-port )])
( let-values ([(d r) ( quotient/remainder x y)])
( display ( + d r))))))

The nest form is unusual in that it has no semantics apart from its expansion, and its implementation is easier to understand than a precise prose description:

( define-syntax nest
( syntax-rules ()
[( nest () body0 body ... )
( let () body0 body ... )]
[( nest ([form forms ... ]) body0 body ... )
(form forms ... ( let () body0 body ... ))]
[( nest ([form forms ... ] . more) body0 body ... )
(form forms ... ( nest more body0 body ... ))]))

top ← prev up next →