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