agentleFS
rainoftimerainoftime/pl-skills/macro-expander/SKILL.md

macro-expander

Skill17 starsChanged 9 months agoApache-2.0View on GitHub

Implement macro systems for syntactic abstraction and code generation at compile time.

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 4 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use hygiene to prevent capture

    line 43
  2. Distinctive:

    Prefer pattern-based macros for clarity

    line 44
  3. Distinctive:

    Test macro expansion thoroughly

    line 46
  4. Distinctive:

    When debugging is important

    line 85

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Macro Expander

Macro systems enable syntactic abstraction by transforming code at compile time. They allow programmers to extend the language with new syntactic constructs.

When to Use This Skill

  • Building DSLs (Domain-Specific Languages)
  • Reducing boilerplate code
  • Implementing language extensions
  • Code generation
  • Compile-time computation

What This Skill Does

  1. Macro Definition: Define syntax transformers
  2. Macro Expansion: Transform macro calls into base syntax
  3. Hygiene: Prevent unintended variable capture
  4. Pattern Matching: Match macro input patterns
  5. Recursive Expansion: Handle nested macros

Key Concepts

ConceptDescription
MacroSyntax transformer
HygienePrevents unintended variable capture
Pattern VariablePlaceholder in macro pattern
ExpansionTransform macro call to base syntax
TemplateOutput pattern for macro

Tips

  • Use hygiene to prevent capture
  • Prefer pattern-based macros for clarity
  • Document macro contracts
  • Test macro expansion thoroughly
  • Consider compile-time errors

Common Use Cases

  • DSL implementation
  • Boilerplate reduction
  • Language extensions
  • Conditional compilation
  • Code generation

Related Skills

  • parser-generator - Macros need AST
  • dsl-embedding - DSLs via macros
  • multi-stage-programming - Staged computation

Canonical References

ReferenceWhy It Matters
Kohlbecker et al. "Hygienic macro expansion"Original hygiene paper
Dybvig et al. "Syntactic abstraction in Scheme"Scheme macros
Rust macro documentationModern procedural macros

Tradeoffs and Limitations

Approach Tradeoffs

ApproachProsCons
Textual macrosSimpleUnhygienic
Hygienic macrosSafeComplex
Procedural macrosPowerfulHard to debug

When NOT to Use This Skill

  • When functions suffice
  • For simple syntactic sugar
  • When debugging is important

Limitations

  • Hygiene is hard to get right
  • Error messages can be cryptic
  • Macro expansion can be slow

Assessment Criteria

A high-quality implementation should have:

CriterionWhat to Look For
HygienePrevents capture
ComposabilityMacros expand macros
Error handlingClear error messages
EfficiencyReasonable expansion time

Quality Indicators

✅ Good: Hygienic, pattern-based, good errors ⚠️ Warning: Sometimes captures variables ❌ Bad: Unhygienic, cryptic errors

Research Tools & Artifacts

Real-world macro systems:

ToolWhy It Matters
Racket macrosAdvanced macro system
Rust proc-macrosRust macro system
C preprocessorOriginal textual macros
Clang/LLVMMacro system for C

Key Systems

  • Racket: Scheme macros
  • Julia macros: Lisp-style macros

Research Frontiers

Current macro research:

DirectionKey PapersChallenge
** hygiene**"Hygienic Macros"Sound hygiene
Generative"Generative Macros"Type generation
Typed"Typed Macros"Type-safe macros

Hot Topics

  1. Macro ML: ML with macros
  2. Wasm macros: WebAssembly macros

Implementation Pitfalls

Common macro bugs:

PitfallReal ExamplePrevention
CaptureVariable captureHygiene
OrderMacro orderPhase separation

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.