How to define a function in a different module other than what you are in right now


#1

Hi Fellows,

module DDF
end

function DDF.foo(x::Int)
   x+1
end

i want to define a function within DDF like foo.

How can i do that? The example above doesn’t work.


Returning a module expression from a macro to be evaluated at a different module
#2
DDF.eval(:(function foo(x::Int)
   x+1
end))

Note that this is usually bad style.

Better:

module DDF
function foo end # just define the generic function without any methods
end

function DDF.foo(x::Int) # add a method to DDF.foo
x+1
end