January 2020
Intermediate to advanced
532 pages
13h 31m
English
Macros are defined in a similar way to how functions are defined, except that the macro keyword is used instead of the function keyword.
We should also keep in mind that a macro must return expressions. Let's create our first macro. This macro returns an expression object that contains a for loop, as follows:
macro hello() return :( for i in 1:3 println("hello world") end )end
Invoking the macro is as easy as calling it with the @ prefix. Refer to the following code:

Unlike functions, macros may be called without using parentheses. So we can just do the following:
Fantastic! We have now written our first macro. While ...
Read now
Unlock full access