What are Julia macros and how do they differ from functions?

Updated May 16, 2026

Short answer

Macros operate on code before execution, while functions operate on runtime values.

Deep explanation

Macros in Julia perform metaprogramming by transforming expressions at parse/compile time. They receive AST (Abstract Syntax Tree) expressions and return modified expressions, enabling domain-specific optimizations.

Real-world example

Used in performance tools like @time and @benchmark.

Common mistakes

  • Confusing macro execution timing with function execution.

Follow-up questions

  • Why are macros powerful in Julia?

More Julia interview questions

View all →