You just need a little hygiene. Check out that section in the manual:
http://docs.julialang.org/en/latest/manual/metaprogramming/#hygiene

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 - note position
of export statement at top of module :)
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)
    OP = esc(OP)
   quote
      $OP(a::Typ) = $OP(a.x)   # add method to base function - fails to
export.  Explicit export statement does not help
   end
end
@makefoo(sin)
end

importall moo


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

> Thank you Jameson.
>
> Dear all
> ...but I am still stuck.  It's like that: the methods I generate by macro
> in my module all overload Base functions (cos).  If I write a new method
> without using a macro, I don't need to export it explicitely (I imagine,
> because I am not creating a new _function_).  But if my method is macro
> generate, it does not export:
>
> 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 - note position of 
> export statement at top of module :)
>
> 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
>
>       $OP(a::Typ)= $OP(a.x)   # add method to base function - fails to 
> export.  Explicit export statement does not help
>
>    end
>
> end
>
> @makefoo(sin)
>
> end
>
>
> importall moo
>
> println(methods(cos))   # 9 methods :) ... I know how to export functions 
> from a module
>
> println(methods(sin))   # 8 methods :( ... But not if I generated them by 
> macro
>
> Is that difference intentional?
>
>
> Sorry Stephane, but the code of @deprecated is, after scrutiny, beyond me.  
> I'll have to take your word for now on the potential evils of exporting macro 
> generated function.  But, then can you suggest a workaround?  Can I export 
> the macro (I failed), and have the macro calls outside the module?  I'd like 
> to keep the module - because it contains a bunch of private functions...
>
>
> Philippe
>
>

Reply via email to