Next: , Previous: , Up: stdlib syntax-case   [Index]


5.12.8 Generating lists of temporaries

Transformers can introduce a fixed number of identifiers into their output simply by naming each identifier. In some cases, however, the number of identifiers to be introduced depends upon some characteristic of the input expression. A straightforward definition of letrec, for example, requires as many temporary identifiers as there are binding pairs in the input expression. The procedure generate-temporaries is used to construct lists of temporary identifiers.

Procedure: generate-temporaries l

l must be be a list or syntax object representing a list–structured form; its contents are not important.

The number of temporaries generated is the number of elements in l. Each temporary is guaranteed to be unique, i.e., different from all other identifiers.

A definition of letrec equivalent to the one using syntax-rules given in scheme derived is shown below.

(define-syntax letrec
  (lambda (x)
    (syntax-case x ()
      ((_ ((i e) ...) b1 b2 ...)
       (with-syntax (((T ...)
                      (generate-temporaries #'(i ...))))
         #'(let ((i #f) ...)
             (let ((T e) ...)
               (set! i T) ...
               (let () b1 b2 ...))))))))

This version uses generate-temporaries instead of recursively defined helper to generate the necessary temporaries.