# Scope of @time

**URL:** <https://discourse.julialang.org/t/scope-of-time/38261>\
**Category:** General Usage\
**Tags:** question\
**Created:** [April 26, 2020, 8:50pm UTC](https://discourse.julialang.org/t/scope-of-time/38261 "2020-04-26T20:50:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ken\_Lin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ken_lin/32/14367_2.png) [@Ken\_Lin](https://discourse.julialang.org/u/Ken_Lin)\
**Post date:** [April 26, 2020, 8:50pm UTC](https://discourse.julialang.org/t/scope-of-time/38261/1 "2020-04-26T20:50:22Z")

</div>

Is the scope of `@time` supposed to be local?

If I do the following:

```julia
x = 1
@time x = 2

```

Then the value of x will be 2. Why can I modify the value of a global variable x in a local scope `@time`?

Similarly, I can declare variables under `@time` and access them outside `@time`. For example,

`@time v = 3`  
Then the value of v will be 3. Why can I access the local variable v?

In contrast, I can’t do the above in `@profile`.

Thank you.

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [April 26, 2020, 9:01pm UTC](https://discourse.julialang.org/t/scope-of-time/38261/2 "2020-04-26T21:01:20Z")

</div>

Macros can do whatever they want (well, not quite). So, they can choose to introduce a new scope or not. You can have a look to what `@time` expands to with `@macroexpand @time x=1`. There is no scope-defining block defined, thus no new scope is made. This contrasts to `@profile` which uses a `try-finally` block which does introduce a new scope.

---

<div class="post-metadata">

**Author:** ![Ken\_Lin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ken_lin/32/14367_2.png) [@Ken\_Lin](https://discourse.julialang.org/u/Ken_Lin)\
**Post date:** [April 26, 2020, 9:18pm UTC](https://discourse.julialang.org/t/scope-of-time/38261/3 "2020-04-26T21:18:15Z")

</div>

Thanks!
