# Why isn't 10^6 evaluated at compile time?

**URL:** <https://discourse.julialang.org/t/why-isnt-10-6-evaluated-at-compile-time/40124>\
**Category:** Performance\
**Created:** [May 25, 2020, 1:17pm UTC](https://discourse.julialang.org/t/why-isnt-10-6-evaluated-at-compile-time/40124 "2020-05-25T13:17:47Z")\
**Posts on this page:** 2\
**Page:** 2

<div class="post-metadata">

**Author:** ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Post date:** [May 25, 2020, 11:04pm UTC](https://discourse.julialang.org/t/why-isnt-10-6-evaluated-at-compile-time/40124/21 "2020-05-25T23:04:28Z")

</div>

Why isn’t `@eval` as fast as the eval macro from @Mason?

---

<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:** [May 25, 2020, 11:12pm UTC](https://discourse.julialang.org/t/why-isnt-10-6-evaluated-at-compile-time/40124/22 "2020-05-25T23:12:29Z")

</div>

If you write `f(x) = x * @eval 10^6`, Julia can’t know that it’s safe to do the `eval` at parse time, it has to wait until the function is actually running. Notice that my macro doesn’t return `:(eval($ex))`, it first runs `eval(ex)` and then returns that result, so

```julia
julia> @macroexpand @eval_at_parse_time 10^6
1000000

```

whereas

```julia
julia> @macroexpand @eval 10^6
:((Base.Core).eval(Main, $(Expr(:copyast, :($(QuoteNode(:(10 ^ 6))))))))

```

that’s why the above macro is only really useful for evaluating stuff involving literals. You can’t use local variables, or even global varaibles / functions that are defined after `f`.

[Previous page](https://discourse.julialang.org/t/why-isnt-10-6-evaluated-at-compile-time/40124.md?page=1)
