Julia Language Metaprogramming Reimplementing the @show macro

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

In Julia, the @show macro is often useful for debugging purposes. It displays both the expression to be evaluated and its result, finally returning the value of the result:

julia> @show 1 + 1
1 + 1 = 2
2

It is straightforward to create our own version of @show:

julia> macro myshow(expression)
           quote
               value = $expression
               println($(Meta.quot(expression)), " = ", value)
               value
           end
       end

To use the new version, simply use the @myshow macro:

julia> x = @myshow 1 + 1
1 + 1 = 2
2

julia> x
2


Got any Julia Language Question?