# Assigning a macro to a variable

**URL:** <https://discourse.julialang.org/t/assigning-a-macro-to-a-variable/3773>\
**Category:** General Usage\
**Created:** [May 17, 2017, 3:21pm UTC](https://discourse.julialang.org/t/assigning-a-macro-to-a-variable/3773 "2017-05-17T15:21:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wsshin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wsshin/32/360_2.png) [@wsshin](https://discourse.julialang.org/u/wsshin)\
**Post date:** [May 17, 2017, 3:21pm UTC](https://discourse.julialang.org/t/assigning-a-macro-to-a-variable/3773/1 "2017-05-17T15:21:10Z")

</div>

We can assign a function to a variable:

```julia
julia> f = sin
sin (generic function with 10 methods)

julia> f(1)
0.8414709848078965

```

Can we do something similar with a macro? For example, I want to do something like this:

```julia
julia> using BenchmarkTools

julia> f = btime

julia> @f sin(1)

```

---

<div class="post-metadata">

**Author:** ![cstjean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstjean/32/1444_2.png) [@cstjean](https://discourse.julialang.org/u/cstjean)\
**Post date:** [May 17, 2017, 3:26pm UTC](https://discourse.julialang.org/t/assigning-a-macro-to-a-variable/3773/2 "2017-05-17T15:26:47Z")

</div>

Not that I know of, but you can

```julia
macro f(args...)
    :(@btime($(map(esc, args)...)))
end

@f 2+2

```

And it wouldn’t be hard to write a macro to shorten it to `@synonym @f = @btime`

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [May 17, 2017, 3:34pm UTC](https://discourse.julialang.org/t/assigning-a-macro-to-a-variable/3773/3 "2017-05-17T15:34:42Z")

</div>

Macros are just functions with a funny name

```julia
@eval const $(Symbol("@f")) = $(Symbol("@btime"))

```
