thautwarm / MLStyle.jl

Julia functional programming infrastructures and metaprogramming facilities
https://thautwarm.github.io/MLStyle.jl/latest/
MIT License
404 stars 39 forks source link

can not use @match inside another macro #41

Closed Roger-luo closed 5 years ago

Roger-luo commented 5 years ago

MWE: copying what's in here: https://github.com/thautwarm/MLStyle-Playground/blob/master/StaticCapturing.jl

to a module. The scoping is not correct.

thautwarm commented 5 years ago

Oh, thanks, the scoping seems to be broken while expanding nested macros, e.g.,

module DefinitionModule
   export @addyz
   macro addy(x)
      esc(:($x + y))
   end

    macro addyz(x)
        esc(:(@addy($x) + z)) 
   end

   function test(y, z)
      @addyz 1
   end
   @assert test(2, 3) == 6

end

using .DefinitionModule

function  test(y, z)
   @addyz 1
end

test(2, 3) # ERROR: LoadError: UndefVarError: @addy not defined

I directly used @match in the generated code of , which made @match necessary for the callee of any macro that invoke . That's too bad for is not totally unusable!

However, in the following days(about one week) I have no time to fix this extremely important issue. Could you please help me with this? I think it won't cost much time, just avoid macrocalls inside quote expressions and, export corresponding function implementations gen_lambda, gen_match, gen_when for macros , @match, @when, respectively.

thautwarm commented 5 years ago

It seems that it's resolved now?

Roger-luo commented 5 years ago

Yeah, fixed.