I am trying to define an outer constructor for this struct:
@with_kw struct Hijri
year::Int64
month::Int64
day::Int64
validate::Bool #TODO: should be able to initialize a Hijri with giving this parameter
end
Here is my constructor:
Hijri(year, month, day, validate=true) = Hijri(year, month, day, validate)
When I call it as follows:
Hijri(1400, 1, 1)
I get UndefVarError:
ERROR: LoadError: UndefVarError: Hijri not defined
Stacktrace:
[1] top-level scope
@ ~/Documents/projects/hijri/hijri-converter-julia-package/hijri_converter/src/convert.jl:288
in expression starting at /home/jafar_isbarov/Documents/projects/hijri/hijri-converter-julia-package/hijri_converter/src/convert.jl:288
When I tried to remove the optional argument from constructor:
Hijri(year, month, day) = Hijri(year, month, day, true)
I still got exactly the same error.
I have to questions:
(1) What is the reason for this error?
(2) Is there a more efficient (and clean) way of implementing optional struct fields?