# Outer constructor with default parameters

**URL:** <https://discourse.julialang.org/t/outer-constructor-with-default-parameters/73853>\
**Category:** General Usage\
**Tags:** function, struct, constructors\
**Created:** [December 31, 2021, 8:14am UTC](https://discourse.julialang.org/t/outer-constructor-with-default-parameters/73853 "2021-12-31T08:14:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jafar.isbarov](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jafar.isbarov/32/36130_2.png) [@jafar.isbarov](https://discourse.julialang.org/u/jafar.isbarov)\
**Post date:** [December 31, 2021, 8:14am UTC](https://discourse.julialang.org/t/outer-constructor-with-default-parameters/73853/1 "2021-12-31T08:14:42Z")

</div>

I am trying to define an outer constructor for this struct:

```julia
@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:

```julia
Hijri(year, month, day, validate=true) = Hijri(year, month, day, validate)

```

When I call it as follows:

```julia
Hijri(1400, 1, 1)

```

I get UndefVarError:

```julia
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:

```julia
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?

---

<div class="post-metadata">

**Author:** ![jafar.isbarov](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jafar.isbarov/32/36130_2.png) [@jafar.isbarov](https://discourse.julialang.org/u/jafar.isbarov)\
**Post date:** [December 31, 2021, 9:01am UTC](https://discourse.julialang.org/t/outer-constructor-with-default-parameters/73853/2 "2021-12-31T09:01:28Z")

</div>

Apparently, I was calling the function outside of the scope. The function was defined within a module, and I was calling it outside of it.

(Should I delete the question?)
