Challenge: Writing Your Own Macro

Complete the challenge to create your own macro.

We'll cover the following

Description

We already saw that we implement macros whenever there’s a functionality that we’re going to use extensively and it makes sense to have an abstraction in that way. Taking all this into consideration, you’re now going to create an improvement to the println function.

The println function is a core function that prints to the console whatever data is being passed as an argument. However, there are many times when we want to only know the value of a variable or what’s being returned by a function. Today, this is only possible by including the print of this variable as one more line of code and repeating the structure that we want to see because the println function doesn't return anything.

So, an interesting macro to create would be print-and-return, which would print the structure and return this same structure. This way, we could add this new macro as a function around the variable that we want to see without having to create an extra line. Let’s look closer to at a code showing the usage of the macro.

Get hands-on with 1200+ tech skills courses.