Defining macros

In previous chapters, we have already used macros, such as @printf, in Chapter 2, Variables, Types, and Operations, and @time in Chapter 3, Functions. Macros are like functions, but instead of values they take expressions (which can also be symbols or literals) as input arguments. When a macro is evaluated, the input expression is expanded, that is, the macro returns a modified expression. This expansion occurs at parse time when the syntax tree is being built, not when the code is actually executed.

The following descriptions highlight the difference between macros and functions when they are called or invoked:

  • Function: It takes the input values and returns the computed values at runtime
  • Macro: It takes the input expressions ...

Get Julia 1.0 Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.