{"size": 2553, "ext": "scrbl", "max_stars_repo_path": "cross-macro-communication/cross-macro-communication.scrbl", "max_stars_repo_name": "maueroats/syntax-parse-example", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "cross-macro-communication/cross-macro-communication.scrbl", "max_issues_repo_name": "maueroats/syntax-parse-example", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cross-macro-communication/cross-macro-communication.scrbl", "max_forks_repo_name": "maueroats/syntax-parse-example", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 40.5238095238, "max_line_length": 112, "alphanum_fraction": 0.6839012926}
#lang syntax-parse-example
@require[
  (for-label racket/base syntax/parse syntax-parse-example/cross-macro-communication/cross-macro-communication)]

@(define cross-macro-communication-eval
   (make-base-eval '(require racket
                             syntax-parse-example/cross-macro-communication/cross-macro-communication)))

@title{Cross Macro Communication}

@; =============================================================================

@defmodule[syntax-parse-example/cross-macro-communication/cross-macro-communication]{}

@deftogether[(
 @defform[(define-for-macros id expr)]
 @defform[(get-macroed id)]
)]{
  The @racket[define-for-macros] and @racket[get-macroed]
  demonstrate the use of @racket[syntax-local-value] when
  communicating information across macros. Anything defined
  with @racket[define-for-macros] can be accessed (at
  compile/macro expansion time) by @racket[get-macroed].

  @examples[#:eval cross-macro-communication-eval
            (define-for-macros cake 42)
            (get-macroed cake)
            (eval:error cake)
  ]

  This communication works even if the identifiers are defined and used in different files or modules:

  @examples[#:eval cross-macro-communication-eval
            (module the-definition racket
              (require syntax-parse-example/cross-macro-communication/cross-macro-communication)
              (define-for-macros shake 54)
              (provide shake))
            (module the-use racket
              (require 'the-definition
                       syntax-parse-example/cross-macro-communication/cross-macro-communication)
              (get-macroed shake))
            (require 'the-use)]

  The following is the source code for @racket[define-for-macros] and @racket[get-macroed]:

  @racketfile{cross-macro-communication.rkt}

  In @racket[define-for-macros], the macro simply binds a new
  value at compile time using @racket[define-syntax]. In this
  example @racket[define-for-macros] is mostly synonymous with
  @racket[define-syntax], but it demonstrates that the
  @racket[name] could be changed (to say add a question mark
  at the end), and the given expression can be changed. The
  @racket[get-macroed] form simply takes the compile time value and
  puts it in the run time module. If @racket[name] is used
  outside of a macro then a syntax error is raised.

  The point of @racket[#%datum] is to make it seem like a value was part of
   the source code.
  See @secref["expand-steps" #:doc '(lib "scribblings/reference/reference.scrbl")]
   for details.
}
