I have checked the Stackoverflow topic Difference between @with_kw and Base.@kwdef in Julia?, whose last update is from Oct, 18, 2021, and would like to know whether there should be any drawbacks due to my current preferred use of the package Parameters.jl (with the corresponding macro @with_kw) instead of the default Julia’s Base.@kw_def; in fact, it seems to me the package still has (some/many?) more resources than the default base macro. Is this correct?
allow @asserts in the type body which then get included in the positional inner constructor.
Pulling on this thread a little - this one actually stops me converting by simple substitution from @with_kw to @kwdef because the structs are no longer syntactically valid.
julia> @kwdef struct Foo
x::Int64
@assert x > 3
end
ERROR: UndefVarError: `x` not defined
Is there an easy fix for this? The assertions in the body are nice, I like how declarative it is.
That same error occurs without any struct macro, struct body @asserts are specifically processed by Parameters.jl. It’s just a matter of making @kwdef do the same thing and having someone approve it. Not sure if it would be, as struct body @asserts are technically doable in base Julia, it’s just bizarre and seemingly useless to do an assertion with a global variable inside a struct body with an unrelated field of the same name.