Metaprogramming within docstring with @eval

Viewed 288

I'm attempting to associate a docstring with a function that is defined with an @eval macro; I also wish to use symbols to dynamically generate the docstrings.

for (f, name) in ((:add, :addition), ... )
    @eval begin
        @doc "Documentation for $name" ->
        function f(args)
             ## FUNCTION BODY
        end
    end
end

While I can successfully reference $name from within the @eval statement, I cannot reference $name from within the docstring itself. It gives the error UndefVarError: name not defined.

1) Is there a way to get this to work? I've tried a number of ways to get out of the @doc scope and to gain access to variables in the surrounding scope, but I haven't been successful.

2) What is the nature of the -> syntax?
I got the -> syntax from Github, but I can find no mention of it in the Julia documentation, and even having used Julia for a decent while, I haven't encountered it before.

2 Answers
Related