Skip to content

Deprecate macro #36259

@zenna

Description

@zenna

I propose to deprecate macro both as a construct and as a concept.

I came to this idea from the fact that whenever I write a macro that macro often does nothing more than call a function which does the actual code transformation. That way it's much easier to debug, and if I need to use the transformation in a non-macro setting I can easily do so.

My suggestion is simple:

  1. There are no macros, just normal functions that transform Exprs
  2. The @somefunction(someexpr) syntax will transform that someexpr in exactly the way it does now.

The conceptual change is going away from the idea of a macro as an entity, and moving all the work it does into the special semantics of the calling of that function (to do the code substitution).

I would imagine that this isn't much of a change in implementation to what is going on now, but I think it brings some conceptual clarity and some practical benefits:

  • As I said above, we would mean we wouldn't have arbitrary decisions about what goes in a macro and what goes in a function
  • If I or someone else writes code-transformation that I want to use I can do so more easily if its in function form that if its in macroform
  • It's easier to understand. We don't need to teach newcomers that macros are just functions that transform expressions, because they would obviously be functions that just transform expressions

My guess is that we got to the current situation by a quirk. We adopted define-macro from scheme but did not adopt scheme's behaviour of having no special syntax for applying macros. Put differently, scheme could not get rid of define-macro because it has no syntax to make the differentiation that macro substitution happens at a different stage of compilation/interpretation.

I'm of course open to the possibility that there is some glaring problem with this proposal that I haven't seen. On slack @oxinabox noted that one problem could be that in current code there is a lot of overlap between function names and macro names, This is true, but I think a relatively small problem. Besides, we have multiple dispatch we could in most cases just specialise.

Deprecating macros would be a breaking change of course. One non-breaking change would be the ability to call code transforming functions as using some variant of the @ syntax

Metadata

Metadata

Assignees

No one assigned

    Labels

    designDesign of APIs or of the language itselfmacros@macrosspeculativeWhether the change will be implemented is speculative

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions