Phuoc
Phuoc

Reputation: 1093

How to alias a macro in julia

I'd like to make a name alias of a macro. My current implementation is to create a new macro that call and pass over the argument, eg.:

macro print(xs...)
  quote
    @show $(xs...)
  end
end

Is there any better / built-in way to this?

Upvotes: 3

Views: 557

Answers (2)

HarmonicaMuse
HarmonicaMuse

Reputation: 7893

You could also do:

julia> @eval const $(Symbol("@print")) = $(Symbol("@show"))
@show (macro with 1 method)

julia> @print 1 + 1
1 + 1 = 2
2

Upvotes: 5

Anshul Singhvi
Anshul Singhvi

Reputation: 1742

In Julia 1.3, you can use the var"@macroname" syntax, like so:

var"@print" = var"@show"

Then, @show will be effectively aliased to @print.

Upvotes: 6

Related Questions