(define*
[x 4]
[y 18]
[(quot rem) (quotient/remainder x y)])
quot rem
; -> 0
; -> 4
Definitions are automatically dispatched either to define or define-values depending on the manner in which identifiers are supplied (define-values is used if the identifiers are contained within a set of parenthesis)
Before and After
This macro saves a lot of unneccesary code when laying out a sequence of definitions
Resulting in a sequence of patterns, each of which bind either id or a list of idv - as well as expr
The macro then uses the ~? fallthrough syntax to choose which syntax to produce in response.
(~? (define id expr)
(define-values (idv ...) expr)) ...
If id is not bound then the syntax containing idv will be produced instead.
The ellipsis syntax then repeats this for the whole list of patterns.
Previous iterations
I've unearthed an older version of this macro, which made use of recursive expansion
(define-syntax-parser define*
[(_ (id:id expr:expr) next ...+)
#'(begin
(define id expr)
(define* next ...))]
[(_ (id:id expr:expr))
#'(define id expr)])
Of course this macro does not support definitions that bind multiple identifiers at once - although it does handily demonstrate recursive macros.
I confirm that the code is under the same license as the Racket language, and associated text is under Creative Commons Attribution 4.0 International License
Contact
I've already submit a macro, but I'd like to continue contributing to this resource!
Macro
Make a sequence of definitions - similar to let*.
Example
Definitions are automatically dispatched either to
define
ordefine-values
depending on the manner in which identifiers are supplied (define-values
is used if the identifiers are contained within a set of parenthesis)Before and After
This macro saves a lot of unneccesary code when laying out a sequence of definitions
Inner workings
The macro works by accepting either type of clause (single or multiple values)
Resulting in a sequence of patterns, each of which bind either
id
or a list ofidv
- as well asexpr
The macro then uses the~?
fallthrough syntax to choose which syntax to produce in response.If
id
is not bound then the syntax containingidv
will be produced instead. The ellipsis syntax then repeats this for the whole list of patterns.Previous iterations
I've unearthed an older version of this macro, which made use of recursive expansion
Of course this macro does not support definitions that bind multiple identifiers at once - although it does handily demonstrate recursive macros.
Licence
I confirm that the code is under the same license as the Racket language, and associated text is under Creative Commons Attribution 4.0 International License
Contact
I've already submit a macro, but I'd like to continue contributing to this resource!