I think you probably should escape both instances of $OP not just the first
one.


On Tue, Aug 12, 2014 at 1:55 PM, Philippe Maincon <
[email protected]> wrote:

> Thank you again, Jacob!
>
> I pondered that under the shower, and it did the trick.  For record, if
> somebody wants to generate a function from a macro in a function, here is a
> little example.  Case closed.
>
> Philippe
>
> module moo
>
> importall Base          # need to import Base.cos, Base.sin to add methods to 
> it
>
> export Typ              # export all that is to be public
>
> type Typ                # public, because exported
>
>     x
>
> end
>
> cos(a::Typ) = cos(a.x)  # add method to base function - this does NOT require 
> any export out of this module or import by the user
>
> macro makefoo(OP)
>
>    return quote
>
>       $(esc(OP))(a::Typ)= $OP(a.x)   # add method to base function.  Note the 
> $(esc(OP)) to prevent macro hygiene from changing the name of generated 
> function
>
>    end
>
> end
>
> println(macroexpand(:(@makefoo(sin))))
>
> @makefoo(sin)
>
> end
>
>
> importall moo
>
> println(methods(cos))
>
> println(methods(sin))
>
>
>

Reply via email to