# \#keyword-arguments

**URL:** https://discourse.julialang.org/tag/keyword-arguments/1287.md

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

---

## [Keyword arguments of 32-bit type don't work](https://discourse.julialang.org/t/keyword-arguments-of-32-bit-type-dont-work/135311)

<div class="topic-metadata">

**Author:** [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Replies:** 6\
**Last updated:** [January 29, 2026, 5:37pm UTC](https://discourse.julialang.org/t/keyword-arguments-of-32-bit-type-dont-work/135311 "2026-01-29T17:37:28Z")

</div>

Why 32bit keyword argument functions give error (Int32 also) ? julia\> x = 2 2 julia\> function sixty\_four(x; y::Float64=0.5) x+y end sixty\_four (generic function with 1 method) julia\> function thi…

---

## [Keyword arguments not allowed on left-hand side of broadcast assignments?](https://discourse.julialang.org/t/keyword-arguments-not-allowed-on-left-hand-side-of-broadcast-assignments/133920)

<div class="topic-metadata">

**Author:** [@matthias314](https://discourse.julialang.org/u/matthias314)\
**Replies:** 1\
**Last updated:** [November 17, 2025, 3:18am UTC](https://discourse.julialang.org/t/keyword-arguments-not-allowed-on-left-hand-side-of-broadcast-assignments/133920 "2025-11-17T03:18:44Z")

</div>

Broadcasting with assignment works with a function call on the left-hand side. However, function calls with keyword arguments do not work for some reason: julia\> f(v; a = 0) = copy(v) f (generic function with 1 method) …

---

## [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…

---

## [Dispatch on keywords](https://discourse.julialang.org/t/dispatch-on-keywords/129854)

<div class="topic-metadata">

**Author:** [@Cyan](https://discourse.julialang.org/u/Cyan)\
**Replies:** 6\
**Last updated:** [June 14, 2025, 8:34am UTC](https://discourse.julialang.org/t/dispatch-on-keywords/129854 "2025-06-14T08:34:01Z")

</div>

I wrote these two functions function test(;e::Float64) return e^2 end function test(;e::Int) return e\*2 end I obtain the right answer when test(1.) or test(1), but the test(e=1.) returns an error of: TypeErro…

---

## [Nothing == absence of keyword argument?](https://discourse.julialang.org/t/nothing-absence-of-keyword-argument/108119)

<div class="topic-metadata">

**Author:** [@ryofurue](https://discourse.julialang.org/u/ryofurue)\
**Replies:** 15\
**Last updated:** [June 13, 2025, 1:35pm UTC](https://discourse.julialang.org/t/nothing-absence-of-keyword-argument/108119 "2025-06-13T13:35:30Z")

</div>

Is there a convenient idiom to indicate that a keyword argument is absent? I imagine that somebody may have already invented a macro or something to do this . . . There are library functions, typically from graphics pa…

---

## [Macro to generate 2 keyword function parameters](https://discourse.julialang.org/t/macro-to-generate-2-keyword-function-parameters/128161)

<div class="topic-metadata">

**Author:** [@filchristou](https://discourse.julialang.org/u/filchristou)\
**Replies:** 3\
**Last updated:** [April 17, 2025, 3:43pm UTC](https://discourse.julialang.org/t/macro-to-generate-2-keyword-function-parameters/128161 "2025-04-17T15:43:57Z")

</div>

Let’s say I have this function import Dates: DateTime function myfun1(; ena::Int=1, offsettime::DateTime, entrytime::DateTime, dio::Int) return nothing end with the parameters being :($(Expr(:parameters, :($(Expr(…

---

## [\`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…

---

## [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…

---

## [Possible to know if a certain method supports a certain keyword?](https://discourse.julialang.org/t/possible-to-know-if-a-certain-method-supports-a-certain-keyword/112498)

<div class="topic-metadata">

**Author:** [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Replies:** 4\
**Last updated:** [April 4, 2024, 8:22am UTC](https://discourse.julialang.org/t/possible-to-know-if-a-certain-method-supports-a-certain-keyword/112498 "2024-04-04T08:22:18Z")

</div>

Is it possible to know if a certain method supports a certain keyword argument, or one has to use exceptions?

---

## [Passing \`Symbol\` variable allocates when literal does not?](https://discourse.julialang.org/t/passing-symbol-variable-allocates-when-literal-does-not/110518)

<div class="topic-metadata">

**Author:** [@bremez](https://discourse.julialang.org/u/bremez)\
**Replies:** 4\
**Last updated:** [February 21, 2024, 4:04pm UTC](https://discourse.julialang.org/t/passing-symbol-variable-allocates-when-literal-does-not/110518 "2024-02-21T16:04:44Z")

</div>

I have the following snippet: function preparearrays!(arrays, N, L; mode = :all) for n in 0:(length(arrays)-1) if mode === :all for m in 0:(L-1) # run till length L to zero all bits …

---

## [A keyword argument must have a default value?](https://discourse.julialang.org/t/a-keyword-argument-must-have-a-default-value/108421)

<div class="topic-metadata">

**Author:** [@jiang\_ming\_zhang](https://discourse.julialang.org/u/jiang_ming_zhang)\
**Replies:** 7\
**Last updated:** [January 6, 2024, 2:55pm UTC](https://discourse.julialang.org/t/a-keyword-argument-must-have-a-default-value/108421 "2024-01-06T14:55:30Z")

</div>

This seems a common practice in the codes I saw. Is it required or not?

---

## [Should the manual discuss type parameters of keyword arguments?](https://discourse.julialang.org/t/should-the-manual-discuss-type-parameters-of-keyword-arguments/105752)

<div class="topic-metadata">

**Author:** [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Replies:** 1\
**Last updated:** [November 3, 2023, 12:34pm UTC](https://discourse.julialang.org/t/should-the-manual-discuss-type-parameters-of-keyword-arguments/105752 "2023-11-03T12:34:14Z")

</div>

Type parameters for keyword arguments are currently a convenience form, equivalent to saving the result of a typeof, perform a subtype check when that is specified. Eg foo(; a::C) where {C \<: Integer} = :C is more o…

---

## [Short Names for Keyword Arguments](https://discourse.julialang.org/t/short-names-for-keyword-arguments/103407)

<div class="topic-metadata">

**Author:** [@TI36XPro](https://discourse.julialang.org/u/TI36XPro)\
**Replies:** 3\
**Last updated:** [August 31, 2023, 3:31pm UTC](https://discourse.julialang.org/t/short-names-for-keyword-arguments/103407 "2023-08-31T15:31:11Z")

</div>

Can I alias keyword arguments for brevity? For example, in MATLAB I can do the following x = linspace(0, 1); y = x.^2; lw = "linewidth" close all plot(x, y, lw=2) There is a similar thing in python’s matplotlib where…

---

## [Why do Julia functions handle keyword arguments as \`Base.Pairs\` instead of \`NamedTuple\` or \`Dict\`?](https://discourse.julialang.org/t/why-do-julia-functions-handle-keyword-arguments-as-base-pairs-instead-of-namedtuple-or-dict/102263)

<div class="topic-metadata">

**Author:** [@singularitti](https://discourse.julialang.org/u/singularitti)\
**Replies:** 2\
**Last updated:** [July 30, 2023, 5:25am UTC](https://discourse.julialang.org/t/why-do-julia-functions-handle-keyword-arguments-as-base-pairs-instead-of-namedtuple-or-dict/102263 "2023-07-30T05:25:36Z")

</div>

In Python, where we use \*args and \*\*kwargs to handle an arbitrary number of positional and keyword arguments in a function. In Python, these positional arguments are gathered into a tuple, and keyword arguments are gathe…

---

## [Should I add type annotation to keyword arguments?](https://discourse.julialang.org/t/should-i-add-type-annotation-to-keyword-arguments/99231)

<div class="topic-metadata">

**Author:** [@greatpet](https://discourse.julialang.org/u/greatpet)\
**Replies:** 10\
**Last updated:** [May 30, 2023, 1:32am UTC](https://discourse.julialang.org/t/should-i-add-type-annotation-to-keyword-arguments/99231 "2023-05-30T01:32:17Z")

</div>

Old versions of Julia’s performance tips https://docs.julialang.org/en/v1/manual/performance-tips advised annotating the types of keyword arguments, but this is no longer mentioned in the current version. Do I still ne…

---

## [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…

---

## [Weird memory allocation when passing functions as keyword arguments](https://discourse.julialang.org/t/weird-memory-allocation-when-passing-functions-as-keyword-arguments/96920)

<div class="topic-metadata">

**Author:** [@sunoru](https://discourse.julialang.org/u/sunoru)\
**Replies:** 6\
**Last updated:** [April 3, 2023, 3:01pm UTC](https://discourse.julialang.org/t/weird-memory-allocation-when-passing-functions-as-keyword-arguments/96920 "2023-04-03T15:01:28Z")

</div>

I was trying to understand the cause of some unexpected memory allocations and found the program has the following strange behaviors. I am really confused and hope someone can help me figure it out, thanks! I tested on 1…

---

## [Using the end keyword as a function argument](https://discourse.julialang.org/t/using-the-end-keyword-as-a-function-argument/96615)

<div class="topic-metadata">

**Author:** [@SantiagoOrtiz](https://discourse.julialang.org/u/SantiagoOrtiz)\
**Replies:** 3\
**Last updated:** [March 26, 2023, 2:13am UTC](https://discourse.julialang.org/t/using-the-end-keyword-as-a-function-argument/96615 "2023-03-26T02:13:22Z")

</div>

Hi, Is there any way to pass the end keyword as an argument in a function or another index (i.e., -1 in python) to point to the last position of an array? a = \[1 2 3 4 5\] function f1(a, n) return a\[n\] end f1(a, e…

---

## [Keyword Arguments and Type Stability](https://discourse.julialang.org/t/keyword-arguments-and-type-stability/94993)

<div class="topic-metadata">

**Author:** [@alfaromartino](https://discourse.julialang.org/u/alfaromartino)\
**Replies:** 11\
**Last updated:** [February 23, 2023, 9:23am UTC](https://discourse.julialang.org/t/keyword-arguments-and-type-stability/94993 "2023-02-23T09:23:44Z")

</div>

I need to remain flexible (I’m testing the code) and I ran into the following problem. MWE param = 2 x = rand(100) foo(x; β = param) = sum(x .\* β) @code\_warntype foo(x) # type unstable @code\_warntype fo…

---

## [Finding possible keyword arguments](https://discourse.julialang.org/t/finding-possible-keyword-arguments/40752)

<div class="topic-metadata">

**Author:** [@fgerick](https://discourse.julialang.org/u/fgerick)\
**Replies:** 18\
**Last updated:** [September 13, 2022, 1:23pm UTC](https://discourse.julialang.org/t/finding-possible-keyword-arguments/40752 "2022-09-13T13:23:39Z")

</div>

This is inspired by this post: Is there a way of finding allowed keyword arguments for a function (e.g. bar) that passes its kwargs to another function, such as foo(;a=2,b=3) = a+b bar(;kwargs...) = foo(; kwargs...) s…

---

## [Make function arguments positional or keyword](https://discourse.julialang.org/t/make-function-arguments-positional-or-keyword/2984)

<div class="topic-metadata">

**Author:** [@sbohor3](https://discourse.julialang.org/u/sbohor3)\
**Replies:** 33\
**Last updated:** [October 19, 2018, 8:23pm UTC](https://discourse.julialang.org/t/make-function-arguments-positional-or-keyword/2984 "2018-10-19T20:23:57Z")

</div>

How do I create a function that can take either positional or keyword arguments? Right now, I have a function that takes keyword arguments. But, I would to revise it to take either positional or keyword arguments. Thanks…
