# Order in which macros are processed

**URL:** <https://discourse.julialang.org/t/order-in-which-macros-are-processed/93530>\
**Category:** General Usage\
**Tags:** macros\
**Created:** [January 25, 2023, 7:03pm UTC](https://discourse.julialang.org/t/order-in-which-macros-are-processed/93530 "2023-01-25T19:03:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![brianguenter](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brianguenter/32/29519_2.png) [@brianguenter](https://discourse.julialang.org/u/brianguenter)\
**Post date:** [January 25, 2023, 7:03pm UTC](https://discourse.julialang.org/t/order-in-which-macros-are-processed/93530/1 "2023-01-25T19:03:45Z")

</div>

Given the following code in a file called “TestMacro.jl”:

```julia
module TestMacro
import Base

struct Glob end
export Glob

macro define()
    :(Base.:*(a::Glob, b::Glob) = "here")
end

@define

Base.:*(a::Glob, b::Glob) = "there"
end # module TestMacro

```

why is the output of this code “here” instead of “there”?

```julia
julia> using TestMacro
[Info: Precompiling TestMacro [85f89ff2-3dec-4fa1-bb05-16c45dba80a1]
WARNING: Method definition *(TestMacro.Glob, TestMacro.Glob) in module 
TestMacro at :\Users\seatt\OneDrive\Documents\temp\TestMacro\src\TestMacro.jl:7 
overwritten at c:\Users\seatt\OneDrive\Documents\temp\TestMacro\src\TestMacro.jl:12.
  **incremental compilation may be fatally broken for this module**

julia> a = Glob()
Glob()

julia> a*a
"here"

```

I expected the second definition of `Base.:*` would supersede that created by the call of the `@define` macro, since it comes after it in the file and there is a compiler warning saying that the times method has been redefined.

If the code is included in a fresh Julia session it executes as I would expect.

```julia
julia> include("src/TestMacro.jl")
Main.TestMacro

julia> a = TestMacro.Glob()
Main.TestMacro.Glob()

julia> a*a
"there"

```

Presumably this is caused by a difference between the way expressions are handled in the REPL vs. non-REPL. But what is the mental model one should use to predict the outcome?
