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
On this page:
nest
Version: 4.0.2

 

2.23 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 ...))]))