Live
Black Hat USAAI BusinessBlack Hat AsiaAI BusinessMean field sequence: an introductionLessWrong AISwift package AI inference engine generated from Rust crateHacker News AI TopAI Tools That Actually Pay You Back: A Developer's Guide to Monetizing AIDev.to AIThe $6 Million Shockwave: How DeepSeek Just Broke the AI MonopolyMedium AIHow I Got My First Freelance Client in 3 Days (Using AI) — Beginner Guide (India 2026)Medium AIWhy Your Resume Gets Rejected Before a Human Sees It (And How to Fix It)Dev.to AII've Been Saying RAG Is Dead Since 2020Medium AIAI Print-on-Demand Passive Income: ₹400-2K/Design from HomeDev.to AIFaceless YouTube Automation with AI: Complete Guide 2026Dev.to AIWhy 40% of AI Projects Will Be Canceled by 2027Medium AIAutomate Churn Analysis and Win-Backs with AI-Powered PersonalizationDev.to AINo-Code vs. Custom Code: Which One Should You Actually Use for Your MVP?Dev.to AIBlack Hat USAAI BusinessBlack Hat AsiaAI BusinessMean field sequence: an introductionLessWrong AISwift package AI inference engine generated from Rust crateHacker News AI TopAI Tools That Actually Pay You Back: A Developer's Guide to Monetizing AIDev.to AIThe $6 Million Shockwave: How DeepSeek Just Broke the AI MonopolyMedium AIHow I Got My First Freelance Client in 3 Days (Using AI) — Beginner Guide (India 2026)Medium AIWhy Your Resume Gets Rejected Before a Human Sees It (And How to Fix It)Dev.to AII've Been Saying RAG Is Dead Since 2020Medium AIAI Print-on-Demand Passive Income: ₹400-2K/Design from HomeDev.to AIFaceless YouTube Automation with AI: Complete Guide 2026Dev.to AIWhy 40% of AI Projects Will Be Canceled by 2027Medium AIAutomate Churn Analysis and Win-Backs with AI-Powered PersonalizationDev.to AINo-Code vs. Custom Code: Which One Should You Actually Use for Your MVP?Dev.to AI
AI NEWS HUBbyEIGENVECTOREigenvector

Meta-Programming and Macro capabilities of various languages

DEV Communityby MagneApril 2, 20264 min read2 views
Source Quiz

Meta-programming = the broad idea of “programs that manipulate or generate programs” . It can happen at runtime (reflection) or compile-time (macros). Macros = one specific style of meta-programming, usually tied to transforming syntax at compile time (in a pre-processor or AST-transformer). It takes a piece of code as input and replaces it with another piece of code as output, often based on patterns or parameters. Rule‑based transformation: A macro is specified as a pattern (e.g., a template, an AST pattern, or token pattern) plus a replacement that is generated when that pattern is matched. Expansion, not function call: Macro use is not a runtime call; the macro is expanded before execution, so the final code is the result of replacing the macro invocation with its generated code. Here

Meta-programming = the broad idea of “programs that manipulate or generate programs”. It can happen at runtime (reflection) or compile-time (macros).

Macros = one specific style of meta-programming, usually tied to transforming syntax at compile time (in a pre-processor or AST-transformer). It takes a piece of code as input and replaces it with another piece of code as output, often based on patterns or parameters. Macros consist of:

  • Rule‑based transformation: A macro is specified as a pattern (e.g., a template, an AST pattern, or token pattern) plus a replacement that is generated when that pattern is matched.

  • Expansion, not function call: Macro use is not a runtime call; the macro is expanded before execution, so the final code is the result of replacing the macro invocation with its generated code.

Here are some programming languages and their meta-programming and macro capabilities.

NB! Take with a grain of salt. The result comes from working with perplexity.ai, and I have not had a chance to personally verify all of the cells. They do look generally correct to me overall, though. Corrections are welcome!

Metaprogramming + macro features

Here are the programming languages with their scores (out of 15) and links to their repos or homepages:

  • Racket: 15

  • Common Lisp (CL): 13

  • Scheme (R7RS‑small): 12

  • Rust: 11

  • Nim: 10

  • Clojure: 10

  • Carp: 9

  • Jai: 5

  • C++: 5

  • Zig: 4

  • Ruby: 4

