This code produce a syntax error. I cannot use a default value in a @kwdef struct?
@kwdef struct MyStruct
indir::String = "./",
outdir::String = "./result",
threshold::Int = 2
end
ERROR: syntax: invalid assignment location ""./result"" around REPL[16]:1
The
@kwdefis a macro in julia that defines a struct, and automatically creates an associated constructor.Normally, to create a struct and constructor, one would write:
But the macro
@kwdefincreases readability by simplifying this slightly.The same struct and constructor can be defined, using
@kwdefwith:Note: In both examples, there are no commas between parameters. The code provided in the question was breaking due to the commas being included.
@kwdefuses the same syntax as a struct definition, so it should not have commas.