# Assignment and named tuples

**URL:** https://discourse.julialang.org/t/assignment-and-named-tuples/133674
**Category:** General Usage
**Tags:** syntax
**Created:** [November 5, 2025, 10:37am UTC](https://discourse.julialang.org/t/assignment-and-named-tuples/133674 "2025-11-05T10:37:05Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![rokke](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rokke/32/222691_2.png) [@rokke](https://discourse.julialang.org/u/rokke)
#### Post date: [November 5, 2025, 10:37am UTC](https://discourse.julialang.org/t/assignment-and-named-tuples/133674/1 "2025-11-05T10:37:05Z")

</div>

I love the `(a=4)` syntax which both assigns a variable and returns its value, for example:

```julia-auto
vector = [(a=1+2+3)+4+5, a+4+5]

```

there is also a very similar syntax used in named tuples, `(a=4,)` which creates a tuple with a named element `a`. this is also useful since it lets you use keyword arguments:

```julia-auto
function sample(a, b; word1, word2)
    [word1, a, word2, b]
end
sample(word2=3, 2, 4, word1=1)

```

however, these two syntaxes fight with eachother, and the second usually wins:

```julia-auto
sample(word2=3, (a=2), a+2, word1=1)
#error: unsupported keword argument a

```

it appears that the parens are interpreted as precedence clarification, but since commas are already the lowest precedence, it doesn’t do anything, and ‘simplifies’ itself down to `sample(word2=3, a=2, a+2, word1=1)`, which is an error. if someone actually meant to clarify precedence intent, they would likely do

```julia-auto
sample(word2=3, a=(2), a+2, word1=1)

```

since this currently does nothing, could ‘parens assignments’ in function calls be fixed, or would that be considered a breaking change?

---

<div class="post-metadata">

### Author: ![Vasily\_Pisarev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vasily_pisarev/32/7929_2.png) [@Vasily\_Pisarev](https://discourse.julialang.org/u/Vasily_Pisarev)
#### Post date: [November 5, 2025, 10:59am UTC](https://discourse.julialang.org/t/assignment-and-named-tuples/133674/2 "2025-11-05T10:59:51Z")

</div>

I think `(a = 2)` is meant to be equivalent to `a = 2`. If you need the result, use `(a = 2;)`.

---

<div class="post-metadata">

### Author: ![kellertuer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kellertuer/32/220707_2.png) [@kellertuer](https://discourse.julialang.org/u/kellertuer)
#### Post date: [November 5, 2025, 11:54am UTC](https://discourse.julialang.org/t/assignment-and-named-tuples/133674/3 "2025-11-05T11:54:01Z")

</div>

I personally am neither a fan of “hiding” the assignment `a=2` in a function call nor “mixing“ keyword and positional arguments.

But one thing that does work is beyond storing the result, also returning it from the bracket (extending Vasily’s answer) as `(a=2; a)`,  
because otherwise even in the structured form

```julia
ample(a=2, a+1; word1=7, word2=3)

```

complains in the `a+1` that a is not defined (in the parent scope) but

```julia
ample( (a=2; a), a+1; word1=7, word2=3)

```

does actually work, even in your order, “mixing” positional and keyword args

```julia-auto
sample(word2=3, (a=2; a), a+1, word1=3)

```

I personally would actually prefer the slightly more readable form (IMHO)

```julia-auto
a=2
sample(a, a+1; word1=3, word2=7)

```

---

<div class="post-metadata">

### Author: ![rokke](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rokke/32/222691_2.png) [@rokke](https://discourse.julialang.org/u/rokke)
#### Post date: [November 5, 2025, 12:05pm UTC](https://discourse.julialang.org/t/assignment-and-named-tuples/133674/4 "2025-11-05T12:05:51Z")

</div>

wait, what is the benefit of the second a? assignment statements already return their value, right?

```julia-auto
sample(word2=3, (a=2;), a+2, word1=1)

```

does not error for me

---

<div class="post-metadata">

### Author: ![kellertuer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kellertuer/32/220707_2.png) [@kellertuer](https://discourse.julialang.org/u/kellertuer)
#### Post date: [November 5, 2025, 12:10pm UTC](https://discourse.julialang.org/t/assignment-and-named-tuples/133674/5 "2025-11-05T12:10:58Z")

</div>

Oh, that is interesting, then I confused something there. Note that on REPL

```julia-auto
Julia>a=2;

```

suppressed the output (prints nothing). Then I was not careful enough and assumed the same for the term in brackets, but you are right, even on REPL

```julia-auto
Julia>(a=2;)

```

returns 2, since the `;` then acts as a “divider” between expressions, just there is not even a second expression following. So, sure, your variant works as well. The second a explicitly returns a (so you could also assign a and return 2a or so like in `(a=2; 2*a)` for example).

---

<div class="post-metadata">

### Author: ![rokke](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rokke/32/222691_2.png) [@rokke](https://discourse.julialang.org/u/rokke)
#### Post date: [November 5, 2025, 12:19pm UTC](https://discourse.julialang.org/t/assignment-and-named-tuples/133674/6 "2025-11-05T12:19:22Z")

</div>

the parens only fail to assign when they don’t effect precedence; so if I wanted to return 2a I would do

```julia-auto
sample(word2=3, (a=2)*2, a+2, word1=1)

```

as long as you’re using infix operators, the parens work on their own
