
Changed backtracking algorithm, runtime representations - syntax classes, ~describe no longer implicitly commit - ~describe no longer delimits effect of cut Added keyword & optional args for stxclasses Added ~do and #:do, ~post, ~commit and #:commit, ~delimit-cut and #:no-delimit-cut Added syntax/parse/debug, syntax/parse/experimental/* - expr/c for contracting macro sub-expressions moved from syntax/parse to syntax/parse/experimental/contract - syntax class reflection (~reflect, ~splicing-reflect) - eh-alternative-sets (~eh-var) - provide-syntax-class/contract (only for params, not attrs so far) Changed ~fail to not include POST progress (#:fail still does) old (~fail _) is now (~post (~fail _)) Made msg argument of ~fail optional Removed generic "repetition constraint violated" msg Removed atom-in-list stxclass Removed unnecessary datum->syntax on cdr of pair pattern massive improvements to long-list microbenchmarks Optimization: integrable syntax classes (id, expr, keyword) need better measurements Optimization: ad hoc elimination of head/tail choice point for (EH ... . ()) patterns Added unstable/wrapc (proc version of expr/c)
43 lines
1.5 KiB
Racket
43 lines
1.5 KiB
Racket
#lang scribble/doc
|
|
@(require scribble/manual
|
|
scribble/struct
|
|
scribble/decode
|
|
scribble/eval
|
|
"parse-common.rkt"
|
|
(for-label racket/class))
|
|
|
|
@title[#:tag "exprc"]{Experimental: Contracts on macro sub-expressions}
|
|
|
|
@emph{This section involves facilities that are experimental and
|
|
subject to change.}
|
|
|
|
Just as procedures often expect certain kinds of values as arguments,
|
|
macros often have expectations about the expressions they are
|
|
given. And just as procedures express those expectations via
|
|
contracts, so can macros, using the @scheme[expr/c] syntax class.
|
|
|
|
For example, here is a macro @scheme[myparameterize] that behaves like
|
|
@scheme[parameterize] but enforces the @scheme[parameter?] contract on
|
|
the parameter expressions.
|
|
|
|
@myinteraction[
|
|
(define-syntax (myparameterize stx)
|
|
(syntax-parse stx
|
|
[(_ ((p v:expr) ...) body:expr)
|
|
#:declare p (expr/c #'parameter?
|
|
#:name "parameter argument")
|
|
#'(parameterize ((p.c v) ...) body)]))
|
|
(myparameterize ((current-input-port
|
|
(open-input-string "(1 2 3)")))
|
|
(read))
|
|
(myparameterize (('whoops 'something))
|
|
'whatever)
|
|
]
|
|
|
|
@bold{Important:} Make sure when using @scheme[expr/c] to use the
|
|
@scheme[c] attribute. If the macro above had used @scheme[p] in the
|
|
template, the expansion would have used the raw, unchecked
|
|
expressions. The @scheme[expr/c] syntax class does not change how
|
|
pattern variables are bound; it only computes an attribute that
|
|
represents the checked expression.
|