# Instance of a composite type

**URL:** https://discourse.julialang.org/t/instance-of-a-composite-type/14067
**Category:** General Usage
**Created:** [August 26, 2018, 4:37am UTC](https://discourse.julialang.org/t/instance-of-a-composite-type/14067 "2018-08-26T04:37:39Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![microlifecc](https://avatars.discourse-cdn.com/v4/letter/m/ed655f/32.png) [@microlifecc](https://discourse.julialang.org/u/microlifecc)
#### Post date: [August 26, 2018, 4:37am UTC](https://discourse.julialang.org/t/instance-of-a-composite-type/14067/1 "2018-08-26T04:37:39Z")

</div>

Hi!  
So I am trying to create an instance of a structure:

```
struct keypoint
    x
    y
    scale
    angle
    Vector{Any}(VecLength)
end

```

Now I know the values of all the fields except the last one. I need to initialize the instance of the structure with the known values but for the last field I have to call another function where the data to be generated and then stored in the last field of the instance. Is there a way to get this done in Julia?

I am referring to the tutorials [here](http://bogumilkaminski.pl/files/julia_express_v0.6.2.pdf) and [here](https://learnxinyminutes.com/docs/julia/) but I guess in both places all the fields of the instance have been initialized at one go.

Thanks!

---

<div class="post-metadata">

### Author: ![v-i-s-h](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/v-i-s-h/32/46152_2.png) [@v-i-s-h](https://discourse.julialang.org/u/v-i-s-h)
#### Post date: [August 26, 2018, 4:58am UTC](https://discourse.julialang.org/t/instance-of-a-composite-type/14067/2 "2018-08-26T04:58:44Z")

</div>

Will this work for you?

```julia
struct keypoint
    x
    y
    scale
    angle
    myVector::Vector{Any}
    function keypoint( _x, _y, _scale, _angle )
        _myVector = myFunction( myArgs )
        new( _x, _y, _scale, _angle, _myVector )
    end
end

```

---

<div class="post-metadata">

### Author: ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)
#### Post date: [August 26, 2018, 6:46am UTC](https://discourse.julialang.org/t/instance-of-a-composite-type/14067/3 "2018-08-26T06:46:52Z")

</div>

Apart from the straightforward answer above, there is also [Parameters.jl](https://github.com/mauro3/Parameters.jl) which allows you to do

```julia
@with_kw struct keypoint
    x = xdefault
    y = ydefault
    scale = scaledefault
    angle = angledefault
    myvector = myfunction(x,y,scale,angle) # calculate myvector default based on other field values
end

```

(On a side note, maybe this is just because this is a minimal example, but you should type your fields.)
