I hope you enjoyed this section on getting an understanding of how macros are created and how they work.
We are now going to go over the solution for the assignment for this section.
The question is create a macro called OP that takes three arguments.
All three arguments will be integers.
But the third argument is going to be how we tell the macro what operation to perform.
Operation one is add.
Operation two is subtract, three is multiply, four is divide and five is mod.
So I went ahead and put all of the example outputs that we are looking for and to Main so now that we
can create our macro rule.
So we start off by saying macro rules, we give it a name.
In this case it is going to be OP and now we are going to specify the parameters that we want.
So we will say a.
B and C, which is going to be how we specify what operation we want to perform on A and B, so now
we can very easily just run a match block on all of these.
And we will say one is going to return A plus B, you need to put that dollar sign.
Two is going to return A minus B, three is going to return A times B, four is going to return a divide
by B, five is going to return the mod A, mod
B, and then if any other value is passed in, that is not one, two, three, four, five, we will
just return negative one so that we know that we passed in some unexpected operation.
So now if we run our macro, we expect to get the appropriate values of seven, three, 10 to 1, and
then negative one.
So I hope you enjoyed this assignment on creating your own custom macro that is going to allow you to
specify what operation to run on to arbitrary values.