Scores are out of 15 = 4 (metaprogramming) + 3 (compile‑time facilities) + 8 (macro features).

Each cell is either ✅ (yes) or – (no / limited).

Feature / language Racket Common Lisp Scheme (R7RS‑small) Rust Nim Clojure Carp Jai C++ Zig comptime

Ruby

Metaprogramming features:

Runtime metaprogramming (e.g., open classes, define_method, method hooks) ✅ ✅ – – – ✅ – – – – ✅

Runtime reflection / introspection ✅ ✅ ✅ – – ✅ – – ✅ – ✅

Runtime eval / dynamic code loading ✅ ✅ ✅ – – ✅ – – – – ✅

Build‑ or tooling‑level code generation supported ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅

Metaprogramming score (out of 4): 4 4 3 1 1 4 1 1 2 1 4

Compile‑time facilities (not strictly macros): Racket Common Lisp Scheme (R7RS‑small) Rust Nim Clojure Carp Jai C++ Zig comptime

Ruby

Run arbitrary code at compile time ✅ ✅ ✅ ✅ ✅ – ✅ ✅ ✅ (constexpr) ✅ –

Types as values at compile time ✅ (– but in Typed Racket) – – ✅ ✅ – – ✅ ✅ (constexpr + templates) ✅ –

constexpr‑style type‑level / compile‑time computation ✅ – – ✅ (const‑eval) ✅ – ✅ ✅ ✅ (via constexpr) ✅ –

Macro features:

Hygienic identifier binding ✅ ✅ ✅ ✅ ✅ ✅ ✅ (gensym but manual) ✅ – – –

Operate on AST / syntax tree ✅ ✅ ✅ ✅ ✅ ✅ ✅ – – – –

Pattern‑based transformations ✅ ✅ ✅ ✅ ✅ ✅ ✅ – – – –

Define new syntactic forms ✅ ✅ ✅ ✅ ✅ ✅ ✅ – – – –

Define new keywords / syntax ✅ ✅ ✅ ✅ ✅ ✅ ✅ – – – –

Override core language forms ✅ ✅ ✅ – – – – – – – –

Multi‑phase / macros of macros ✅ ✅ ✅ ✅ – – – – – – –

Full‑fledged DSL / language building (via macros) ✅ ✅ ✅ ✅ ✅ ✅ ✅ – – – –

Macro & compile time features score (out of 11) 11 9 9 10 9 6 6 4 3 3 0

Total score 15 13 12 11 10 10 9 5 5 4 4

Racket Common Lisp Scheme (R7RS‑small) Rust Nim Clojure Carp Jai C++ Zig comptime

Ruby

The score counts one point per row where the language can reasonably do what the feature describes (DSL‑building is counted as a full feature, even if “limited” in some languages).

The feature score is not an ultimate measure of meta-programming power, since a language (like C++) may have a higher score than another language (like Ruby), but generally be considered less tailored for meta-programming than the other language (Ruby is generally revered for its powerful meta-programming abilities).

Macro features are varied and many, and thus in the total score they gain an undue weight, although runtime meta-programming may be just as, or even more, powerful.

Lisp-style languages (with their homoiconic S-expressions) make out 5 of the 11 languages in our list: Racket, CL, Scheme, Clojure, Carp.

For further reading: https://github.com/oils-for-unix/oils/wiki/Metaprogramming

Was this article helpful?

Sign in to highlight and annotate this article

AI
Ask AI about this article
Powered by Eigenvector · full article context loaded
Ready

Conversation starters

Ask anything about this article…

Daily AI Digest

Get the top 5 AI stories delivered to your inbox every morning.

More about

transformerfeaturecode generation

Knowledge Map

Knowledge Map
TopicsEntitiesSource
Meta-Progra…transformerfeaturecode genera…perplexityDEV Communi…

Connected Articles — Knowledge Graph

This article is connected to other articles through shared AI topics and tags.

Knowledge Graph100 articles · 184 connections
Scroll to zoom · drag to pan · click to open

Discussion

Sign in to join the discussion

No comments yet — be the first to share your thoughts!

More in Products