# Use @\_\_LINE\_\_ etc in another macro definition

**URL:** https://discourse.julialang.org/t/use-line-etc-in-another-macro-definition/41077
**Category:** General Usage
**Created:** [June 9, 2020, 3:20pm UTC](https://discourse.julialang.org/t/use-line-etc-in-another-macro-definition/41077 "2020-06-09T15:20:17Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![barfo](https://avatars.discourse-cdn.com/v4/letter/b/8baadc/32.png) [@barfo](https://discourse.julialang.org/u/barfo)
#### Post date: [June 9, 2020, 3:20pm UTC](https://discourse.julialang.org/t/use-line-etc-in-another-macro-definition/41077/1 "2020-06-09T15:20:17Z")

</div>

This has been up on First Steps for five days without eliciting a comment, hoping a wider audience can provide me some assistance…

How do I do this…

```
verbosity_tags = [....]
macro noise(tag, args...)
    return :(if $tag in verbosity_tags; println("$(basename(@ __FILE__ )): $(@ __LINE__ ): ", $(esc.(args)...)); end )
end

```

in such a way that **@FILE** & **@LINE** are expanded at the point @noise is used rather than at the point it is defined.

It seems clear that they should be wrapped in another layer of quoting to delay the expansion however my naive attempts to do so have failed.

I did manage to achieve what I wanted by assembling the macro body by hand using Expr et al. but that’s a rather clumsy way to do a pretty trivial thing.

jon.

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [June 9, 2020, 3:39pm UTC](https://discourse.julialang.org/t/use-line-etc-in-another-macro-definition/41077/2 "2020-06-09T15:39:20Z")

</div>

Use the implicit ` __source__ ` argument to macros:

```julia

julia> macro showsource()
           @show __source__.file __source__.line
       end
@showsource (macro with 1 method)

julia> @showsource();
__source__.file = Symbol("REPL[2]")
__source__.line = 1

julia> 1
1

julia> 

       @showsource();
__source__.file = Symbol("REPL[4]")
__source__.line = 3

```

---

<div class="post-metadata">

### Author: ![barfo](https://avatars.discourse-cdn.com/v4/letter/b/8baadc/32.png) [@barfo](https://discourse.julialang.org/u/barfo)
#### Post date: [June 10, 2020, 3:51am UTC](https://discourse.julialang.org/t/use-line-etc-in-another-macro-definition/41077/3 "2020-06-10T03:51:46Z")

</div>

I got to where I wanted with…

```
macro xxx(t, args...)
    if :($t); print("$(basename(string( __source__.file))): $( __source__.line): "); :( println($(esc.(args)...));) end
end

```

It had not occurred to me to quote only portions of the macro body thereby allowing **source** to be referenced. Still patching args… into a single call to println escaped me and I had to split it into two calls.

However, I would rather know how to reference @ **LINE** etc from another macro definition. Avoiding doing so is, well, avoiding the issue. If it can’t be done then that seems wrong to me.

In my old head it simply requires another layer of quoting to delay the expansion of @ **LINE** until the context is that of the invocation rather than the definition.

jon.
