Hi, I would like to know how to control the way in which package name 
prefixes are added in the expressions returned by macros.

Let's take a simple example macro, which takes an function call and 
replaces the first argument by a function "foo" of that argument:

macro composefoo(ex)
    x = ex.args[2]
    ex.args[2] = :(foo($x))

If I define this in Main I will obtain:

julia> macroexpand(:(@composefoo bar(x)))

But if I define the same macro inside a package called Foo, the result is:

julia> using Foo
julia> macroexpand(:(@composefoo bar(x)))

In this example, if the function "foo" is defined inside Foo (and not 
exported), it is useful to have the prefix automatically added in the 
returned expression, but I would like to preserve the function name "bar" 
and the argument "x" untouched.

I know that I can escape the returned expression, but that would be 
dangerous in more complex cases, if the expression contains different 
lines, including the assignment of values to new variables and I don't want 
to accidentally overwrite existing variables with the same name in Main. 
Generally, I would like to escape only the names of the variables and 
functions that are included in the input expression. But I don't know if 
there is a smart way of doing that.

Best regards
Helios De Rosario

Reply via email to