# \#kwargs

**URL:** https://discourse.julialang.org/tag/kwargs/783.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [How to call a function with a keyword argument whose name is stored in a variable](https://discourse.julialang.org/t/how-to-call-a-function-with-a-keyword-argument-whose-name-is-stored-in-a-variable/113744)

<div class="topic-metadata">

**Author:** [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Replies:** 4\
**Last updated:** [September 12, 2025, 7:13am UTC](https://discourse.julialang.org/t/how-to-call-a-function-with-a-keyword-argument-whose-name-is-stored-in-a-variable/113744 "2025-09-12T07:13:16Z")

</div>

If someone need it.. or for myself when I will forget it :wink: This snippet allows to call a function with a keyword argument whose name is stored in a variable: foo(x;extra=0) = x+extra keyword = "extra" foo(2,extra=…

---

## [Performance implications of computations in keyword arguments](https://discourse.julialang.org/t/performance-implications-of-computations-in-keyword-arguments/131977)

<div class="topic-metadata">

**Author:** [@loisel](https://discourse.julialang.org/u/loisel)\
**Replies:** 9\
**Last updated:** [September 1, 2025, 11:54am UTC](https://discourse.julialang.org/t/performance-implications-of-computations-in-keyword-arguments/131977 "2025-09-01T11:54:19Z")

</div>

Long story short, I’m putting my entire function into default values of keyword arguments, and I want to know if this is bad. I’m working on a Julia package to solve PDEs. The “driver code” of such solvers often has a z…

---

## [Macros to fill keyword arguments](https://discourse.julialang.org/t/macros-to-fill-keyword-arguments/25454)

<div class="topic-metadata">

**Author:** [@dstarerstor](https://discourse.julialang.org/u/dstarerstor)\
**Replies:** 6\
**Last updated:** [August 20, 2025, 4:40pm UTC](https://discourse.julialang.org/t/macros-to-fill-keyword-arguments/25454 "2025-08-20T16:40:10Z")

</div>

Hi everyone, I’m having a difficult time understanding how to properly use macros. I’m trying to make a macro @passkwargs that will turn foo(; @passkwargs(x,y)) into foo(; x=x, y=y) I’m just starting to work with ma…

---

## [\`methods\` and \`@which\` give different results](https://discourse.julialang.org/t/methods-and-which-give-different-results/127954)

<div class="topic-metadata">

**Author:** [@sadish-d](https://discourse.julialang.org/u/sadish-d)\
**Replies:** 7\
**Last updated:** [April 11, 2025, 5:46pm UTC](https://discourse.julialang.org/t/methods-and-which-give-different-results/127954 "2025-04-11T17:46:29Z")

</div>

I have: f(; x) = 0 and I do: f(x = 1) creating one specialized method (MethodInstance?) of f. I can see the specialized method with a @which: julia\> (@which f(x = 1)) |\> Base.specializations Base.MethodSpecializati…

---

## [Kwargs allocating (?)](https://discourse.julialang.org/t/kwargs-allocating/127326)

<div class="topic-metadata">

**Author:** [@miguelborrero](https://discourse.julialang.org/u/miguelborrero)\
**Replies:** 6\
**Last updated:** [March 27, 2025, 4:21am UTC](https://discourse.julialang.org/t/kwargs-allocating/127326 "2025-03-27T04:21:00Z")

</div>

Hi there, consider the following simple function: M = \[1.0 2.0; 3.0 4.0\] n = size(M,1) I\_n = Matrix{Float64}(I, n, n) A\_temp = zeros(n, n) diff\_temp = zeros(n, n) function inf\_norm\_dif…

---

## [Nothing and type stability in kwargs](https://discourse.julialang.org/t/nothing-and-type-stability-in-kwargs/123532)

<div class="topic-metadata">

**Author:** [@kockahonza](https://discourse.julialang.org/u/kockahonza)\
**Replies:** 6\
**Last updated:** [December 11, 2024, 10:50am UTC](https://discourse.julialang.org/t/nothing-and-type-stability-in-kwargs/123532 "2024-12-11T10:50:29Z")

</div>

Hi, so this is a fairly general question, but is it possible to use Nothing without type stability related performance hits? A specific example I have now is a simple simulator where I want to implement multiple optional…

---

## [Kwargs unexpected (?) error](https://discourse.julialang.org/t/kwargs-unexpected-error/122089)

<div class="topic-metadata">

**Author:** [@aris](https://discourse.julialang.org/u/aris)\
**Replies:** 2\
**Last updated:** [October 31, 2024, 8:14pm UTC](https://discourse.julialang.org/t/kwargs-unexpected-error/122089 "2024-10-31T20:14:48Z")

</div>

I ran across the following while writing some code. function foo( x::Vector, y::Vector; cond=true) if cond return x .- y end end function bar(x, y; kwargs...) return foo(x, y, kwargs...) end # The…

---

## [Incorrect \`method overwritten\` warning with optional kwargs..?](https://discourse.julialang.org/t/incorrect-method-overwritten-warning-with-optional-kwargs/120714)

<div class="topic-metadata">

**Author:** [@iago-lito](https://discourse.julialang.org/u/iago-lito)\
**Replies:** 4\
**Last updated:** [September 30, 2024, 2:56pm UTC](https://discourse.julialang.org/t/incorrect-method-overwritten-warning-with-optional-kwargs/120714 "2024-09-30T14:56:27Z")

</div>

My package exposes this caller method, whose behaviour may be controlled by consumers provided they specialize f: TestPkg/src/TestPkg.jl module TestPkg # Entry point for users. caller(a) = f(a; b = 1) export caller #…

---

## [How to get default values of a functions kwargs](https://discourse.julialang.org/t/how-to-get-default-values-of-a-functions-kwargs/66158)

<div class="topic-metadata">

**Author:** [@juliascrub](https://discourse.julialang.org/u/juliascrub)\
**Replies:** 2\
**Last updated:** [August 23, 2024, 12:01pm UTC](https://discourse.julialang.org/t/how-to-get-default-values-of-a-functions-kwargs/66158 "2024-08-23T12:01:56Z")

</div>

I have a function f: function f(; a=1, b=2, c=3) return 1 end I can get the names of its kwargs using: Base.kwarg\_decl.(methods(f))\[1\] Is there any way to get the default values of those kwargs?

---

## [Can I make Julia eval a variable before using it as a kwargs?](https://discourse.julialang.org/t/can-i-make-julia-eval-a-variable-before-using-it-as-a-kwargs/99322)

<div class="topic-metadata">

**Author:** [@bertulli](https://discourse.julialang.org/u/bertulli)\
**Replies:** 10\
**Last updated:** [May 27, 2023, 9:53pm UTC](https://discourse.julialang.org/t/can-i-make-julia-eval-a-variable-before-using-it-as-a-kwargs/99322 "2023-05-27T21:53:48Z")

</div>

Hi! I’m building a DataFrame with the column names stored in some variables (both as symbols and strings): adc\_I\_title = "Arc ADC Current (A)" adc\_V\_title = "Arc ADC Voltage (V)" adc\_I\_symbol = Symbol(adc\_I\_title) adc\_V…

---

## [Mystery of kwargs](https://discourse.julialang.org/t/mystery-of-kwargs/38768)

<div class="topic-metadata">

**Author:** [@lewis](https://discourse.julialang.org/u/lewis)\
**Replies:** 11\
**Last updated:** [December 7, 2022, 8:01am UTC](https://discourse.julialang.org/t/mystery-of-kwargs/38768 "2022-12-07T08:01:30Z")

</div>

I am completely flummoxed by using a dict as the kwargs input in a varargs function that uses keyword arguments. Read the manual many times but it leaves out a critical thing: how does the callee unpack the varargs? Th…

---

## [Passing keyword arguments to nested functions | or how to use macros to define a function whose kwargs are those of their inner function calls](https://discourse.julialang.org/t/passing-keyword-arguments-to-nested-functions-or-how-to-use-macros-to-define-a-function-whose-kwargs-are-those-of-their-inner-function-calls/88671)

<div class="topic-metadata">

**Author:** [@abelsiqueira](https://discourse.julialang.org/u/abelsiqueira)\
**Replies:** 0\
**Last updated:** [October 13, 2022, 2:48pm UTC](https://discourse.julialang.org/t/passing-keyword-arguments-to-nested-functions-or-how-to-use-macros-to-define-a-function-whose-kwargs-are-those-of-their-inner-function-calls/88671 "2022-10-13T14:48:41Z")

</div>

Important: I am trying to figure this out to compare to a Python approach, which I mention in the second part of the question. Suppose I have two functions, foo and bar, whose keyword argument I don’t know or care. Sup…

---

## [How to use \`kwargs\` to avoid passing around keyword arguments?](https://discourse.julialang.org/t/how-to-use-kwargs-to-avoid-passing-around-keyword-arguments/84856)

<div class="topic-metadata">

**Author:** [@Cory\_Simon](https://discourse.julialang.org/u/Cory_Simon)\
**Replies:** 2\
**Last updated:** [July 27, 2022, 2:13am UTC](https://discourse.julialang.org/t/how-to-use-kwargs-to-avoid-passing-around-keyword-arguments/84856 "2022-07-27T02:13:32Z")

</div>

I found the documentation on kwargs to be a little terse… how can I exploit keyword arguments to avoid copying tons of different keyword arguments when passing them function to function? my example below. seems unnatura…

---

## [Using a keyword argument leads to enormous allocations](https://discourse.julialang.org/t/using-a-keyword-argument-leads-to-enormous-allocations/80354)

<div class="topic-metadata">

**Author:** [@moble](https://discourse.julialang.org/u/moble)\
**Replies:** 8\
**Last updated:** [May 9, 2022, 3:09pm UTC](https://discourse.julialang.org/t/using-a-keyword-argument-leads-to-enormous-allocations/80354 "2022-05-09T15:09:00Z")

</div>

I’ve been running into a bizarre problem with huge allocations, and I’ve just discovered that the problem can be avoided if I don’t use a keyword argument to a function inside my main computation function. The allocatio…

---

## [Force specialization on kwargs](https://discourse.julialang.org/t/force-specialization-on-kwargs/34789)

<div class="topic-metadata">

**Author:** [@dilumaluthge](https://discourse.julialang.org/u/dilumaluthge)\
**Replies:** 15\
**Last updated:** [March 7, 2022, 1:46pm UTC](https://discourse.julialang.org/t/force-specialization-on-kwargs/34789 "2022-03-07T13:46:53Z")

</div>

If I have a function like this: f\_vararg(varargs::Int...) = tuple(varargs...) I can force specialization on varargs with either of the following: g\_vararg(varargs::Vararg{Int, N}) where {N} = tuple(varargs...) h\_vara…

---

## [Passing kwargs... can overwrite other keyword arguments](https://discourse.julialang.org/t/passing-kwargs-can-overwrite-other-keyword-arguments/74933)

<div class="topic-metadata">

**Author:** [@albheim](https://discourse.julialang.org/u/albheim)\
**Replies:** 2\
**Last updated:** [January 20, 2022, 2:13pm UTC](https://discourse.julialang.org/t/passing-kwargs-can-overwrite-other-keyword-arguments/74933 "2022-01-20T14:13:12Z")

</div>

I recently got bitten by some behavior that was not immediately obvious to me (combined with a little sloppy coding from my side). In my case I had a function passing on some kwargs from higher up, as well as adding som…

---

## [FunctionWrappers and kwargs](https://discourse.julialang.org/t/functionwrappers-and-kwargs/67339)

<div class="topic-metadata">

**Author:** [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)\
**Replies:** 1\
**Last updated:** [August 30, 2021, 11:21am UTC](https://discourse.julialang.org/t/functionwrappers-and-kwargs/67339 "2021-08-30T11:21:27Z")

</div>

I see FunctionWrappers.jl as a critical tool to enable precompilation of code that takes functions as inputs, and hence reduce latency in such cases. I think the package is a crucial tool in the Julia language, since the…

---

## [Rationale for kwargs as Iterators.Pairs](https://discourse.julialang.org/t/rationale-for-kwargs-as-iterators-pairs/66435)

<div class="topic-metadata">

**Author:** [@sijo](https://discourse.julialang.org/u/sijo)\
**Replies:** 4\
**Last updated:** [August 15, 2021, 3:17pm UTC](https://discourse.julialang.org/t/rationale-for-kwargs-as-iterators-pairs/66435 "2021-08-15T15:17:01Z")

</div>

I’m curious why the keyword arguments are available wrapped in Iterators.Pairs in the function body: function f(; kwargs...) # kwargs is a NamedTuple wrapped in an Iterators.Pairs end Is it legacy cruft from a time…

---

## [How to view kwargs](https://discourse.julialang.org/t/how-to-view-kwargs/46280)

<div class="topic-metadata">

**Author:** [@Dustin\_Hess](https://discourse.julialang.org/u/Dustin_Hess)\
**Replies:** 4\
**Last updated:** [September 13, 2020, 12:45pm UTC](https://discourse.julialang.org/t/how-to-view-kwargs/46280 "2020-09-13T12:45:34Z")

</div>

When using a package such as PlotlyJS.jl, ( Such as I am). How does one find all kwargs available for a particular function. PoltyJS does not document what they are. They do show you how to use them but it seems not be o…

---

## [Discovery of possible keywords for kwargs... Maybe we need Base.optional\_keywords?](https://discourse.julialang.org/t/discovery-of-possible-keywords-for-kwargs-maybe-we-need-base-optional-keywords/44989)

<div class="topic-metadata">

**Author:** [@jules](https://discourse.julialang.org/u/jules)\
**Replies:** 7\
**Last updated:** [August 16, 2020, 8:41pm UTC](https://discourse.julialang.org/t/discovery-of-possible-keywords-for-kwargs-maybe-we-need-base-optional-keywords/44989 "2020-08-16T20:41:25Z")

</div>

I think we need better tooling to discover optional keyword arguments. Maybe this needs to be dealt with in Base, rather than VSCode, Juno, etc. Consider the following scenario: In Makie, we have many plotting function…

---

## [Using kwargs and non kwargs in a function call](https://discourse.julialang.org/t/using-kwargs-and-non-kwargs-in-a-function-call/37518)

<div class="topic-metadata">

**Author:** [@birodaniel8](https://discourse.julialang.org/u/birodaniel8)\
**Replies:** 5\
**Last updated:** [April 13, 2020, 8:33pm UTC](https://discourse.julialang.org/t/using-kwargs-and-non-kwargs-in-a-function-call/37518 "2020-04-13T20:33:51Z")

</div>

Hi al, I am new at programming in Julia, but I am struggling to implement and call a function in a particular way, which I was using a lot in Python. I have a function like: function f(x, y=1, z=3; kwargs...) retur…

---

## [Extracting kwargs from anonymous function](https://discourse.julialang.org/t/extracting-kwargs-from-anonymous-function/37350)

<div class="topic-metadata">

**Author:** [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)\
**Replies:** 12\
**Last updated:** [April 11, 2020, 4:08pm UTC](https://discourse.julialang.org/t/extracting-kwargs-from-anonymous-function/37350 "2020-04-11T16:08:44Z")

</div>

EDIT: original title was “Confused about escaping in macros” I’m trying metaprogramming in Julia for the first time, and I’m having some trouble grasping the escaping and hygiene discussion in the manual. I’m trying to…

---

## [Composing new and default Kwargs](https://discourse.julialang.org/t/composing-new-and-default-kwargs/36745)

<div class="topic-metadata">

**Author:** [@alejandrovpm](https://discourse.julialang.org/u/alejandrovpm)\
**Replies:** 4\
**Last updated:** [March 30, 2020, 4:54pm UTC](https://discourse.julialang.org/t/composing-new-and-default-kwargs/36745 "2020-03-30T16:54:56Z")

</div>

Hello, I upgraded Julia from version 0.63 to version 1.4. To compose new and default Kwargs in Julia v0.63 I used the following function: function foo(; kwargs...) defaults = (; x="default") merge!(defa…

---

## [Smart kwargs... dispatch](https://discourse.julialang.org/t/smart-kwargs-dispatch/14571)

<div class="topic-metadata">

**Author:** [@DominiqueMakowski](https://discourse.julialang.org/u/DominiqueMakowski)\
**Replies:** 16\
**Last updated:** [March 30, 2020, 2:37pm UTC](https://discourse.julialang.org/t/smart-kwargs-dispatch/14571 "2020-03-30T14:37:32Z")

</div>

Let’s say a function f() involves another function with multiple arguments. From what I understood, one can avoid listing them with with the kwargs... argument that “passes” the optional arguments down to the other funct…

---

## [Why is this closure over keyword arguments causing such a dramatic slowdown?](https://discourse.julialang.org/t/why-is-this-closure-over-keyword-arguments-causing-such-a-dramatic-slowdown/36308)

<div class="topic-metadata">

**Author:** [@anon32405968](https://discourse.julialang.org/u/anon32405968)\
**Replies:** 19\
**Last updated:** [March 22, 2020, 8:43pm UTC](https://discourse.julialang.org/t/why-is-this-closure-over-keyword-arguments-causing-such-a-dramatic-slowdown/36308 "2020-03-22T20:43:15Z")

</div>

I’m writing a function that allows a user to freeze some variables of a function (needs to be generic with respect to the names and number of keyword arguments). Design-wise, I now have exactly what I need and the code i…

---

## [Save kwargs in struct field to be used later in function calls](https://discourse.julialang.org/t/save-kwargs-in-struct-field-to-be-used-later-in-function-calls/34376)

<div class="topic-metadata">

**Author:** [@HenriDeh](https://discourse.julialang.org/u/HenriDeh)\
**Replies:** 3\
**Last updated:** [February 9, 2020, 1:48pm UTC](https://discourse.julialang.org/t/save-kwargs-in-struct-field-to-be-used-later-in-function-calls/34376 "2020-02-09T13:48:07Z")

</div>

I have a struct Foo with a field that contains keyword arguments given at construction. I want to then be able to call a function with keyword arguments recovered from Foo: struct Foo kwargs end Foo(;kwargs...) = F…

---

## [Constant propagation of kwargs possible?](https://discourse.julialang.org/t/constant-propagation-of-kwargs-possible/27810)

<div class="topic-metadata">

**Author:** [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)\
**Replies:** 3\
**Last updated:** [August 22, 2019, 2:41am UTC](https://discourse.julialang.org/t/constant-propagation-of-kwargs-possible/27810 "2019-08-22T02:41:46Z")

</div>

I suspect the answer is ‘no’, but is current Julia able to constant-propagate kwargs? In other words, is it possible to make the following infer in some way while preserving the kwarg? Julia 1.2 julia\> h(; n) = ntuple(…

---

## [Forwarding vs filtering kwargs](https://discourse.julialang.org/t/forwarding-vs-filtering-kwargs/23196)

<div class="topic-metadata">

**Author:** [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)\
**Replies:** 4\
**Last updated:** [April 16, 2019, 1:14pm UTC](https://discourse.julialang.org/t/forwarding-vs-filtering-kwargs/23196 "2019-04-16T13:14:30Z")

</div>

When I want to forward kwargs from an API function to various internal dispatched methods I just allow them to have arbitrary kwargs, like so external\_api(x; kw...) = \_internal(x; kw...) \_internal(x::Float64; kw1 = 1, k…

---

## [Precompile() for function with kwargs](https://discourse.julialang.org/t/precompile-for-function-with-kwargs/19857)

<div class="topic-metadata">

**Author:** [@orange\_si](https://discourse.julialang.org/u/orange_si)\
**Replies:** 4\
**Last updated:** [January 23, 2019, 11:10am UTC](https://discourse.julialang.org/t/precompile-for-function-with-kwargs/19857 "2019-01-23T11:10:15Z")

</div>

hi everyone, I am using julia 1.0.2, and try to precompile for function. precompile() works for function with args(no kwargs), but when have kwargs, it seems not worked, so how to precompile for function with kwargs? …

---

## [How to tell what kwargs are supported by a function](https://discourse.julialang.org/t/how-to-tell-what-kwargs-are-supported-by-a-function/14840)

<div class="topic-metadata">

**Author:** [@bluesmoon](https://discourse.julialang.org/u/bluesmoon)\
**Replies:** 6\
**Last updated:** [September 12, 2018, 2:34pm UTC](https://discourse.julialang.org/t/how-to-tell-what-kwargs-are-supported-by-a-function/14840 "2018-09-12T14:34:52Z")

</div>

Is there any way to tell through code whether a function supports a particular kwarg or not? I have a list of args in a Dict, and I need to filter this Dict to those that are supported by the function being called but sh…

[Next page](https://discourse.julialang.org/tag/kwargs/783.md?match_all_tags=true&page=1&tags%5B%5D=kwargs)
