# \#syntax

**URL:** https://discourse.julialang.org/tag/syntax/141.md

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

---

## [Where are control flow labels fully documented?](https://discourse.julialang.org/t/where-are-control-flow-labels-fully-documented/137252)

<div class="topic-metadata">

**Author:** [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Replies:** 1\
**Last updated:** [May 23, 2026, 7:23am UTC](https://discourse.julialang.org/t/where-are-control-flow-labels-fully-documented/137252 "2026-05-23T07:23:19Z")

</div>

The documentation of @label is rather sparse. I am looking for a comprehensive list of which forms can be preceded by @label my\_label (apparently begin, for, what else?) which forms accept labels (eg break and @got…

---

## [Syntax error in an array expression](https://discourse.julialang.org/t/syntax-error-in-an-array-expression/22607)

<div class="topic-metadata">

**Author:** [@vvjn](https://discourse.julialang.org/u/vvjn)\
**Replies:** 6\
**Last updated:** [November 18, 2025, 10:19am UTC](https://discourse.julialang.org/t/syntax-error-in-an-array-expression/22607 "2025-11-18T10:19:22Z")

</div>

I ran the following code A = rand(2,3); A\[1, 2 +1 \] and I got this error ERROR: syntax: missing separator in array expression. Same error with i=2; A\[1, i +1\], which is how I came across this. Of course, A\[1,2+1\] works …

---

## [Assignment and named tuples](https://discourse.julialang.org/t/assignment-and-named-tuples/133674)

<div class="topic-metadata">

**Author:** [@rokke](https://discourse.julialang.org/u/rokke)\
**Replies:** 5\
**Last updated:** [November 5, 2025, 12:19pm UTC](https://discourse.julialang.org/t/assignment-and-named-tuples/133674 "2025-11-05T12:19:22Z")

</div>

I love the (a=4) syntax which both assigns a variable and returns its value, for example: 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 na…

---

## [\`hasfield\` and \`getkey\` in namedtuple](https://discourse.julialang.org/t/hasfield-and-getkey-in-namedtuple/132616)

<div class="topic-metadata">

**Author:** [@Marco\_Lombardi](https://discourse.julialang.org/u/Marco_Lombardi)\
**Replies:** 5\
**Last updated:** [September 25, 2025, 8:32am UTC](https://discourse.julialang.org/t/hasfield-and-getkey-in-namedtuple/132616 "2025-09-25T08:32:59Z")

</div>

Just a curiosity: is there any particular reason for the slightly odd choice of access functions for named tuples? I would expect to have hasfield and getfield, or alternatively haskey and getkey, but I see a mixture of …

---

## [What does the parser think this invalid construction means?](https://discourse.julialang.org/t/what-does-the-parser-think-this-invalid-construction-means/132155)

<div class="topic-metadata">

**Author:** [@rcomm](https://discourse.julialang.org/u/rcomm)\
**Replies:** 10\
**Last updated:** [September 7, 2025, 2:00pm UTC](https://discourse.julialang.org/t/what-does-the-parser-think-this-invalid-construction-means/132155 "2025-09-07T14:00:46Z")

</div>

I discovered today that this line: if \<cond expr\>: return true; else return false; end always returns true, whatever the value of x. The behaviour is the same in the REPL and in functions. I admit I thought that the …

---

## [Literal expression for array of vectors](https://discourse.julialang.org/t/literal-expression-for-array-of-vectors/130184)

<div class="topic-metadata">

**Author:** [@Sevi](https://discourse.julialang.org/u/Sevi)\
**Replies:** 12\
**Last updated:** [June 25, 2025, 1:06pm UTC](https://discourse.julialang.org/t/literal-expression-for-array-of-vectors/130184 "2025-06-25T13:06:12Z")

</div>

Is there an array literal that gives me this object (and a variation with some integer elements in some of the vectors)? julia\> ... 3×5 Matrix{Vector{Int64}}: \[\] \[\] \[\] \[\] \[\] \[\] \[\] \[\] \[\] \[\] \[\] \[\] \[\] \[\] \[\] …

---

## [Destructuring of NamedTuple in julia 1.10](https://discourse.julialang.org/t/destructuring-of-namedtuple-in-julia-1-10/129308)

<div class="topic-metadata">

**Author:** [@o314](https://discourse.julialang.org/u/o314)\
**Replies:** 3\
**Last updated:** [May 25, 2025, 2:35pm UTC](https://discourse.julialang.org/t/destructuring-of-namedtuple-in-julia-1-10/129308 "2025-05-25T14:35:13Z")

</div>

I wonder if there is a way to destructure a namedtuple with splatting like this (; a, nt...) = (; a=1, b=2, c=3) where one is expecting to get a = 1 and nt = (; b=2, c=3) setted This forms fails @ home with julia v1.1…

---

## [Return value of \`begin ... end\`](https://discourse.julialang.org/t/return-value-of-begin-end/127010)

<div class="topic-metadata">

**Author:** [@LEXUGE](https://discourse.julialang.org/u/LEXUGE)\
**Replies:** 15\
**Last updated:** [March 17, 2025, 3:45pm UTC](https://discourse.julialang.org/t/return-value-of-begin-end/127010 "2025-03-17T15:45:43Z")

</div>

I understand the expression will be evaluated to a value. So a = 1 will be evaluated to 1 where as a=1; will not However, I expect begin a = 1; end to evaluate to nothing as well. Why does it evaluate to 1? Intuitiv…

---

## [If in === ∈, why does .∈ work but .in fails with a ParseError?](https://discourse.julialang.org/t/if-in-why-does-work-but-in-fails-with-a-parseerror/125464)

<div class="topic-metadata">

**Author:** [@Matheus](https://discourse.julialang.org/u/Matheus)\
**Replies:** 5\
**Last updated:** [February 2, 2025, 1:02pm UTC](https://discourse.julialang.org/t/if-in-why-does-work-but-in-fails-with-a-parseerror/125464 "2025-02-02T13:02:59Z")

</div>

Hello everyone, I’m trying to understand the following behavior regarding in and ∈ (I guess they’re called operators?). While they are functionally identical (in === ∈ returns true), they behave differently when used wi…

---

## [Naming convention for functions when an argument is optionally mutated](https://discourse.julialang.org/t/naming-convention-for-functions-when-an-argument-is-optionally-mutated/125180)

<div class="topic-metadata">

**Author:** [@frankwswang](https://discourse.julialang.org/u/frankwswang)\
**Replies:** 5\
**Last updated:** [January 25, 2025, 4:20am UTC](https://discourse.julialang.org/t/naming-convention-for-functions-when-an-argument-is-optionally-mutated/125180 "2025-01-25T04:20:35Z")

</div>

I have a function f with a signature: f(x, y, cache::Union{T1, T2}) where cache will be mutated (modified) when it’s of type T1 and not mutated when it’s of type T2. The type of cache is determined by the combinations …

---

## [Why are there all these strange stumbling blocks in Julia?](https://discourse.julialang.org/t/why-are-there-all-these-strange-stumbling-blocks-in-julia/92644)

<div class="topic-metadata">

**Author:** [@Sandjan](https://discourse.julialang.org/u/Sandjan)\
**Replies:** 89\
**Last updated:** [November 21, 2024, 12:41pm UTC](https://discourse.julialang.org/t/why-are-there-all-these-strange-stumbling-blocks-in-julia/92644 "2024-11-21T12:41:32Z")

</div>

I have programmed in Python so far and find the Python syntax very convenient. When learning Julia I constantly notice things that I can not understand: Why is there no short and simple floor division operator like in P…

---

## [What lowers to hvcat(::Int, ...)?](https://discourse.julialang.org/t/what-lowers-to-hvcat-int/121107)

<div class="topic-metadata">

**Author:** [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Replies:** 4\
**Last updated:** [October 9, 2024, 3:37pm UTC](https://discourse.julialang.org/t/what-lowers-to-hvcat-int/121107 "2024-10-09T15:37:25Z")

</div>

I am curious what syntax lowers to hvcat(::Int, ...). Everything I tried lowers into the hvcat(::Tuple{Vararg{Int}}, ...) form. An example would be useful.

---

## [Fun with Unicode: TemplateᐸTᐳ syntax and more](https://discourse.julialang.org/t/fun-with-unicode-template-t-syntax-and-more/117995)

<div class="topic-metadata">

**Author:** [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Replies:** 4\
**Last updated:** [August 9, 2024, 12:24pm UTC](https://discourse.julialang.org/t/fun-with-unicode-template-t-syntax-and-more/117995 "2024-08-09T12:24:36Z")

</div>

Inspired by a Go example: julia\> const VectorᐸIntᐳ = Vector{Int} Vector{Int64} (alias for Array{Int64, 1}) julia\> \[1,2,3\] isa VectorᐸIntᐳ true julia\> x = 2 2 julia\> xᐸ3 = x\<3 true julia\> xᐸ3+4 5 julia\> ᐸ = \> \> (gen…

---

## [Is there a nice way to add submatrices to a larger matrix?](https://discourse.julialang.org/t/is-there-a-nice-way-to-add-submatrices-to-a-larger-matrix/116420)

<div class="topic-metadata">

**Author:** [@AwesomeQuest](https://discourse.julialang.org/u/AwesomeQuest)\
**Replies:** 4\
**Last updated:** [July 1, 2024, 2:34pm UTC](https://discourse.julialang.org/t/is-there-a-nice-way-to-add-submatrices-to-a-larger-matrix/116420 "2024-07-01T14:34:23Z")

</div>

So I’ve found two ways of doing this, the obvious for-loop way and the slightly more Julian infix operator way. First, the for-loop way for (ind,i) in enumerate(indices) M\[i:i+n, i:i+m\] .= A\[ind\] end Where indices co…

---

## [\`sum\` syntax rule differs between Julia and \`JuMP\`](https://discourse.julialang.org/t/sum-syntax-rule-differs-between-julia-and-jump/116125)

<div class="topic-metadata">

**Author:** [@WuSiren](https://discourse.julialang.org/u/WuSiren)\
**Replies:** 2\
**Last updated:** [June 23, 2024, 11:59pm UTC](https://discourse.julialang.org/t/sum-syntax-rule-differs-between-julia-and-jump/116125 "2024-06-23T23:59:51Z")

</div>

a = \[1, 2, 3, 4\] sum(a\[n\] for n in 1:0) # ERROR: MethodError: reducing over an empty collection is not allowed; consider supplying \`init\` to the reducer using JuMP m = Model() @constraint(m, sum(a\[n\] for n in 1:0) \>= 0)…

---

## [Function call with quotes instead of parenthesis](https://discourse.julialang.org/t/function-call-with-quotes-instead-of-parenthesis/114382)

<div class="topic-metadata">

**Author:** [@TI36XPro](https://discourse.julialang.org/u/TI36XPro)\
**Replies:** 3\
**Last updated:** [May 17, 2024, 7:42am UTC](https://discourse.julialang.org/t/function-call-with-quotes-instead-of-parenthesis/114382 "2024-05-17T07:42:07Z")

</div>

Hello, I was looking at the LocalRegistry package when I noticed the following (unrelated I think to the actual LocalRegistry package). using Pkg pkg"registry add \<repository url\>" It looks like the quotes are used in…

---

## [How to make \`\[0\] == 0\`?](https://discourse.julialang.org/t/how-to-make-0-0/112630)

<div class="topic-metadata">

**Author:** [@WuSiren](https://discourse.julialang.org/u/WuSiren)\
**Replies:** 24\
**Last updated:** [April 29, 2024, 6:13pm UTC](https://discourse.julialang.org/t/how-to-make-0-0/112630 "2024-04-29T18:13:14Z")

</div>

julia\> 2 .- \[1 1\] \* \[1; 1\] == 0 false This means in Julia \[0\] != 0. Although I can understand this rule, I feel it inconvenient to use. Do I have to build awareness of this kind and to code carefully when using Julia, o…

---

## [How to extract the indices of a certain variable from a \`Vector{VariableRef}\`?](https://discourse.julialang.org/t/how-to-extract-the-indices-of-a-certain-variable-from-a-vector-variableref/113555)

<div class="topic-metadata">

**Author:** [@WuSiren](https://discourse.julialang.org/u/WuSiren)\
**Replies:** 2\
**Last updated:** [April 28, 2024, 3:21am UTC](https://discourse.julialang.org/t/how-to-extract-the-indices-of-a-certain-variable-from-a-vector-variableref/113555 "2024-04-28T03:21:30Z")

</div>

using JuMP m = Model() @variable(m, x\[1:3\]) @variable(m, y\[1:5\]) v = all\_variables(m) v is an 8-element Vector{VariableRef}. Now I want to extract all the indices with respect to variable y from the vector v (e.g., it c…

---

## [\`vcat(\[\], \[1 2\])\` # OK. \`vcat(\[\], \[1 "2"\])\` # Not OK](https://discourse.julialang.org/t/vcat-1-2-ok-vcat-1-2-not-ok/112991)

<div class="topic-metadata">

**Author:** [@WuSiren](https://discourse.julialang.org/u/WuSiren)\
**Replies:** 18\
**Last updated:** [April 21, 2024, 5:22pm UTC](https://discourse.julialang.org/t/vcat-1-2-ok-vcat-1-2-not-ok/112991 "2024-04-21T17:22:22Z")

</div>

vcat(\[\], \[1 2\]) # OK vcat(\[\], \[1 "2"\]) # Not OK: ERROR: ArgumentError: number of columns of each array must match (got (1, 2)) \[\[\];\[1 2\]\] # OK \[\[\];\[1 "2"\]\] # Not OK: ERROR: ArgumentError: number of columns of each array…

---

## [Maintaining structures across workers](https://discourse.julialang.org/t/maintaining-structures-across-workers/112820)

<div class="topic-metadata">

**Author:** [@Utkarsh\_Sharma](https://discourse.julialang.org/u/Utkarsh_Sharma)\
**Replies:** 1\
**Last updated:** [April 12, 2024, 4:07pm UTC](https://discourse.julialang.org/t/maintaining-structures-across-workers/112820 "2024-04-12T16:07:29Z")

</div>

I created a struct params to be used across different workers as - @everywhere params = parameters(Int64\[\], ...) I initialise params.mapping\_ping as params.mapping\_ping = rand(1:params.q\_datacenters, dimensions.num\_fu…

---

## [Fixing the Piping/Chaining Issue (Rev 3)](https://discourse.julialang.org/t/fixing-the-piping-chaining-issue-rev-3/90836)

<div class="topic-metadata">

**Author:** [@uniment](https://discourse.julialang.org/u/uniment)\
**Replies:** 89\
**Last updated:** [April 5, 2024, 3:13am UTC](https://discourse.julialang.org/t/fixing-the-piping-chaining-issue-rev-3/90836 "2024-04-05T03:13:54Z")

</div>

Third time’s (hopefully) the charm :wink: Okay so in contrast with my last two proposals (1, 2) this proposal is less preachy, and more “hey check out this crazy cool thing I did and please offer feedback.” Hopefully it…

---

## [Why doesn't Julia have the \`switch-case\` structure?](https://discourse.julialang.org/t/why-doesnt-julia-have-the-switch-case-structure/110936)

<div class="topic-metadata">

**Author:** [@WuSiren](https://discourse.julialang.org/u/WuSiren)\
**Replies:** 4\
**Last updated:** [February 29, 2024, 9:26am UTC](https://discourse.julialang.org/t/why-doesnt-julia-have-the-switch-case-structure/110936 "2024-02-29T09:26:58Z")

</div>

Why doesn’t Julia have the switch-case structure? Is it unnecessary, or is there a better solution?

---

## [Do-block syntax with keyword arguments](https://discourse.julialang.org/t/do-block-syntax-with-keyword-arguments/101111)

<div class="topic-metadata">

**Author:** [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Replies:** 4\
**Last updated:** [February 10, 2024, 1:37pm UTC](https://discourse.julialang.org/t/do-block-syntax-with-keyword-arguments/101111 "2024-02-10T13:37:26Z")

</div>

Is is possible to use the do syntax with keyword arguments? MWE: just\_call(f, args...; kwargs...) = f(args...; kwargs...) # lambda just\_call((x; z) -\> @show(x, z), 1; z = 2) # do just\_call(1; z = 2) do x; z @show …

---

## [Syntax: Escape hatch for unicode haters](https://discourse.julialang.org/t/syntax-escape-hatch-for-unicode-haters/108363)

<div class="topic-metadata">

**Author:** [@foobar\_lv2](https://discourse.julialang.org/u/foobar_lv2)\
**Replies:** 124\
**Last updated:** [January 16, 2024, 1:58pm UTC](https://discourse.julialang.org/t/syntax-escape-hatch-for-unicode-haters/108363 "2024-01-16T13:58:19Z")

</div>

Some people have a perennial problem with unicode in source files, and would prefer to simply never deal with that. We have two interesting precedents inside the julia language to deal with that: String literals permi…

---

## [Minimisation with equality constraints](https://discourse.julialang.org/t/minimisation-with-equality-constraints/107358)

<div class="topic-metadata">

**Author:** [@eveningsilverfox](https://discourse.julialang.org/u/eveningsilverfox)\
**Replies:** 5\
**Last updated:** [December 10, 2023, 9:13pm UTC](https://discourse.julialang.org/t/minimisation-with-equality-constraints/107358 "2023-12-10T21:13:06Z")

</div>

I am trying a constrained minimisation with equality constraints. using LinearAlgebra using Optimization, OptimizationMOI, AmplNLWriter, Ipopt\_jll function objectivehelp(N) car = rand(N) .+ 1; sar = rand(N); r…

---

## [Plotting data showing 2 sets of data](https://discourse.julialang.org/t/plotting-data-showing-2-sets-of-data/107272)

<div class="topic-metadata">

**Author:** [@Kearney](https://discourse.julialang.org/u/Kearney)\
**Replies:** 1\
**Last updated:** [December 7, 2023, 2:33pm UTC](https://discourse.julialang.org/t/plotting-data-showing-2-sets-of-data/107272 "2023-12-07T14:33:57Z")

</div>

this is my code ‘’'begin 2 wind = CSV.File(WindGenFile) |\> DataFrame 3 rename!(wind, :" REGION" =\> :Region, :“DATE & TIME” =\> :DateTime, :" ACTUAL WIND(MW)" =\> :ActualWind, :" FORECAST REGION(MW)" =\> :ForecastWind) 5 …

---

## [Is the doc of VegaLote.jl up to date?](https://discourse.julialang.org/t/is-the-doc-of-vegalote-jl-up-to-date/104125)

<div class="topic-metadata">

**Author:** [@Axze-rgb](https://discourse.julialang.org/u/Axze-rgb)\
**Replies:** 4\
**Last updated:** [September 21, 2023, 10:27pm UTC](https://discourse.julialang.org/t/is-the-doc-of-vegalote-jl-up-to-date/104125 "2023-09-21T22:27:40Z")

</div>

Hello, I have asked this before but as a late edit in a thread . Therefore I thought I might as well make a dedicated thread. I have compared vegalite and glmakie and settled fot vegalite, I found Makie harder. Anyway, …

---

## [Can expressions containing syntax errors be used in macro calls?](https://discourse.julialang.org/t/can-expressions-containing-syntax-errors-be-used-in-macro-calls/103949)

<div class="topic-metadata">

**Author:** [@Tortar](https://discourse.julialang.org/u/Tortar)\
**Replies:** 2\
**Last updated:** [September 17, 2023, 1:57pm UTC](https://discourse.julialang.org/t/can-expressions-containing-syntax-errors-be-used-in-macro-calls/103949 "2023-09-17T13:57:59Z")

</div>

I’d like to use an expression like this one in a macro call struct A(B) x::Int end which gives a syntax error when called without the macro wrap: julia\> struct A(B) x::Int end ERROR: syntax: inva…

---

## [Precedence of \`=\` vs \`,\`](https://discourse.julialang.org/t/precedence-of-vs/101637)

<div class="topic-metadata">

**Author:** [@Neal\_Gafter](https://discourse.julialang.org/u/Neal_Gafter)\
**Replies:** 2\
**Last updated:** [July 14, 2023, 11:09pm UTC](https://discourse.julialang.org/t/precedence-of-vs/101637 "2023-07-14T23:09:49Z")

</div>

The precedence below seems inconsistent. In particular, the last result is unexpected. Is the Julia precedence “whatever the parser does”, or is there some underlying design? julia\> quote a, b end quote …

---

## [Is there a reason for the LCHF approach to syntactic sugar?](https://discourse.julialang.org/t/is-there-a-reason-for-the-lchf-approach-to-syntactic-sugar/99607)

<div class="topic-metadata">

**Author:** [@Euhan](https://discourse.julialang.org/u/Euhan)\
**Replies:** 2\
**Last updated:** [May 30, 2023, 2:20pm UTC](https://discourse.julialang.org/t/is-there-a-reason-for-the-lchf-approach-to-syntactic-sugar/99607 "2023-05-30T14:20:40Z")

</div>

Preamble/Disclaimer: This topic is about syntactic sugar that I find missing. I know that these tasks are not hard to accomplish in other ways. I often find that my assumptions about what functions extend to what types…

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