Just needs extra `$`s in the docstring, one for expression interpolation
and one for string interpolation:
julia> for name in (:year, :month, :day, :hour, :minute, :second, :
millisecond)
@eval begin
@doc """
$($name)(dt::TimeType) -> Int64
Return the $($name) of a `Date` or `DateTime` as an `Int64`.
""" ->
$name(dt::TimeType)
end
end
(`name` will be displayed fully qualified, i.e. `Base.Dates.year`, so you
could convert `name` it to a string to avoid that.)
-- Mike
On Thursday, 3 March 2016 16:44:38 UTC+2, Curtis Vogt wrote:
>
> I was hoping to generate several redundant docstrings using code
> generation. Unfortunately I have run into an issue where $name isn't
> being replaced in the docstring:
>
> julia> using Base.Dates
>
> julia> for name in (:year, :month, :day, :hour, :minute, :second, :
> millisecond)
> @eval begin
> @doc """
> $name(dt::TimeType) -> Int64
>
> Return the $name of a `Date` or `DateTime` as an `Int64`.
> """ ->
> $name(dt::TimeType)
> end
> end
> ERROR: UndefVarError: name not defined
> in eval(::Module, ::Any) at ./boot.jl:267
> [inlined code] from ./boot.jl:266
> in anonymous at ./no file:4294967295
> in eval(::Module, ::Any) at ./boot.jl:267
>
>
>
> Is there a way I can get this to work?
>