# Why is the expression \`@foo.x\` parsed as \`macrocall . foo @x\` and not \`macrocall @foo .x\`?

**URL:** <https://discourse.julialang.org/t/why-is-the-expression-foo-x-parsed-as-macrocall-foo-x-and-not-macrocall-foo-x/82218>\
**Category:** Internals & Design\
**Tags:** question, macros, parsing\
**Created:** [June 4, 2022, 12:05am UTC](https://discourse.julialang.org/t/why-is-the-expression-foo-x-parsed-as-macrocall-foo-x-and-not-macrocall-foo-x/82218 "2022-06-04T00:05:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dylanxyz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dylanxyz/32/36646_2.png) [@dylanxyz](https://discourse.julialang.org/u/dylanxyz)\
**Post date:** [June 4, 2022, 12:05am UTC](https://discourse.julialang.org/t/why-is-the-expression-foo-x-parsed-as-macrocall-foo-x-and-not-macrocall-foo-x/82218/1 "2022-06-04T00:05:12Z")

</div>

I know Julia is not at that stage anymore, but i’m curious to know. And just to clarify the `macrocall @foo .x`, expression, i mean:

```julia
Expr
  head: Symbol macrocall
  args: Array{Any}((2,))
    1: Symbol @foo
    2: Expr
        head: Symbol .
        args: Array{Any}((1,))
            Symbol x

```

Edit: fixed expression mistake

---

<div class="post-metadata">

**Author:** ![cjdoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjdoris/32/213133_2.png) [@cjdoris](https://discourse.julialang.org/u/cjdoris)\
**Post date:** [June 4, 2022, 10:05am UTC](https://discourse.julialang.org/t/why-is-the-expression-foo-x-parsed-as-macrocall-foo-x-and-not-macrocall-foo-x/82218/2 "2022-06-04T10:05:21Z")

</div>

Because whitespace is important in Julia. `@foo.x` and `foo.@x` are the same thing (a macro call with 0 arguments) whereas `@foo .x` is a macro call with 1 argument, the same as `@foo(.x)`.

`.x` is a valid expression to the parser, it is used for relative imports like `using .Foo`.

---

<div class="post-metadata">

**Author:** ![CameronBieganek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cameronbieganek/32/6915_2.png) [@CameronBieganek](https://discourse.julialang.org/u/CameronBieganek)\
**Post date:** [June 4, 2022, 4:20pm UTC](https://discourse.julialang.org/t/why-is-the-expression-foo-x-parsed-as-macrocall-foo-x-and-not-macrocall-foo-x/82218/3 "2022-06-04T16:20:01Z")

</div>

To expand upon what @cjdoris said:

The syntaxes `Base.@kwdef` and `@Base.kwdef` are equivalent. They both refer to the macro `@kwdef`, which is defined in the `Base` module.

```julia
julia> :(Base.@kwdef) == :(@Base.kwdef)
true

julia> dump(:(Base.@kwdef))
Expr
  head: Symbol macrocall
  args: Array{Any}((2,))
    1: Expr
      head: Symbol .
      args: Array{Any}((2,))
        1: Symbol Base
        2: QuoteNode
          value: Symbol @kwdef
    2: LineNumberNode
      line: Int64 1
      file: Symbol REPL[2]

julia> dump(:(@Base.kwdef))
Expr
  head: Symbol macrocall
  args: Array{Any}((2,))
    1: Expr
      head: Symbol .
      args: Array{Any}((2,))
        1: Symbol Base
        2: QuoteNode
          value: Symbol @kwdef
    2: LineNumberNode
      line: Int64 1
      file: Symbol REPL[3]

```

However, I think it makes more sense to use the `Base.@kwdef` syntax.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [June 5, 2022, 4:46pm UTC](https://discourse.julialang.org/t/why-is-the-expression-foo-x-parsed-as-macrocall-foo-x-and-not-macrocall-foo-x/82218/4 "2022-06-05T16:46:25Z")

</div>

Using `@Module.macro` instead of `Module.@macro` strikes me as a bit of a legacy syntax and it’s kind of too bad we kept it for Julia 1.0, but yes, they mean the same thing and parse the same.

---

<div class="post-metadata">

**Author:** ![melonedo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/melonedo/32/15503_2.png) [@melonedo](https://discourse.julialang.org/u/melonedo)\
**Post date:** [June 19, 2022, 4:46pm UTC](https://discourse.julialang.org/t/why-is-the-expression-foo-x-parsed-as-macrocall-foo-x-and-not-macrocall-foo-x/82218/5 "2022-06-19T16:46:00Z")

</div>

This is surprising, I have never considered `Mod.@macro` to be valid before.
