I don't think that the `using X` inside module Y here re-runs the eval, 
there is only one instance of modules, it doesn't create a new instance 
inside module Y.  So your replacement of X._ex_func() at top level still 
holds.

On Tuesday, February 16, 2016 at 5:36:15 AM UTC+10, Julia Tylors wrote:
>
> I started to think, this may be normal working of julia.
>
> import X:_ex_func
> using X
> _ex_func() = println("DDD")
> _1ex_func()
> julia> _1ex_func()
> DDD
> sty
>
> julia> module Y
>           using X
>           _
> _1ex_func      __precompile__  _ex_func
> julia> module Y
>           using X
>           _1ex_func()
>       end
> DDD
> sty
> Y
>
> However, it seems once a function is overridden, it stays overridden in 
> every module.
> That is a very weird idea. why is there such a design decision? Can 
> someone care to explain it?
>
> Thanks
>
> On Monday, February 15, 2016 at 11:04:07 AM UTC-8, Julia Tylors wrote:
>>
>> Guys, this is no solution to my problem, 
>>
>> escaping basically tells the the quoted expr to be resolved outside the 
>> macro as Lutfullah did. However in my case, escaping a function call 
>> doesn't work for some reason.
>> And for that matter, esc should be recursive though...
>>
>>
>> On Monday, February 15, 2016 at 6:44:58 AM UTC-8, Joshua Ballanco wrote:
>>>
>>> On February 14, 2016 at 21:49:30, Julia Tylors (julia...@gmail.com
>>> (mailto:juliatyl...@gmail.com)) wrote: 
>>>
>>> > Hi fellows,   
>>> >   
>>> >   
>>> > I was coding a macro, and I am having a prefix issue with functions.   
>>> >   
>>> > basically the problem is: Every single one of available functions 
>>> (_ex_func) which i want to be globally accessible are prefixed with the 
>>> name of the module(X) in which the macro f is defined   
>>> >   
>>> >   
>>> > Here is the code example:   
>>> >   
>>> > julia> module X   
>>> > export @f 
>>> > macro f(x) 
>>> > st = string("_",x) 
>>> > sy = symbol(st) 
>>> > esc(quote 
>>> > function ($sy)() 
>>> > println("st") 
>>> > end 
>>> >   
>>> > function ($(symbol(string("_1",x))))()   
>>> > ($sy)() 
>>> > println("sty") 
>>> > end 
>>> > export $sy 
>>> > export $(symbol(string("_1",x))) 
>>> > end 
>>> > ) 
>>> > end 
>>> > @eval @f ex_func 
>>> > end 
>>> > X 
>>> >   
>>> > julia> using X   
>>> >   
>>> > julia> _   
>>> >   
>>> > _1ex_func __precompile__ _ex_func   
>>> > julia> _1ex_func.env.defs.func.code 
>>> > AST(:($(Expr(:lambda, Any[], Any[Any[],Any[],0,Any[]], :(begin # none, 
>>> line 12: 
>>> > (X._ex_func)() # none, line 13: # i want this to be not prefixed by X 
>>> > return (X.println)("sty") 
>>> > end))))) 
>>> >   
>>> > julia> macroexpand(:(@f ex_func))   
>>> > quote # none, line 7: 
>>> > function _ex_func() # none, line 8: 
>>> > println("st") 
>>> > end # none, line 11: 
>>> > function _1ex_func() # none, line 12: 
>>> > _ex_func() # none, line 13: # it seems OK, here!!! 
>>> > println("sty") 
>>> > end # none, line 15: 
>>> > export _ex_func # none, line 16: 
>>> > export _1ex_func 
>>> > end 
>>> >   
>>> >   
>>> >   
>>> > as you may see , I may well define _ex_func in other modules and use 
>>> it from the function X._1ex_func().   
>>> > But this prevents me doing it. 
>>> >   
>>> > How can i solve this problem?   
>>> >   
>>> > Thanks 
>>>
>>> OH! I know this! 
>>>
>>> Actually, I do believe this is a bug in macro hygiene and have been 
>>> meaning to file it. In the mean time, double-escaping should work for you: 
>>>
>>>     julia> module X 
>>>                macro p(y) 
>>>                  quote 
>>>                    println($y) 
>>>                  end 
>>>                end 
>>>                macro q(y) 
>>>                  quote 
>>>                    println(:($($y))) 
>>>                  end 
>>>                end 
>>>            end 
>>>     X 
>>>      
>>>     julia> using X 
>>>      
>>>     julia> test = "Hello, world" 
>>>     "Hello, world" 
>>>      
>>>     julia> @X.p(test) 
>>>     ERROR: UndefVarError: test not defined 
>>>      
>>>     julia> @X.q(test) 
>>>     Hello, world 
>>>
>>

Reply via email to