Open shhyou opened 3 years ago
That's nice!
Is there a particular reason why :id
is not included in the syntax class directly? That would avoid the need for (and _:id ...)
.
Some macros may let
-bind subforms to first evaluate them for later use. Therefore the subforms can be any expressions. I couldn't find a way to pass syntax classes around or compose them, so the _:id
specification is left out of the syntax class.
Macro
Some macros need to generate a sequence of fresh identifiers corresponding to a list of input forms. The standard solution is invoking
generate-temporaries
with a syntax list and bind the result to a new pattern variable. However, the new pattern variable is disconnected from the input forms and such an approach quickly becomes unmanageable when the input forms come nested in more than one ellipses.By delegating the work to syntax classes, the syntax attributes tightly couples the generate identifiers with the input forms (and they even have DrRacket binding arrows). Moreover, repetition handling is entirely done by syntax/parse, thereby simplifying the code.
Example
In this example, we create a
define/immutable-parameter
form for defining function while disabling mutation of the parameters throughmake-variable-like-transformer
.The macro
define/immutable-parameter
parses the argumentsarg
withfresh-variable
to generate temporary identifiers on-the-fly. Each of the fresh identifier is directly paired with the original identifier through syntax attributes.Licence
I license the code in this issue under the same MIT License that the Racket language uses and the texts under the Creative Commons Attribution 4.0 International License