Julia Language Reimplementing the @show macro


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