Update README.md
Fix code block formatting
This commit is contained in:
parent
8368cc5641
commit
6eafcb7eda
10
README.md
10
README.md
|
@ -5,26 +5,26 @@ A Racket package for creating macros with built-in support for defining sub-macr
|
||||||
|
|
||||||
Sometimes complex Racket macros need a way for their syntax to be extended. The Racket match form is an example, new patterns can be created for match using define-match-expander. This racket package provides a form for defining a macro with the ability to define expanders for the macro. Consider this contrived example:
|
Sometimes complex Racket macros need a way for their syntax to be extended. The Racket match form is an example, new patterns can be created for match using define-match-expander. This racket package provides a form for defining a macro with the ability to define expanders for the macro. Consider this contrived example:
|
||||||
|
|
||||||
(define-syntax call-each
|
(define-syntax call-each
|
||||||
(syntax-parser
|
(syntax-parser
|
||||||
[(_ f (expr ...))
|
[(_ f (expr ...))
|
||||||
#'(begin (f expr) ...)]))
|
#'(begin (f expr) ...)]))
|
||||||
|
|
||||||
(call-each displayln (1 2 3))
|
(call-each displayln (1 2 3))
|
||||||
|
|
||||||
If a user of this macro wished for a way to specify a range of numbers as the arguments, the user must define their own version of call-each with support for ranges that expands to using the original call-each. However, this racket package provides a form, define-syntax-with-expanders:
|
If a user of this macro wished for a way to specify a range of numbers as the arguments, the user must define their own version of call-each with support for ranges that expands to using the original call-each. However, this racket package provides a form, define-syntax-with-expanders:
|
||||||
|
|
||||||
(define-syntax-with-expanders call-each
|
(define-syntax-with-expanders call-each
|
||||||
(syntax-parser
|
(syntax-parser
|
||||||
[(_ f (expr ...))
|
[(_ f (expr ...))
|
||||||
#'(begin (f expr) ... )]))
|
#'(begin (f expr) ... )]))
|
||||||
|
|
||||||
(define-call-each-expander foo
|
(define-call-each-expander foo
|
||||||
(syntax-parser
|
(syntax-parser
|
||||||
[(_ low:number high:number)
|
[(_ low:number high:number)
|
||||||
#`(#,@(range (syntax-e #'low) (syntax-e #'high)))]))
|
#`(#,@(range (syntax-e #'low) (syntax-e #'high)))]))
|
||||||
|
|
||||||
(call-each displayln (foo 1 4))
|
(call-each displayln (foo 1 4))
|
||||||
|
|
||||||
The define-syntax-with-expanders form creates a define-call-each-expander form, which defines syntax transformers that are only used inside the body of a call-each form and expand before call-each does.
|
The define-syntax-with-expanders form creates a define-call-each-expander form, which defines syntax transformers that are only used inside the body of a call-each form and expand before call-each does.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user