# UndefVarError with @. macro. Needs to pre-declare the assigned variable?

**URL:** <https://discourse.julialang.org/t/undefvarerror-with-macro-needs-to-pre-declare-the-assigned-variable/10683>\
**Category:** New to Julia\
**Created:** [May 3, 2018, 1:41pm UTC](https://discourse.julialang.org/t/undefvarerror-with-macro-needs-to-pre-declare-the-assigned-variable/10683 "2018-05-03T13:41:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pierre-haessig](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pierre-haessig/32/217129_2.png) [@pierre-haessig](https://discourse.julialang.org/u/pierre-haessig)\
**Post date:** [May 3, 2018, 1:41pm UTC](https://discourse.julialang.org/t/undefvarerror-with-macro-needs-to-pre-declare-the-assigned-variable/10683/1 "2018-05-03T13:41:22Z")

</div>

Hi,

I’m fairly new to Julia (my main language is Python). I’m struggling with a problem that is probably pretty basic with regard to macro usage. I’m on Julia 0.6.2.

In particular for the `@.` macro, if I run:

```julia
@. x = (abs([1 2 3]) <= 1)

```

I get a `ERROR: UndefVarError: x not defined`. If x is defined before, this runs fine. Is it a well-know fact that the assigned variable needs to be predeclared for using with `@.`?

I’ve found seamingly related questions on StackOverflow ([Broken macro functionality in Julia v0.6](https://stackoverflow.com/questions/45115088/broken-macro-functionality-in-julia-v0-6) and [Julia macro expansion inside function](https://stackoverflow.com/questions/49893132/julia-macro-expansion-inside-function)) and a PR [15850](https://github.com/JuliaLang/julia/pull/15850) about a change of “macro hygiene” in 0.6 that generated similar `UndefVarError` errors in various modules. But in the end, I cannot relate these to my problem.

Thanks for your kind help.  
Pierre

---

<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:** [May 3, 2018, 1:46pm UTC](https://discourse.julialang.org/t/undefvarerror-with-macro-needs-to-pre-declare-the-assigned-variable/10683/2 "2018-05-03T13:46:40Z")

</div>

```julia
julia> x = @. (abs([1 2 3]) <= 1)
1×3 BitArray{2}:
 true false false

```

`x .= ` is inplace assignment.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [May 3, 2018, 2:00pm UTC](https://discourse.julialang.org/t/undefvarerror-with-macro-needs-to-pre-declare-the-assigned-variable/10683/3 "2018-05-03T14:00:46Z")

</div>

```julia
@. x = (abs([1 2 3]) <= 1)

```

expands to the equivalent of (roughly)

```julia
let z = [1, 2, 3]
    for i in 1:3 
        x[i] = abs(z[i] <= 1)
    end
end

```

so `x` needs to exist.

---

<div class="post-metadata">

**Author:** ![pierre-haessig](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pierre-haessig/32/217129_2.png) [@pierre-haessig](https://discourse.julialang.org/u/pierre-haessig)\
**Post date:** [May 3, 2018, 2:33pm UTC](https://discourse.julialang.org/t/undefvarerror-with-macro-needs-to-pre-declare-the-assigned-variable/10683/4 "2018-05-03T14:33:54Z")

</div>

Thanks a lot!

I had missed the fact that `=` was also “dotted” by the `@.` macro, and I didn’t have in mind that `.=` is inplace assignement.
