# Problem in attaching array type in struct

**URL:** <https://discourse.julialang.org/t/problem-in-attaching-array-type-in-struct/36417>\
**Category:** New to Julia\
**Created:** [March 24, 2020, 5:40am UTC](https://discourse.julialang.org/t/problem-in-attaching-array-type-in-struct/36417 "2020-03-24T05:40:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lee](https://avatars.discourse-cdn.com/v4/letter/l/bc8723/32.png) [@Lee](https://discourse.julialang.org/u/Lee)\
**Post date:** [March 24, 2020, 5:40am UTC](https://discourse.julialang.org/t/problem-in-attaching-array-type-in-struct/36417/1 "2020-03-24T05:40:00Z")

</div>

Does anyone know why this stretch is giving error?

´´´  
struct lis  
it = zeros(Int8, 10)  
beg::Int8  
en::Int8  
tot::Int8  
end  
´´´  
Thanks!

---

<div class="post-metadata">

**Author:** ![anon94023334](https://avatars.discourse-cdn.com/v4/letter/a/e274bd/32.png) [@anon94023334](https://discourse.julialang.org/u/anon94023334)\
**Post date:** [March 24, 2020, 5:46am UTC](https://discourse.julialang.org/t/problem-in-attaching-array-type-in-struct/36417/2 "2020-03-24T05:46:01Z")

</div>

First, [please surround your code with triple backticks](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757).

Second, you cannot have variable assignments within a struct. The error message you get tells you this:  
`ERROR: syntax: "it = zeros(Int8, 10)" inside type definition is reserved`

If you need this data inside a struct, create a field `it::Vector{Int8}` and then initialize the struct with `lis(zeros(Int8, 10), ...)`.

---

<div class="post-metadata">

**Author:** ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)\
**Post date:** [March 24, 2020, 8:17pm UTC](https://discourse.julialang.org/t/problem-in-attaching-array-type-in-struct/36417/3 "2020-03-24T20:17:35Z")

</div>

Probably useful: [Default value of \*some\* fields in a mutable struct](https://discourse.julialang.org/t/default-value-of-some-fields-in-a-mutable-struct/33408).

See also Parameters.jl which allows you to set default values for fields.

---

<div class="post-metadata">

**Author:** ![Lee](https://avatars.discourse-cdn.com/v4/letter/l/bc8723/32.png) [@Lee](https://discourse.julialang.org/u/Lee)\
**Post date:** [March 25, 2020, 10:39pm UTC](https://discourse.julialang.org/t/problem-in-attaching-array-type-in-struct/36417/4 "2020-03-25T22:39:57Z")

</div>

Hello! thanks for the tip. The way I want to manipulate the struct, using hectorogen values, is giving this error.

```julia
struct lis
   it::Vector{Int8}
   beg::Int8
   en::Int8
   tot::Int8
end

ERROR: invalid redefinition of constant lis
Stacktrace:
 [1] top-level scope at none:0

```

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [March 26, 2020, 6:17am UTC](https://discourse.julialang.org/t/problem-in-attaching-array-type-in-struct/36417/5 "2020-03-26T06:17:38Z")

</div>

> [@Lee](#):
>
> invalid redefinition of constant lis

You probably defined it before. You can only redefine a `struct` after restarting Julia.
