On Tuesday, May 24, 2016 at 11:13:29 AM UTC-4, [email protected] wrote:
>
> Cedric, 
>
> Yes, you have identified the issue: when I say "using file.@mac" followed 
> by "macroexpand(:(@mac expr))" at the REPL prompt, then future 'include' 
> statements do not reload the macro definition.  However, if I skip the 
> "using" directive and qualify the name as file.@mac in the macroexpand 
> call, then future 'include' statements do reload the macro.
>
> This behavior runs counter to my expectation of how "using" operates.  Can 
> you explain in more detail what "using" does?
>

It's magic to me too, TBH. The manual says

The statement using Lib means that a module called Lib will be available 
> for resolving names as needed. 
>

but I don't understand how its implementation interacts with 
reload/include. 


> -- Steve
>
>
>
> On Tuesday, May 24, 2016 at 8:15:25 AM UTC-4, Cedric St-Jean wrote:
>>
>> Are you `using` the module? In general, `using` and reloading don't play 
>> very nice with each other. I just tried with a module like
>>
>> module foo
>> macro aa()
>>     20
>> end
>> end
>>
>> and when I use the module name
>>
>> include("foo.jl")
>> foo.@aa
>>
>> it works out.
>>
>> On Tue, May 24, 2016 at 12:21 AM, <[email protected]> wrote:
>>
>>> Cedric,
>>>
>>> I encountered this issue in the following context: the macro is defined 
>>> inside a module.  I test it from the REPL using the macroexpand function.  
>>> When macroexpand bombs or else gives me the wrong expansion, I edit the 
>>> file with the macro definition and reload the module via include.  However, 
>>> the next invocation of macroexpand from the REPL still uses the old 
>>> definition.
>>>
>>> The suggestion from Kaj Wiik to use the workspace() command seems to 
>>> have addressed the issue.  In fact, I just submitted a PR to the Julia 
>>> manual with a couple of sentences to explain this.
>>>
>>> -- Steve
>>>
>>>
>>> On Tuesday, May 24, 2016 at 12:03:24 AM UTC-4, Cedric St-Jean wrote:
>>>>
>>>> Maybe you already know this, but macros are applied at parsing time (or 
>>>> right after parsing - not sure). This means that if you have
>>>>
>>>> # In Macro.jl
>>>> macro macmac(x)
>>>> ...
>>>> end
>>>>
>>>> # In Fun.jl
>>>> function foo(x)
>>>>    macmac(something)
>>>> end
>>>>  
>>>>
>>>> Then whenever you've changed Macro.jl, you need to reload both Macro.jl 
>>>> and Fun.jl, because as far as Julia is concerned, `macmac(something)` 
>>>> isn't 
>>>> "a reference to the macmac macro"; once Fun.jl has been loaded, `macmac` 
>>>> is 
>>>> completely gone from foo's definition, and replaced with its 
>>>> macroexpansion.
>>>>
>>>> Doing that, I've never had any issue with reloading macros. Do you have 
>>>> another problem in mind, or more specific code?
>>>>
>>>> On Monday, May 23, 2016 at 5:31:37 PM UTC-4, [email protected] wrote:
>>>>>
>>>>> First, thanks to Matt Baumann for answering my previous post so 
>>>>> quickly!
>>>>>
>>>>> Next question: it seems that for developing and debugging a macro, the 
>>>>> usual REPL cycle of edit/include/edit/include does not work.,  I find 
>>>>> that 
>>>>> using 'include' to reload the macro definition defined inside a module 
>>>>> does 
>>>>> not overwrite its previous definition.  It seems that to replace a macro 
>>>>> definition, I need to exit the REPL and start a new REPL.  Is there some 
>>>>> other way?
>>>>>
>>>>> Thanks,
>>>>> Steve Vavasis
>>>>>
>>>>>
>>

Reply via email to