You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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.
A macro is currently defined by a function of type
Syntax -> Macro Syntax
. This requires encoding arguments to other macros asSyntax
values, and then parsing them back into values in the callee. This also precludes passing opaque values such as functions andMacro
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 typea -> Macro b
must appear in a region whose AST isb
, and delimits a region inside of which the AST isa
.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 aCore
program which uses theCore
as its AST, notSyntax
. In between macros may introduce various other intermediate AST types as they find it convenient. For example, a public-facing macro may accept aSyntax
, but delegate most of the work to an auxiliary macro which takes in the part of theSyntax
which remains to be processed plus aMacro 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.The text was updated successfully, but these errors were encountered: