As Jacob points out, a macro body is a function that maps input expressions to the expression that will be evaluated instead due to macro expansion. If you're calling eval in the macro, you're evaluating code at macro expansion time – i.e. when your code is being parsed. This is almost certainly not what you want.
Emitting exports from a macro is still slightly tricky – the @deprecated macro <https://github.com/JuliaLang/julia/blob/640ccec3b57c780c0c4ef57d145e722866c75f9c/base/deprecated.jl#L1-L33> does this. It requires emitting a special :toplevel AST node. Hopefully that helps. On Mon, Aug 11, 2014 at 7:22 AM, Jacob Quinn <[email protected]> wrote: > I think you just need to remove the eval() from your macro. Macros should > always return Expr (expression) objects, and not be in the business of > eval-ing things. > > -Jacob > > > On Mon, Aug 11, 2014 at 7:16 AM, Philippe Maincon < > [email protected]> wrote: > >> Hi, >> >> Within a module, I am defining a macro, and then calling it multiple time >> to generate a bunch of functions. >> >> I would like to make these functions available to the user of the macro, >> so I should export them. My macro now looks like >> >> macro Op1(OP,A) >> >> eval(quote >> >> >> $OP(a::Dual) = Dual($OP(a.x),a.dx*$A,a.id) >> >> export $OP # code line 72 >> >> end) >> >> end >> >> >> (yes, I am still playing with automatic differentiation...) but on executing >> the module file I get >> >> LoadError("P:/Programming/Julia/autodiff9.jl",72,ErrorException("unsupported >> or misplaced expression export")) >> >> >> Can I somehow automatise the exporting of function using the macro as I >> attempt in the code above, or do I need to explicity export each function >> that I create via macro? >> >> >> Philippe >> >> >> >
