# No Way to Rename Macros?

**URL:** <https://discourse.julialang.org/t/no-way-to-rename-macros/14344>\
**Category:** General Usage\
**Tags:** macros\
**Created:** [August 31, 2018, 2:52am UTC](https://discourse.julialang.org/t/no-way-to-rename-macros/14344 "2018-08-31T02:52:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mattcbro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattcbro/32/24487_2.png) [@mattcbro](https://discourse.julialang.org/u/mattcbro)\
**Post date:** [August 31, 2018, 2:52am UTC](https://discourse.julialang.org/t/no-way-to-rename-macros/14344/1 "2018-08-31T02:52:17Z")

</div>

After the significant changes between 0.6.4 and 0.7 and up, I have tasked myself the job of creating version independent code. There are several instances where a simple replacement of one macro name with another would suffice. However this appears to be impossible with Julia as far as I can tell.

An important example is the case where the macro @parallel is essentially replaced with @distributed in v0.7. In my versioning logic I can not simply set parallel = distributed; I get an undefined error. Furthermore it appears I can not simply create a new macro of the form,

```julia
macro par(args...)
:( @distributed $(args...) )
end

```

It seems that other macros won’t play nice with my renaming, ie

```julia
@sync @par ....

```

does not have the same effect as

```julia
@sync @distributed ...

```

No doubt there are some kind of environment dependencies or escaped variables etc. that are lost in the translation. Is there any way to fix this situation? Can one do a pure textual macro that get’s evaluated and has the same properties as the original macro? The complexity and surprises in the macro system are rather daunting.

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [August 31, 2018, 5:50am UTC](https://discourse.julialang.org/t/no-way-to-rename-macros/14344/2 "2018-08-31T05:50:11Z")

</div>

Can you do something like:

```julia
@static if VERSION < v"0.7-"
  @oldmacro(foo)
else
  @newmacro(foo)
end

```

at the call site? It’s not terribly pretty, but I think it would work (on mobile now, so I can’t test it).

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [August 31, 2018, 5:55am UTC](https://discourse.julialang.org/t/no-way-to-rename-macros/14344/3 "2018-08-31T05:55:59Z")

</div>

You can do this:

```julia
if VERSION < v"0.7-"
    @eval const $(Symbol("@oldmacro")) = $(Symbol("@newmacro"))
end

```

Example:

```julia
julia> @eval const $(Symbol("@hello")) = $(Symbol("@info"));

julia> @hello "Hello"
[ Info: Hello

```

---

<div class="post-metadata">

**Author:** ![mattcbro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattcbro/32/24487_2.png) [@mattcbro](https://discourse.julialang.org/u/mattcbro)\
**Post date:** [September 1, 2018, 2:27am UTC](https://discourse.julialang.org/t/no-way-to-rename-macros/14344/4 "2018-09-01T02:27:13Z")

</div>

Tried that but with relatively complex macros like @sync and @distributed I think you would have to copy the entire for loop twice into each branch of that if statement.

So far what I’ve done is define a @distributed macro for use in Version \< v"0.7.0" . In 0.6.4 I don’t seem to be getting the weird side effects from nesting macros in other macros. I did file a bug report, because I think it may actually be a bug in how gensym() creates symbols, but it’s too far down in the weeds for me to figure out.

---

<div class="post-metadata">

**Author:** ![mattcbro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattcbro/32/24487_2.png) [@mattcbro](https://discourse.julialang.org/u/mattcbro)\
**Post date:** [September 1, 2018, 2:29am UTC](https://discourse.julialang.org/t/no-way-to-rename-macros/14344/5 "2018-09-01T02:29:40Z")

</div>

Uh wow. Not sure why one needs Symbol const or @eval for all this LOL.
