# Can't call struct constructor inside of a function

**URL:** https://discourse.julialang.org/t/cant-call-struct-constructor-inside-of-a-function/77359
**Category:** New to Julia
**Tags:** question, struct, constructors
**Created:** [March 3, 2022, 2:06pm UTC](https://discourse.julialang.org/t/cant-call-struct-constructor-inside-of-a-function/77359 "2022-03-03T14:06:55Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![the\_dude](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/the_dude/32/33355_2.png) [@the\_dude](https://discourse.julialang.org/u/the_dude)
#### Post date: [March 3, 2022, 2:06pm UTC](https://discourse.julialang.org/t/cant-call-struct-constructor-inside-of-a-function/77359/1 "2022-03-03T14:06:55Z")

</div>

I have this struct created in a file:

 ![struct_env](https://global.discourse-cdn.com/julialang/original/3X/6/6/662d1387894afbc45fb8803565bccd3a687d767f.png)

I’m including it on another file using:

 ![imports_data_gen](https://global.discourse-cdn.com/julialang/original/3X/9/2/92e1a1c7824a89b247e94c762a5b6a794aa37355.png)

But, when a try to call the constructor of the struct inside of a function like this:

 ![declaring_inside_function](https://global.discourse-cdn.com/julialang/original/3X/d/a/da1ace70ed3cecf336f669c96c57f2e8a61b8729.png)

I get this error:

```julia
ERROR: LoadError: UndefVarError: e not defined
Stacktrace:
 [1] generate_env()
   @ Main ~/path/to/file/data_gen.jl:161
 [2] top-level scope
   @ ~/path/to/file/data_gen.jl:167
in expression starting at /path/to/file/data_gen.jl:167

```

Could someone help me?

---

<div class="post-metadata">

### Author: ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)
#### Post date: [March 3, 2022, 2:11pm UTC](https://discourse.julialang.org/t/cant-call-struct-constructor-inside-of-a-function/77359/2 "2022-03-03T14:11:00Z")

</div>

What is the last `e` in

```julia
e = Environment(dfp, ... , e)
---------------------------^

```

---

<div class="post-metadata">

### Author: ![the\_dude](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/the_dude/32/33355_2.png) [@the\_dude](https://discourse.julialang.org/u/the_dude)
#### Post date: [March 3, 2022, 2:20pm UTC](https://discourse.julialang.org/t/cant-call-struct-constructor-inside-of-a-function/77359/3 "2022-03-03T14:20:29Z")

</div>

Ops… I’m sorry. I’ve been working for so many hours that I couldn’t realize. 😵‍💫  
Need to sleep…

Thank you very much for your help!
