8.18
top
← prev up next →

auto-syntax-eπŸ”— i

Suzanne Soy <racket@suzanne.soy>

This package allows using syntax pattern variables outside of syntax templates: when x is bound as a syntax pattern variable, writing x then becomes roughly equivalent to (syntax->datum #'x-ddd), where x-ddd is x wrapped under the appropriate number of ellipses. If the pattern variable is bound by syntax-parse and contains non-syntax parts (e.g. it was bound within an ~optional clause, or using #:attr), they are left unchanged.

syntax

( auto-with-syntax ([patᵢeᵢ]...)body...)

Like (with-syntax ([patᵢeᵢ]... )body... ), but the syntax pattern variables bound by the patᵢ... can be used outside of syntax patterns (they are implicitly transformed using syntax->datum ):

Example:
> (auto-with-syntax ([x#'123])
(list (add1 x)#'x))

'(124 #<syntax:eval:1:0 123>)

syntax

( auto-syntax (pvarᵢ...)body...)

Re-binds the syntax pattern variables pvarᵢ... , so that can be used outside of syntax patterns like in auto-with-syntax :

Examples:
> (syntax-parse #'(123)
[(x:naty:nat... )
(list (map add1 (cons xy))#'(xy... )))])

'((2 3 4) #<syntax:eval:1:0 (1 2 3)>)

> (syntax-parse #'(123)
[({~seq x:nat{~optional y:nat}}... )
(list (map cons xy)
(attribute y)))])

'(((1 . 2) (3 . #f))

(#<syntax:eval:2:0 1> #<syntax:eval:2:0 3>)

(#<syntax:eval:2:0 2> #f))

When one of the pvarᵢ... is not a syntax pattern variable, it is ignored and the existing binding, if any, is left untouched.

Note that it is not necessary to specify the ellipsis-depth of each pvarᵢ.

syntax

( auto-syntax-case stx-expression(literal...)
[patᵢmaybe-guardᵢbodyᵢ]
...)
maybe-guardᵢ =
| guard-expression
Like syntax-case , but the syntax pattern variables bound by the patᵢ... can be used outside of templates like in auto-with-syntax .

top
← prev up next →

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /