# Field insertion in immutable @with\_kw struct

**URL:** <https://discourse.julialang.org/t/field-insertion-in-immutable-with-kw-struct/72373>\
**Category:** General Usage\
**Tags:** question, setfield\
**Created:** [December 1, 2021, 1:03pm UTC](https://discourse.julialang.org/t/field-insertion-in-immutable-with-kw-struct/72373 "2021-12-01T13:03:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alequa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alequa/32/12338_2.png) [@alequa](https://discourse.julialang.org/u/alequa)\
**Post date:** [December 1, 2021, 1:03pm UTC](https://discourse.julialang.org/t/field-insertion-in-immutable-with-kw-struct/72373/1 "2021-12-01T13:03:32Z")

</div>

Hi,  
I am trying to load a `@with_kw struct` from a named tuple, but I cannot find a way to associate the fields correctly.  
I would like to use something like a split operator, but the split operator on a named tuple return only the values. I am sure there is a way of doing this, can you help me?

I could use a for loop on the fieldnames, but my struct is immutable.

```julia
##
using Parameters

@with_kw struct Fruits
	banana::Int
	apple::Int
	raspberry::Int
end

market = (banana=3, raspberry=4, apple=1)

split_fruits = Fruits(market...)
fields_fruits = Fruits(banana=market.banana, raspberry=market.raspberry, apple=market.apple)

## check the cart
_samestuff(m, f, field)= getfield(m, field) == getfield(f, field)
samestuff(market, fruits) = all([_samestuff(market,fruits,field) for field in fieldnames(Fruits)])

split_operator = samestuff(market,split_fruits)
field_assignment = samestuff(market,fields_fruits)

print("The split operator works: $split_operator \n")
print("The field assignment works: $field_assignment")

## output
The split operator works: false 
The field assignment works: true

```

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [December 1, 2021, 1:09pm UTC](https://discourse.julialang.org/t/field-insertion-in-immutable-with-kw-struct/72373/2 "2021-12-01T13:09:52Z")

</div>

I think you want

```julia
julia> Fruits(; market...)
Fruits
  banana: Int64 3
  apple: Int64 1
  raspberry: Int64 4

```

this splats `market` as keyword arguments, whereas your version splats it as positional arguments, in which case you just get the order in which the values show up:

```julia
julia> println(market...)
341

```

---

<div class="post-metadata">

**Author:** ![alequa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alequa/32/12338_2.png) [@alequa](https://discourse.julialang.org/u/alequa)\
**Post date:** [December 1, 2021, 1:10pm UTC](https://discourse.julialang.org/t/field-insertion-in-immutable-with-kw-struct/72373/3 "2021-12-01T13:10:37Z")

</div>

yes, thanks!
