2 + 3
5
Marie-Hélène Burle
Julia code is itself data and can be manipulated by the language while it is running.
Let’s start with something simple:
How is this run internally?
The string "2 + 3"
gets parsed into an expression:
Then that expression gets evaluated:
They resemble functions and just like functions, they accept as input a tuple of arguments.
BUT macros return an expression which is compiled directly rather than requiring a runtime eval
call.
So they execute before the rest of the code is run.
Macro’s names are preceded by @
(e.g. @time
).
Julia comes with many macros and you can create your own with:
As with functions, Julia suggests to use lower case, without underscores, as macro names.