Passing expression arguments

It is important to emphasize that macro arguments are passed as expressions rather than values. It may look confusing for beginners because macros are invoked similarly to functions, but the behavior is completely different. 

Let's make sure that we fully understand what this means. When calling a function with a variable, the value of the variable is passed into the function. Consider the following sample code for a showme function:

Now, let's create a @showme macro that does nothing but display the argument in the console. We can then compare the results with the preceding code:

As we can see, the results from running a macro are totally different than those we get from calling a function. The function argument x really only sees an expression from where the macro was called. From the diagram at the beginning of this section, we can see that macros are supposed to take in expressions and return a single expression as a result. They do not know the value of the arguments as they work at the syntax level. 

As we will see in the next section, expressions can even be manipulated when the macro is run. Let's go!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.15.135.63