{"size": 1526, "ext": "scrbl", "max_stars_repo_path": "pkgs/racket-doc/syntax/scribblings/transformer.scrbl", "max_stars_repo_name": "lkh01/racket", "max_stars_repo_stars_event_min_datetime": "2018-07-05T21:18:24.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-04T14:48:37.000Z", "max_issues_repo_path": "pkgs/racket-doc/syntax/scribblings/transformer.scrbl", "max_issues_repo_name": "lkh01/racket", "max_issues_repo_issues_event_min_datetime": "2017-05-10T07:33:20.000Z", "max_issues_repo_issues_event_max_datetime": "2018-07-19T15:49:46.000Z", "max_forks_repo_path": "pkgs/racket-doc/syntax/scribblings/transformer.scrbl", "max_forks_repo_name": "lkh01/racket", "max_forks_repo_forks_event_min_datetime": "2016-04-25T11:47:57.000Z", "max_forks_repo_forks_event_max_datetime": "2017-05-09T14:52:48.000Z"}
{"max_stars_count": 4, "max_issues_count": 9, "max_forks_count": 3, "avg_line_length": 33.9111111111, "max_line_length": 85, "alphanum_fraction": 0.7214941022}
#lang scribble/doc
@(require "common.rkt" scribble/eval (for-label syntax/transformer))

@(define the-eval (make-base-eval))
@(the-eval '(require syntax/transformer (for-syntax racket/base syntax/transformer)))

@title[#:tag "syntax/transformer"]{Creating Macro Transformers}

@defmodule[syntax/transformer]

@defproc[(make-variable-like-transformer
          [reference-stx (or/c syntax? (-> identifier? syntax?))]
          [setter-stx (or/c syntax? (-> syntax? syntax?) #f) #f])
         (and/c set!-transformer? (-> syntax? syntax?))]{

Creates a transformer that replaces references to the macro identifier
with @racket[reference-stx]. Uses of the macro in operator position
are interpreted as an application with @racket[reference-stx] as the
function and the arguments as given. If the @racket[reference-stx] is
a procedure, it is applied to the macro identifier.

If the macro identifier is used as the target of a @racket[set!] form,
then the @racket[set!] form expands into the application of
@racket[setter-stx] to the @racket[set!] expression's right-hand side,
if @racket[setter-stx] is syntax; otherwise, the identifier is
considered immutable and a syntax error is raised. If
@racket[setter-stx] is a procedure, it is applied to the entire
@racket[set!] expression.

@examples[#:eval the-eval
(define the-box (box add1))
(define-syntax op
  (make-variable-like-transformer
   #'(unbox the-box)
   #'(lambda (v) (set-box! the-box v))))
(op 5)
(set! op 0)
op
]

@history[#:added "6.3"]{}
}

@close-eval[the-eval]
