Roadmap with respect to `Base.@kwdef`
mauro3 opened this issue · 3 comments
Much of the @with_kw
functionality has been implemented in Base.@kwdef
, see JuliaLang/julia#29316, which will go into Julia 1.1. Once Julia 1.1 has been release, this should be used in Parameters. The plan could be to keep the @with_kw
macro which would use @kwdef
internally and enhance it with its "missing" features (show, reconstruct, type specific unpack macros, auto-documentation, @assert
s).
@kwdef
only defines an outer constructor, whereas @with_kw
defines both inner and outer. There seems to be a reason for that:
Parameters.jl/src/Parameters.jl
Line 518 in 870131f
Maybe this relates:
I defined the following struct
@with_kw struct Vesicle{
C<:Number, #Curvature
AR<:Number, #Area
VO<:Number, #Volume
P<:Number, #Pressure
T<:Number, #Tension
L<:Number, #Length
R<:Real,
E<:Number, #Energy
}
m::C = zero(C)
A::AR
V::VO
ΔP::P
Σ::T
u0::C
u1::C
S::L
v::R
κ::E = 8e-20u"J"
function Vesicle(m::C, A::AR, V::VO, ΔP::P, Σ::T, u0::D, u1::D, S::L, v::R, κ::E) where {C,AR,VO,P,T,D,L,R,E}
(mm, uu0,uu1) = promote(m,u0,u1)
return new{typeof(mm),AR,VO,P,T,L,R,E}(mm, A, V, ΔP, Σ, uu0, uu1, S, v, κ)
end # function
end # struct
but Vesicle(zeros(10)...)
fails with a MethodError
, while Base.@kwdef
works fine.