# Expressions separated by semicolon

**URL:** https://discourse.julialang.org/t/expressions-separated-by-semicolon/12638
**Category:** General Usage
**Created:** [July 24, 2018, 6:32pm UTC](https://discourse.julialang.org/t/expressions-separated-by-semicolon/12638 "2018-07-24T18:32:19Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![heliosdrm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heliosdrm/32/3851_2.png) [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)
#### Post date: [July 24, 2018, 6:32pm UTC](https://discourse.julialang.org/t/expressions-separated-by-semicolon/12638/1 "2018-07-24T18:32:19Z")

</div>

This happens in a tuple of expressions, when there is a semicolon that separates them:

```julia
julia> ex = :(a=1; b=2, c=3)
:(($(Expr(:parameters, :(b=2), :(c=3))), a = 1))

julia> dump(ex)
Expr
  head: Symbol tuple
  args: Array{Any}((2,))
    1: Expr
      head: Symbol parameters
      args: Array{Any}((2,))
        1: Expr
          head: Symbol kw
          args: Array{Any}((2,))
            1: Symbol b
            2: Int64 2
        2: Expr
          head: Symbol kw
          args: Array{Any}((2,))
            1: Symbol c
            2: Int64 3
    2: Expr
      head: Symbol =
      args: Array{Any}((2,))
        1: Symbol a
        2: Int64 1

julia> ex.args[1]
:($(Expr(:parameters, :(b=2), :(c=3))))

julia> ex.args[2]
:(a = 1)

```

I have failed to find the documentation of this. It seems as if it were to distinguish the keyword arguments (here called “parameters”) when the expressions are arguments of a function (or a macro?).

But if the parameters are the tail of the set of expressions, why is it that they are in the first place of `args`?

---

<div class="post-metadata">

### Author: ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)
#### Post date: [July 24, 2018, 6:46pm UTC](https://discourse.julialang.org/t/expressions-separated-by-semicolon/12638/2 "2018-07-24T18:46:58Z")

</div>

You mean `;`? That’s a semi-colon, not a colon.

Semi-colons work just as they do in other languages such as C++ and Java, they are just not required. A semi-colon denotes the end of an expression. For example, `using SomePackage;` and `using SomePackage` are the same if they are both followed by a new line. So, for example, in 0.7

```julia
(a=1; b=2)

```

assigns `1` to `a` and `2` to `b` and returns `b` (since it is the last expression). On the other hand

```julia
(a=1, b=2)

```

Is the syntax for a named tuple.

In function arguments `;` has a special purpose: to denote [keyword arguments](https://docs.julialang.org/en/latest/manual/functions/#Keyword-Arguments-1).

---

<div class="post-metadata">

### Author: ![heliosdrm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heliosdrm/32/3851_2.png) [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)
#### Post date: [July 25, 2018, 5:14am UTC](https://discourse.julialang.org/t/expressions-separated-by-semicolon/12638/3 "2018-07-25T05:14:19Z")

</div>

I meant semicolon, of course.

Thanks for the answer. I understand the difference between separating expressions by comma and semicolon. My question is rather why in `(a=1; b=2, c=3)` the tuple of expressions that is written after the semicolon (which is not actually a “tuple”, but “parameters”) comes first.

This leads to the following situation when evaluating macros:

```julia
julia> macro foo(firstexpression, otherexpressions...)
           print("First: "); println(firstexpression)
           println("Other:"); [println(ex) for ex in otherexpressions]
           quote end
       end
@foo (macro with 1 method)

julia> # This is expected
julia> @foo(sqrt(x), y^2, exp(c))
First: sqrt(x)
Other:
y ^ 2
exp(c)

julia> # But this not!
julia> @foo(sqrt(x); y^2, exp(c))
First: $(Expr(:parameters, :(y ^ 2), :(exp(c))))
Other:
sqrt(x)

```

```julia

```

---

<div class="post-metadata">

### Author: ![johnh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnh/32/3615_2.png) [@johnh](https://discourse.julialang.org/u/johnh)
#### Post date: [July 25, 2018, 9:32am UTC](https://discourse.julialang.org/t/expressions-separated-by-semicolon/12638/4 "2018-07-25T09:32:01Z")

</div>

The semicolon does have a purpose in the REPL. It suppresses the printing of the expression’s value.  
This of course follows on from @ExpandingMan saying the semicolon is the statement separator.

```julia
julia> a=1; b=2
2

julia> a=1; b=2;

```

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [July 25, 2018, 9:40am UTC](https://discourse.julialang.org/t/expressions-separated-by-semicolon/12638/5 "2018-07-25T09:40:27Z")

</div>

I am not sure this is valid syntax:

```julia
julia> (a=1; b=2, c=3)
ERROR: syntax: unexpected semicolon in tuple

julia> VERSION
v"0.7.0-beta2.99"

```

it is apparently parsed, too, it is just caught later. Eg

```julia
julia> function f(x, y, z)
       (a = x; b = y, c =z)
       end
ERROR: syntax: unexpected semicolon in tuple

```

What were you trying to accomplish with this syntax?

---

<div class="post-metadata">

### Author: ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)
#### Post date: [July 25, 2018, 11:59am UTC](https://discourse.julialang.org/t/expressions-separated-by-semicolon/12638/6 "2018-07-25T11:59:41Z")

</div>

This syntax is used for function calls

```nohighlight
julia> :(f(a=1;b=2,c=3)).args
3-element Array{Any,1}:
 :f                                     
 :($(Expr(:parameters, :(b=2), :(c=3))))
 :(a=1)   

```

---

<div class="post-metadata">

### Author: ![dfdx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfdx/32/120_2.png) [@dfdx](https://discourse.julialang.org/u/dfdx)
#### Post date: [July 25, 2018, 12:07pm UTC](https://discourse.julialang.org/t/expressions-separated-by-semicolon/12638/7 "2018-07-25T12:07:28Z")

</div>

> [@heliosdrm](#):
>
> My question is rather why in `(a=1; b=2, c=3)` the tuple of expressions that is written after the semicolon (which is not actually a “tuple”, but “parameters”) comes first.

So I understand the question is why `foo(a; b=1)` is parsed as:

```julia
Expr(:call, :foo, Expr(:parameters, Expr(:kw, :b, 1)), :a)

```

and not

```julia
Expr(:call, :foo, :a, Expr(:parameters, Expr(:kw, :b, 1)))

```

?

I haven’t found an answer to this, but decided that historically it might have been an attempt to distinguish them from keyword arguments, e.g. `foo(a, b=1)`:

```julia
Expr(:call, :foo, :a, Expr(:kw, :b, 1))

```

or ellipsis arguments like in `foo(a...; b=1)`

```julia
Expr(:call, :foo, Expr(:parameters, Expr(:kw, :b, 1)), Expr(:..., :a))

```

or whatever other corner case. Eventually, why not - keyword parameters are quite special in function calls, and although syntactically you have to put them at the end to distinguish from normal arguments, in AST you are free to represent them in whatever form is more convenient for processing.

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [July 25, 2018, 12:11pm UTC](https://discourse.julialang.org/t/expressions-separated-by-semicolon/12638/8 "2018-07-25T12:11:11Z")

</div>

> [@dfdx](#):
>
> Eventually, why not - keyword parameters are quite special in function calls, and although syntactically you have to put them at the end to distinguish from normal arguments

```julia
julia> f(a, b; x=3, y = 4) = a + b + x + y
f (generic function with 1 method)

julia> f(y=1, 2, x=3, 4)
10

```

---

<div class="post-metadata">

### Author: ![dfdx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfdx/32/120_2.png) [@dfdx](https://discourse.julialang.org/u/dfdx)
#### Post date: [July 25, 2018, 12:27pm UTC](https://discourse.julialang.org/t/expressions-separated-by-semicolon/12638/9 "2018-07-25T12:27:09Z")

</div>

Ah, right, I had function definition (i.e. `f(a, b; x=3, y = 4)`) in mind at the time of writing, there’s no such restriction in function call.
