# @kwdef kwargs

**URL:** <https://discourse.julialang.org/t/kwdef-kwargs/109853>\
**Category:** General Usage\
**Tags:** question, constructors\
**Created:** [February 7, 2024, 5:06am UTC](https://discourse.julialang.org/t/kwdef-kwargs/109853 "2024-02-07T05:06:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lincoln\_Hannah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lincoln_hannah/32/19198_2.png) [@Lincoln\_Hannah](https://discourse.julialang.org/u/Lincoln_Hannah)\
**Post date:** [February 7, 2024, 5:06am UTC](https://discourse.julialang.org/t/kwdef-kwargs/109853/1 "2024-02-07T05:06:59Z")

</div>

Could there be a flag added to @kwdef (say @kwargs) that adds a `kwargs...` to the constructor inputs so that

```julia
@kwdef @kwargs struct X
    a
    b
end

X(; a=1, b=2, c=3 )

```

Would work the same as

```julia
X(; a=1, b=2 )

```

i.e. additional arguments in the constructor call are ignored.

---

<div class="post-metadata">

**Author:** ![roflmaostc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/roflmaostc/32/30123_2.png) [@roflmaostc](https://discourse.julialang.org/u/roflmaostc)\
**Post date:** [February 7, 2024, 10:28am UTC](https://discourse.julialang.org/t/kwdef-kwargs/109853/2 "2024-02-07T10:28:34Z")

</div>

Usually I use Parameters.jl.

I think it offers all what you need?

---

<div class="post-metadata">

**Author:** ![Lincoln\_Hannah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lincoln_hannah/32/19198_2.png) [@Lincoln\_Hannah](https://discourse.julialang.org/u/Lincoln_Hannah)\
**Post date:** [February 8, 2024, 12:45am UTC](https://discourse.julialang.org/t/kwdef-kwargs/109853/3 "2024-02-08T00:45:25Z")

</div>

I requested it of Parameters.jl

> <https://github.com/mauro3/Parameters.jl/issues/153>
>
> The objective of this request is to make it very easy to use AsTable(:) to conve…rt a DataFrame to an array of structures. 
> ( AsTable(:) passes a DataFrame row as a named tuple. )
> Example
> 
> \`\`\`
> @with\_kw mystruct (allow\_additional\_args = true, overwrite\_missing = true)
> X
> Y = 2X
> end
> 
> @chain begin
> DataFrame( X=\[1,2\], Y=\[1,missing\], Z=\[1,2\] )
> 
> @rtransform :mystruct = mystruct( AsTable(:)... ) 
> end
> 
> \# produces
> \# mystruct(1, 1)
> \# mystruct(2, 4)
> \`\`\`
> 
> \`allow\_additional\_args = true\`, means column Z is ignored (rather than causing an error).  
> 
> \`overwrite\_missing\` means when column Y = \`missing\`, the default of \`2X\` is used, as it would be if field Y were not supplied e..g \`mystruct(X=1)\`
> 
> 
> More generally
> When the struct has 10 or 20 fields and the DataFrame has 50. (or when the struct is created from a larger struct with a super-set of fields), its nice to not have to re-state the fieldnames.

At the time I think @kwdef wasn’t available to users but now is.
