Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macros should map between typed ASTs #119

Open
gelisam opened this issue Oct 21, 2020 · 1 comment
Open

macros should map between typed ASTs #119

gelisam opened this issue Oct 21, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@gelisam
Copy link
Owner

gelisam commented Oct 21, 2020

A macro is currently defined by a function of type Syntax -> Macro Syntax. This requires encoding arguments to other macros as Syntax values, and then parsing them back into values in the callee. This also precludes passing opaque values such as functions and Macro actions to another macro.

Inspired by this Twitter discussion, I suggest to generalize: a macro should instead be a function of type a -> Macro b. This implies that the (generated) code would have regions, a bit like in PHP where some regions contain HTML, others contain PHP code, others contain CSS, JavaScript, etc. Each region uses a different type (Syntax, or some other alternative) to represent its AST. A macro of type a -> Macro b must appear in a region whose AST is b, and delimits a region inside of which the AST is a.

One day this might be directly exposed to the user via reader macros, but as a first step, let's say that the user writes a program using Syntax's s-expressions as a surface syntax, that every form in that program is a macro, and that once everything is expanded, the result is a Core program which uses the Core as its AST, not Syntax. In between macros may introduce various other intermediate AST types as they find it convenient. For example, a public-facing macro may accept a Syntax, but delegate most of the work to an auxiliary macro which takes in the part of the Syntax which remains to be processed plus a Macro Syntax action as an accumulator argument. No problem: that auxiliary function can take a (Syntax, Macro Syntax) as an argument, and return whatever AST the public-facing macro returns.

@gelisam gelisam added the enhancement New feature or request label Oct 21, 2020
@gelisam
Copy link
Owner Author

gelisam commented Oct 21, 2020

As discussed, it should be f Identifer -> Macro (g Identifier), so that the macro-expander can implement hygiene by adding and flipping Scopes on all the relevant identifiers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant