1 00:00:05,620 --> 00:00:11,800 I hope you enjoyed this section on getting an understanding of how macros are created and how they work. 2 00:00:12,160 --> 00:00:17,320 We are now going to go over the solution for the assignment for this section. 3 00:00:17,590 --> 00:00:22,210 The question is create a macro called OP that takes three arguments. 4 00:00:22,630 --> 00:00:24,790 All three arguments will be integers. 5 00:00:24,790 --> 00:00:30,340 But the third argument is going to be how we tell the macro what operation to perform. 6 00:00:30,940 --> 00:00:32,890 Operation one is add. 7 00:00:33,070 --> 00:00:40,360 Operation two is subtract, three is multiply, four is divide and five is mod. 8 00:00:41,500 --> 00:00:49,990 So I went ahead and put all of the example outputs that we are looking for and to Main so now that we 9 00:00:49,990 --> 00:00:52,180 can create our macro rule. 10 00:00:52,180 --> 00:00:55,780 So we start off by saying macro rules, we give it a name. 11 00:00:55,780 --> 00:01:03,310 In this case it is going to be OP and now we are going to specify the parameters that we want. 12 00:01:03,310 --> 00:01:05,200 So we will say a. 13 00:01:08,410 --> 00:01:20,440 B and C, which is going to be how we specify what operation we want to perform on A and B, so now 14 00:01:20,440 --> 00:01:26,410 we can very easily just run a match block on all of these. 15 00:01:26,410 --> 00:01:36,920 And we will say one is going to return A plus B, you need to put that dollar sign. 16 00:01:36,940 --> 00:01:59,290 Two is going to return A minus B, three is going to return A times B, four is going to return a divide 17 00:02:00,610 --> 00:02:07,960 by B, five is going to return the mod A, mod 18 00:02:10,240 --> 00:02:17,440 B, and then if any other value is passed in, that is not one, two, three, four, five, we will 19 00:02:17,440 --> 00:02:25,270 just return negative one so that we know that we passed in some unexpected operation. 20 00:02:28,630 --> 00:02:39,160 So now if we run our macro, we expect to get the appropriate values of seven, three, 10 to 1, and 21 00:02:39,160 --> 00:02:40,360 then negative one. 22 00:02:40,480 --> 00:02:48,280 So I hope you enjoyed this assignment on creating your own custom macro that is going to allow you to 23 00:02:48,280 --> 00:02:53,260 specify what operation to run on to arbitrary values.