On this page:
top
up

1.6Defining Simple MacrosπŸ”— i

The syntax/parse/define library provides for-syntax all of syntax/parse, as well as providing some new forms.

syntax

( define-syntax-parse-rule (macro-id. pattern)pattern-directive...
template)
Defines a macro named macro-id; equivalent to the following:

(define-syntax (macro-idstx)
#:track-literals
[((~var macro-idid ). pattern)pattern-directive... #'template]))

Examples:
> (define-syntax-parse-rule (fnx:idrhs:expr)(lambda (x)rhs))
> ((fnxx)17)

17

> (fn12)

fn: expected identifier

at: 1

in: (fn 1 2)

#:declarexid
#:declareyid
#:declarerhsexpr
(lambda (xy)rhs))
> ((fn2ab(+ ab))34)

7

> (fn2a#:b'c)

fn2: expected identifier

at: #:b

in: (fn2 a #:b (quote c))

Added in version 7.9.0.22 of package base.

syntax

( define-syntax-parser macro-idparse-option...clause...+)

Defines a macro named macro-id; equivalent to:

(define-syntax macro-id
(syntax-parser parse-option... clause... ))

Examples:
[(fn3x:idrhs:expr)
#'(lambda (x)rhs)]
[(fn3x:idy:idrhs:expr)
#'(lambda (xy)rhs)])
> ((fn3xx)17)

17

> ((fn3ab(+ ab))34)

7

> (fn312)

fn3: expected identifier

at: 1

in: (fn3 1 2)

> (fn3a#:b'c)

fn3: expected expression or expected identifier

at: #:b

in: (fn3 a #:b (quote c))

syntax

( define-simple-macro (macro-id. pattern)pattern-directive...
template)

NOTE: This macro is deprecated; use define-syntax-parse-rule , instead.

Re-exports define-syntax-parse-rule for backward-compatibility.

Changed in version 6.12.0.3 of package base: Changed pattern head to (~var macro-idid ) from macro-id, allowing tilde-prefixed identifiers or identifiers containing colons to be used as macro-id without producing a syntax error.
Changed in version 6.90.0.29: Changed to always use the #:track-literals syntax-parse option.

top
up

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