mcpField
E
elixir-meta-programming

elixir-meta-programming

github.com/pproencaDevelopment21874 installsUpdated 11w ago
Repository

About elixir-meta-programming

A reference skill for writing Elixir macros and declarative DSLs when functions cannot provide the needed syntax or compile-time behavior. It gives focused rules for quote hygiene, DSL generation, and compile-time validation.

Key features

  1. 01Macro design and runtime delegation
  2. 02Quote evaluation and hygiene
  3. 03Declarative DSL construction
  4. 04Compile-time validation and error locations

Use cases

  1. 01Implementing an Elixir macro
  2. 02Generating module code from declarations
  3. 03Reviewing macro evaluation and hygiene
  4. 04Reporting DSL errors at the caller’s source line

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/pproenca/dot-skills --skill elixir-meta-programming

After installing, type/elixir-meta-programmingin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

AGENTS.md
metadata.json
assets/templates/
_template.md
references/
_sections.md
dsl-accumulate-attributes.md
dsl-introspection-function.md
dsl-unquote-fragments.md
dsl-using-minimal.md
macro-defguard-for-guards.md
macro-thin-delegate-runtime.md
quote-bind-quoted-single-eval.md
quote-escape-runtime-data.md
quote-rely-on-hygiene.md
valid-fail-at-compile-time.md
valid-locate-errors-at-caller.md

Details

From the project README

Elixir Metaprogramming & DSLs

How to build Elixir macros and declarative DSLs correctly — for the case where a macro is genuinely warranted and a plain function won't do. Each rule corrects a specific wrong default a capable model makes once it starts writing quote/unquote, __using__, and @before_compile; nothing here restates macro basics the model already knows.

First: is a macro actually warranted?

The default answer is no — reach for a higher-order function, a behaviour, or data-plus-an-interpreter first. That gate is not this skill's job; it lives in the sibling skills and you should apply it before opening this one:

  • staff-level-elixir → data-functions-over-macros (solve it with a function first)
  • adversarial-elixir → meta-functions-not-macro-dsl, meta-use-is-not-import, meta-no-compile-time-coupling

A macro earns its place only when you need something a function cannot give — new syntax, control over whether/when arguments evaluate, or code that must exist at compile time (compiling a schema, generating clauses from a declaration list). Once you've crossed that threshold, this skill is how you do it right.

When to Apply

  • Writing a macro — deciding what goes in the quote block versus a runtime function, and how arguments evaluate
  • Building a declarative DSL — a schema/spec/route/workflow block that collects declarations and generates a module
  • Wiring use MyDSL — what __using__ should inject and what belongs in @before_compile
  • Generating functions or clauses from a list of declarations at compile time
  • Making a DSL fail at mix compile with an error that points at the user's source
  • Reviewing existing macro/DSL code for evaluation, hygiene, escaping, and compile-time-validation bugs

Rule Categories

#CategoryPrefixCovers
1Macro DesignmacroThe shape of a single macro — thin macro over a runtime function; defguard for guard-safe constructs
2Quote & HygienequoteCompile-time semantics traps — multiple evaluation, Macro.escape, hygiene vs var!
3DSL ConstructiondslAssembling a block DSL — accumulating attributes + @before_compile, minimal __using__, unquote fragments, introspection
4Compile-Time ValidationvalidFailing well — validate while compiling, locate errors at the caller's line

Quick Reference

1. Macro Design
2. Quote & Hygiene
3. DSL Construction
4. Compile-Time Validation

How to Use

Read a reference file when its decision comes up. Each rule names the wrong default it corrects, then shows the canonical way (with an Incorrect/Correct contrast only where the wrong way is a real trap).

Related Skills

  • staff-level-elixir — the broader Elixir/OTP/Ecto/Phoenix judgment skill; owns the "prefer a function over a macro" gate
  • adversarial-elixir — architecture-level review that flattens unnecessary macro DSLs; the diagnostic counterpart to this skill

Reference Files

FileDescription
references/_sections.mdCategory definitions and ordering
assets/templates/_template.mdTemplate for new rules
metadata.jsonVersion and source references

Comments

Markdown supported