Dear all,
The title says it all, I don't know if it's very clear since the problem is
a bit tricky... The user has to define his own type Foo, then he needs to
write a function f() that generates Foo types automatically. This needs to
be done for a lot of different models so since I don't want the user to
rewrite a lot of code to redefine f() every time, I wanted that this
function be generated using a macro in the core of my project, which is
wrapped inside a module Mod. So ideally, I would need to define a macro
mac() (or a function that makes an @eval, both are fine with me) inside
Mod; @mac() would be called outside Mod to create f(), which would be used
outside Mod as well. Here is a minimal code:
type Foo
f::Function
end
module Mod
macro mac()
return quote
function f()
return Foo(x -> 1.0)
end
end
end
export @mac
end
using Mod
f = @mac()
println(f())
I have two problems:
- 1. Foo is not recognized inside Mod
- 2. if I remove the dependency on Foo for mac(), it works, but for some
reason, I need to assign the return value of @mac() to f so that it be
usable after; I would have expected that:
@mac()
println(f())
would work, but it doesn't.
How can I solve these two problems?
Many thanks,