fieldnames extension of Parameter Struct
stevengogogo opened this issue · 1 comments
stevengogogo commented
Dear Developers,
I'm wondering that whether Base. fieldnames
(or something similar) can be used to list all the fieldnames of the stuct of Parameter.jl.
The following is the command that I tried to get all the field names from the Base
function
julia> using Parameters
julia> @with_kw struct foo
a
end
foo
julia> f = foo(1)
foo
a: Int64 1
julia> fieldnames(f)
ERROR: MethodError: no method matching fieldnames(::foo)
Closest candidates are:
fieldnames(::Core.TypeofBottom) at reflection.jl:175
fieldnames(::Type{var"#s9"} where var"#s9"<:Tuple) at reflection.jl:177
fieldnames(::DataType) at reflection.jl:172
...
Stacktrace:
[1] top-level scope at REPL[4]:1
julia>
Probably using extension to make parameter.jl fit to Base.fieldnames is an option.
Something like
function Base.fieldnames(foo::StructofParameters)
# To Do
end
stevengogogo commented
I found this works
julia> using Parameters
julia> @with_kw struct foo
a
end
foo
julia> fieldnames(foo)
(:a,)