January 2020
Intermediate to advanced
532 pages
13h 31m
English
In the REPL, any macro is expanded as soon as we invoke it. Interestingly, when a function containing the macro is defined, the macro is expanded as part of the function definition process.
We can see this in action by developing a simple @identity macro that returns whatever expression is passed into it. Right before the expression is returned, we just dump the object to the screen. The code for the @identity macro is as follows:
macro identity(ex) dump(ex) return exend
Since this macro returns the same expression that was passed, it should end up executing the original source code that follows the macro.
Now, let's define a function that uses the @identity macro:
Clearly, the compiler has figured out that the ...
Read now
Unlock full access