This is my first attempt at metaprogramming, so apologies if this should be
obvious from the documentation (or just obvious):
For defining an interface I am implementing "dummy functions" which just
return a tailored error message if an interface function has not been
implemented. At the moment this largely duplicates the standard Julia
behaviour, but it just gives a little more information (e.g. the
information that a certain function ought to be part of an interface), but
long-term I want to give it additional functionality, e.g. more information.
Because I am implementing many of these interface functions, I tried to
write a macro:
module Test
using Docile, Lexicon, Compat
export ffun
macro protofun(fname, argtypes...)
# preprocess the arguments to generate an error message
errmsg = "AbstractAtomsInterface: `$(string(fname))("
for n = 1:length(argtypes)-1
errmsg *= string(argtypes[n]) * ", "
end
errmsg = errmsg[1:end-2] * ")' has no implementation."
eval(quote
@doc $(argtypes[end])->
function $(fname)($(argtypes[1:end-1]...))
error($errmsg)
end
end)
end
@protofun(ffun, ::Number, ::String, doc"yads")
end
When I run this:
julia> using Test
julia> ffun(1.0, "abc")
ERROR: AtomsInterface: `ffun(::Number, ::String)' has no implementation.
in ffun at /Users/ortner/gits/Atoms.jl/Test.jl:20
What I would like to see is
ERROR: AtomsInterface: `ffun(::Float64, ::ASCIIString)' has no
implementation.
in ffun at /Users/ortner/gits/Atoms.jl/Test.jl:20
It is clear to me why my implementation does not work as I hope, but I
don't see how to make this work. I would be grateful about any suggestions.
Many thanks,
Christoph