Parameters.jl
Parameters.jl copied to clipboard
Roadmap with respect to `Base.@kwdef`
Much of the @with_kw functionality has been implemented in Base.@kwdef, see https://github.com/JuliaLang/julia/pull/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, @asserts).
@kwdef only defines an outer constructor, whereas @with_kw defines both inner and outer. There seems to be a reason for that: https://github.com/mauro3/Parameters.jl/blob/870131fa4114af141b4c40d8275259e5d19e444b/src/Parameters.jl#L518, but I'm not sure this still applies.
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.
A breaking change would probably be to fix #96 to be consistent with @kwdef. This would mean to deprecate the reconstruct-constructor (in favor of using Setfield.jl, probably).