# How do I get the current variable value within a macro?

**URL:** <https://discourse.julialang.org/t/how-do-i-get-the-current-variable-value-within-a-macro/103487>\
**Category:** General Usage\
**Tags:** macros\
**Created:** [September 3, 2023, 4:53pm UTC](https://discourse.julialang.org/t/how-do-i-get-the-current-variable-value-within-a-macro/103487 "2023-09-03T16:53:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Post date:** [September 3, 2023, 4:53pm UTC](https://discourse.julialang.org/t/how-do-i-get-the-current-variable-value-within-a-macro/103487/1 "2023-09-03T16:53:20Z")

</div>

```julia
macro getvar(x)
    println(x)
    return nothing
end

x = 1

@getvar x

```

`getvar` sees `x` as a symbol and prints out “x” as expected.

Now, let’s assume I need the `x` **value** for some further logic within the macro (not within the expression returned by the macro, but before I build the expression)? How do I get it?

---

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [September 3, 2023, 4:55pm UTC](https://discourse.julialang.org/t/how-do-i-get-the-current-variable-value-within-a-macro/103487/2 "2023-09-03T16:55:09Z")

</div>

You don’t, that’s the whole point of macros. They operate only on the syntax representation of code, and are run before the variable `x` ever gets a value.
