For Development HEAD DRAFTSearch (procedure/syntax/module):

12.86 util.identifier-syntax - R6RS identifier syntax

Module: util.identifier-syntax

Provide R6RS’s identifier-syntax form.

Macro: identifier-syntax template
Macro: identifier-syntax (id1 template1) ((set! id2 pattern) template2)

[R6RS] {util.identifier-syntax} Creates an idendifier macro transformer in the way R6RS specifies. For identifier transformers, see Identifier transformer. This macro is built on top of make-id-transformer. We provide this to ease porting R6RS code to Gauche.

This form must appear as transformer-spec in macro definitions (see Hygienic macros). The behavior is undefined if this is used in other places.

The first form creates an identifier macro that expands to template. Suppose you define a macro with this:

(define-syntax now (identifier-syntax (sys-time)))

Then, any use of now is expanded to (sys-time); however, (set! now expr) will raise an error.

The second form allows set! as well. The following is a contrived example:

(define-syntax foo
  (identifier-syntax
   [_ (get-foo)]
   [(set! _ expr) (set-foo! expr)]))

Any use of foo is expanded to (get-foo), except (set! foo something), which is expanded to (set-foo! something).

(Unlike using make-id-transformer and syntax-rules combination, the set! matching clause can come later.)

The expansion is hygienic. The identifiers used in template captures meaning in the scope where identifier-syntax appears, and won’t be affected by the scope where the macro is used.



For Development HEAD DRAFTSearch (procedure/syntax/module):
DRAFT