When I use this code:

module IntModN
export @Zn

macro Zn(args...)
    n = args[1]
    @assert n > 1 "Zn, n must be > 1"
    name = length(args) > 1 ? args[2] : "Z$n"
    @assert length(args) < 3 "Zn, too many args"
    println("n:$n/$(typeof(n)) name:$name/$(typeof(name))")
    code = :(module $name
             export foo

             function foo()
             end

             end)
    println(code)
    code
end

end

in another file, like this,

import IntModN.@Zn

@Zn(2, GF2)


then I see:

andrew@netbook:~/project/int-mod-n/src> julia tests.jl
OpenBLAS : Your OS does not support AVX instructions. OpenBLAS is using 
Nehalem kernels as a fallback, which may give poorer performance.
n:2/Int64 name:GF2/Symbol
:($(Expr(:module, true, :$, quote 
        eval(x) = top(Core).eval($,x)
        eval(m,x) = top(Core).eval(m,x) # line 11:
        name # line 12:
        $(Expr(:export, :foo)) # line 14:
        function foo()
        end
    end)))
ERROR: name not defined
 in include_from_node1 at loading.jl:120
while loading /home/andrew/.julia/IntModN/src/tests.jl, in expression 
starting on line 11


and I don't understand why name isn't being spliced in as a symbol.  Nor do 
I understand the extra evals in the code.

I've watched the video and read the manual, and I think I understand 
things.  Yet from my understanding name should be substituted.  So why is 
it undefined?

Thanks,
Andrew

Reply via email to