► |  | Syntax: Meta-Programming Helpers

1 | Parsing and Specifying Syntax
2 | Syntax Object Helpers
3 | Datum Pattern Matching
4 | Module-Processing Helpers
5 | Macro Transformer Helpers
6 | Reader Helpers
7 | Source Locations
8 | Preserving Source Locations
9 | Non-Module Compilation And Expansion
10 | Trusting Standard Recertifying Transformers
11 | Attaching Documentation to Exports
| Index

▼ | 1 | Parsing and Specifying Syntax

1.1 | Introduction
1.2 | Examples
1.3 | Parsing Syntax
1.4 | Specifying Syntax with Syntax Classes
1.5 | Syntax Patterns
1.6 | Defining Simple Macros
1.7 | Literal Sets and Conventions
1.8 | Library Syntax Classes and Literal Sets
1.9 | Debugging and Inspection Tools
1.10 | Experimental

On this page:

define-simple-macro

top← prev up next →

#### 1.6`` Defining Simple Macros

(require syntax/parse/define)

> > syntax

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

Defines a macro named macro-id; equivalent to the following:

> (define-syntax (macro-id stx)
> (syntax-parse stx
> [(macro-id . pattern) pattern-directive ... #'template]))

Examples:

> > (define-simple-macro (fn x:id rhs:expr) (lambda (x) rhs))
> > ((fn x x) 17)
> 17
> > (fn 1 2)
> fn: expected identifier at: 1

> > (define-simple-macro (fn2 x y rhs)
> #:declare x id
> #:declare y id
> #:declare rhs expr
> (lambda (x y) rhs))

> > ((fn2 a b (+ a b)) 3 4)
> 7
> > (fn2 a #:b 'c)
> fn2: expected identifier at: #:b

top← prev up next →