I have written a set of functions, say
bar!, etc., to do some operations that modify their first argument. Now say I want to have their complements
bar… that operate on a default value of that first argument, e.g.
foo(a, args...) = foo!(defaultobject(), args...)
Instead of repeating that line with all the functions, if I’ve got all function names as symbols in the collection
fnames I can just do:
for f in fnames f! = Symbol(f, :!) @eval $f(args...) = $f!(defaultobject(), args...) end
But now I want
foo!, etc. to have a common docstring. I have tried to do this but it fails:
fdocs = Dict( :foo => "documentation of foo and foo!", :bar => "documentation of bar and bar!" # etc. ) for (f, docstring) in fdocs f! = Symbol(f, :!) @eval $f(args...) = $f!(defaultobject(), args...) @doc docstring $f @doc docstring $f! end
The error message that I get is:
ERROR: LoadError: LoadError: LoadError: cannot document the following expression: $(Expr(:$, :f))
It works well if I write directly
@doc docstring :foo
and so on. What am I doing wrong in the loop?