# Calling a macro inside of a macro

**URL:** <https://discourse.julialang.org/t/calling-a-macro-inside-of-a-macro/95729>\
**Category:** General Usage\
**Tags:** metaprogramming\
**Created:** [March 8, 2023, 11:29am UTC](https://discourse.julialang.org/t/calling-a-macro-inside-of-a-macro/95729 "2023-03-08T11:29:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![brunbjerg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brunbjerg/32/53205_2.png) [@brunbjerg](https://discourse.julialang.org/u/brunbjerg)\
**Post date:** [March 8, 2023, 11:29am UTC](https://discourse.julialang.org/t/calling-a-macro-inside-of-a-macro/95729/1 "2023-03-08T11:29:30Z")

</div>

Hello

I am finding myself debugging at large Julia codebase and for some reason I still debug like a 2nd year undergraduate. For that reason I would like to make a macro that looks some thing like this:

```julia
macro pp(input)
    :(println("File: ", @ __FILE__ , "Line: ", @ __LINE__ , " ", <variable name of input>, " ", <actual value of input>))
end

```

The idea is that I can compare variables across multiple files quickly and find their location, but I cannot get it to work probably as the @\_\_FILE \_\_ and @\_\_LINE \_\_ macros refer to the file and line of the macro definition. (A kind of related question: how to get the variable name of the input of the macro?) A minimal working example could be:

```julia
macro pp(input)
    :(println("Line: ", @ __LINE__ , "Name: ", " <name of input> " , $input))
end

a = 1; @pp a

```

Which returns:

```julia
Line: 2 Name: <name of input> 1

```

Does anyone know a good approach for these kinds of macros, I find my self trying every kind of combination of esc(), $ and : to get it to work.

Kind regards

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [March 8, 2023, 11:35am UTC](https://discourse.julialang.org/t/calling-a-macro-inside-of-a-macro/95729/2 "2023-03-08T11:35:53Z")

</div>

See [Module/file/line for log message generated by a macro](https://discourse.julialang.org/t/module-file-line-for-log-message-generated-by-a-macro/63835) and [Use @\_\_LINE\_\_ etc in another macro definition](https://discourse.julialang.org/t/use-line-etc-in-another-macro-definition/41077) (although that is not specifically about “calling macro from another macro”, but it does solve your problem).

---

<div class="post-metadata">

**Author:** ![brunbjerg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brunbjerg/32/53205_2.png) [@brunbjerg](https://discourse.julialang.org/u/brunbjerg)\
**Post date:** [March 8, 2023, 11:42am UTC](https://discourse.julialang.org/t/calling-a-macro-inside-of-a-macro/95729/3 "2023-03-08T11:42:23Z")

</div>

What a Champ!

I got:

```julia
macro pp(input)
    file = basename(String( __source__.file))
    line = __source__.line
    quote
        println("File: ", $file, " Line: ", $line, " Name: ", $(Meta.quot(input)) , " Value: ", $esc(input))
    end
end

```

Which gives:

```julia
a = 1; @pp a

File: print_macro.jl Line: 9 Name: a Value: 1

```
