Introduction to metaprogramming in Julia
2021-07-27 , Red

Metaprogramming is a key technique that intermediate to advanced Julia users sometimes need -- although not as often as they think!

This will be a tutorial introduction to metaprogramming, analyzing, from the bottom up, key topics such as the structure of Julia expressions, how and when to use (and not use) generated functions and macros, and touching on more recent techniques like use of Symbolics.jl and MLStyle.jl.


Metaprogramming is an important skill that intermediate to advanced Julia users sometimes need to use. This tutorial will be an introduction at the intermediate level, aiming to answer clearly questions such as:

  • What is metaprogramming?
  • When and why should I use it?
  • When should I not use it? (See Steven Johnson's keynote from JuliaCon 2019.)
  • What are macros for, and how do they work?
  • What is macro hygiene and how should I use it?
  • How can I write a function that recursively analyses a syntax tree?
  • When should I use a generated function?
  • How can I get access to the code for a function that is already defined?
  • Are there packages that can make this simpler? (Brief sketch)

The goal is to provide a firm foundation of understanding that can then be built on later with more advanced applications (not covered in the workshop). The aim is to provide a relatively pedestrian, but easy to follow, path to understanding, rather than to apply powerful, but difficult to understand, functional techniques.

We will provide simple examples of metaprogramming applied to interesting questions in scientific computing, always aiming for simple examples and explanations.

Professor of Computational Science at the Universidad Nacional Autónoma de México and visiting professor at MIT.

Interested in computational science, interval arithmetic, and numeric-symbolic computing.

Author of the JuliaIntervals suite of packages for interval arithmetic, and various tutorials on Julia.

This speaker also appears in: