# Shorthand for a function that returns kwargs

**URL:** <https://discourse.julialang.org/t/shorthand-for-a-function-that-returns-kwargs/92387>\
**Category:** General Usage\
**Created:** [January 1, 2023, 3:43pm UTC](https://discourse.julialang.org/t/shorthand-for-a-function-that-returns-kwargs/92387 "2023-01-01T15:43:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrey2185](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andrey2185/32/9889_2.png) [@andrey2185](https://discourse.julialang.org/u/andrey2185)\
**Post date:** [January 1, 2023, 3:43pm UTC](https://discourse.julialang.org/t/shorthand-for-a-function-that-returns-kwargs/92387/1 "2023-01-01T15:43:02Z")

</div>

Is it possible to create a function with kwargs that returns a kwargs NamedTuple like this `get_abc(;a,b,c) = (a=a,b=b,c=c)` without `=(a=a,b=b,c=c)`? Or need macroses ?

---

<div class="post-metadata">

**Author:** ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)\
**Post date:** [January 1, 2023, 3:47pm UTC](https://discourse.julialang.org/t/shorthand-for-a-function-that-returns-kwargs/92387/2 "2023-01-01T15:47:47Z")

</div>

Since Julia 1.6+ or so, you can do this:

```julia
julia> get_abc(;a,b,c) = (; a, b, c)
get_abc (generic function with 1 method)

julia> get_abc(a=1, b=2, c=3)
(a = 1, b = 2, c = 3)

```

or this:

```julia
julia> get_kws(; kwargs...) = (; kwargs...)
get_kws (generic function with 1 method)

julia> get_kws(; a = 1, b = 2, c = 3)
(a = 1, b = 2, c = 3)

```

---

<div class="post-metadata">

**Author:** ![andrey2185](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andrey2185/32/9889_2.png) [@andrey2185](https://discourse.julialang.org/u/andrey2185)\
**Post date:** [January 1, 2023, 3:55pm UTC](https://discourse.julialang.org/t/shorthand-for-a-function-that-returns-kwargs/92387/3 "2023-01-01T15:55:06Z")

</div>

```julia
macro kwargs_return_function(f::Symbol, args...)
    _f = Symbol(:_,f)
    return :($(esc(
        quote
            $_f(; $(args...)) = nothing
            $f(; kwargs...) = ($_f(; kwargs...); (; kwargs...))
        end
    )))
end

```

better

```julia
macro kwret(f::Symbol, args...)
    return :($(esc(
        quote
            $f(; $(args...)) = (; $(args...))
        end
    )))
end

```

---

<div class="post-metadata">

**Author:** ![andrey2185](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andrey2185/32/9889_2.png) [@andrey2185](https://discourse.julialang.org/u/andrey2185)\
**Post date:** [January 1, 2023, 3:56pm UTC](https://discourse.julialang.org/t/shorthand-for-a-function-that-returns-kwargs/92387/4 "2023-01-01T15:56:25Z")

</div>

these functions are needed to control the arguments
