{"size": 2963, "ext": "scrbl", "max_stars_repo_path": "pkgs/racket-doc/syntax/scribblings/contract.scrbl", "max_stars_repo_name": "lkh01/racket", "max_stars_repo_stars_event_min_datetime": "2018-07-29T04:13:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-14T16:11:17.000Z", "max_issues_repo_path": "pkgs/racket-doc/syntax/scribblings/contract.scrbl", "max_issues_repo_name": "lkh01/racket", "max_issues_repo_issues_event_min_datetime": "2017-08-25T20:26:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-26T17:48:40.000Z", "max_forks_repo_path": "pkgs/racket-doc/syntax/scribblings/contract.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": 10, "max_issues_count": 15, "max_forks_count": 3, "avg_line_length": 36.5802469136, "max_line_length": 93, "alphanum_fraction": 0.5399932501}
#lang scribble/manual
@(require scribble/struct scribble/decode scribble/eval
          (for-label racket/base racket/contract syntax/contract racket/syntax syntax/parse))

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

@title[#:tag "wrapc"]{Contracts for Macro Subexpressions}

@defmodule[syntax/contract]

This library provides a procedure @racket[wrap-expr/c] for applying
contracts to macro subexpressions.

@defproc[(wrap-expr/c [contract-expr syntax?]
                      [expr syntax?]
                      [#:arg? arg? any/c #t]
                      [#:positive pos-blame
                                  (or/c syntax? string? module-path-index?
                                        'from-macro 'use-site 'unknown)
                                  'from-macro]
                      [#:negative neg-blame
                                  (or/c syntax? string? module-path-index?
                                        'from-macro 'use-site 'unknown)
                                  'use-site]
                      [#:name expr-name
                              (or/c identifier? symbol? string? #f) #f]
                      [#:macro macro-name
                               (or/c identifier? symbol? string? #f) #f]
                      [#:context context (or/c syntax? #f) (current-syntax-context)]
                      [#:phase phase exact-integer? (syntax-local-phase-level)])
         syntax?]{

Returns a syntax object representing an expression that applies the
contract represented by @racket[contract-expr] to the value produced
by @racket[expr].

The other arguments have the same meaning as for @racket[expr/c].

@examples[#:eval the-eval
(define-syntax (myparameterize1 stx)
  (syntax-case stx ()
    [(_ ([p v]) body)
     (with-syntax ([cp (wrap-expr/c
                        #'parameter? #'p
                        #:name "the parameter argument"
                        #:context stx)])
       #'(parameterize ([cp v]) body))]))
(myparameterize1 ([current-input-port
                   (open-input-string "(1 2 3)")])
  (read))
(myparameterize1 (['whoops 'something])
  'whatever)

(module mod racket
  (require (for-syntax syntax/contract))
  (define-syntax (app stx)
    (syntax-case stx ()
      [(app f arg)
       (with-syntax ([cf (wrap-expr/c
                          #'(-> number? number?)
                          #'f
                          #:name "the function argument"
                          #:context stx)])
         #'(cf arg))]))
  (provide app))
(require 'mod)
(app add1 5)
(app add1 'apple)
(app (lambda (x) 'pear) 5)
]

@history[
#:added "6.3"
#:changed "7.2.0.3" @elem{Added the @racket[#:arg?] keyword argument
and changed the default values and interpretation of the
@racket[#:positive] and @racket[#:negative] arguments.}
#:changed "7.3.0.3" @elem{Added the @racket[#:phase] keyword argument.}]}

@close-eval[the-eval]
