Macros julia macro can';的隐式uuu source uuuu参数;不能在报价栏中使用

Macros julia macro can';的隐式uuu source uuuu参数;不能在报价栏中使用,macros,julia,metaprogramming,Macros,Julia,Metaprogramming,我将从我的代码开始: macro example(args...) local s = __source__ println(s) # This part works, showing macro is called on line 9 quote println(s) # Julia tells me this variable "s" is not defined println(

我将从我的代码开始:

    macro example(args...)
        local s = __source__
        println(s)   # This part works, showing macro is called on line 9
        quote
            println(s)   # Julia tells me this variable "s" is not defined
            println(__source__)   # Likewise, "__source__" is not defined here either
        end
    end

    @example 42   # Line 9 of my file
在上面的宏中,我想记录调用宏的行号,并在报价块中使用它。在quote块外的变量中捕获它并在其中使用它,或者直接在quote块中使用它都不起作用。我的理解是quote块之外的代码在解析时运行,从quote块返回的表达式在运行时求值


我觉得必须有一种方法来捕获该变量,并将其直接注入到稍后将要计算的表达式中,但我还没有想出如何做到这一点。这里的任何帮助都是感激的。如果有更好的方法,请告诉我。

我最终自己找到了答案。在第二行中,如果我将
\uuuuuuu source\uuuuuu
更改为
\uuuuuu source\uuuuuu.line
\uuuuuu source\uuuuuuuuuu.file
,只要我随后使用$将结果插入宏返回的表达式中,它就可以正常工作。我仍然不知道为什么
\uuu source\uuuuuuuuuuuuuuuuu
本身不起作用,但是使用
.line
.file
方法对我来说现在起作用了。

我最终自己找到了答案。在第二行中,如果我将
\uuuuuuu source\uuuuuu
更改为
\uuuuuu source\uuuuuu.line
\uuuuuu source\uuuuuuuuuu.file
,只要我随后使用$将结果插入宏返回的表达式中,它就可以正常工作。我仍然不确定为什么
\uuu source\uuu
本身不起作用,但是使用
.line
.file
方法现在对我来说是可行的