# Types of brackets


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

BPL has three kinds of bracket: brackets `[ ]`, parentheses `( )` and
braces `{ }`. Each gives its own meaning to the separators space, `;`
and `⋄`. A line break means `⋄`, except just inside a bracket or next to
`;`, `⋄` or `?`, where it separates nothing. For what brackets and
braces create, see [Arrays](arrays.ipynb) and [Dfns](dfns.ipynb).

<table>
<colgroup>
<col style="width: 25%" />
<col style="width: 25%" />
<col style="width: 25%" />
<col style="width: 25%" />
</colgroup>
<thead>
<tr>
<th>Inside</th>
<th>Space</th>
<th><code>;</code></th>
<th><code>⋄</code> or a line break</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>[ ]</code></td>
<td>Separates items</td>
<td>Separates items that contain spaces</td>
<td>Separates rows of an array</td>
</tr>
<tr>
<td><code>( )</code></td>
<td>Separates runs</td>
<td>Not allowed</td>
<td>Separates rows of a vector</td>
</tr>
<tr>
<td><code>{ }</code></td>
<td>Separates runs</td>
<td>Separates bodies</td>
<td>Separates statements</td>
</tr>
<tr>
<td>Top level</td>
<td>Separates runs</td>
<td>Not allowed</td>
<td>Separates statements</td>
</tr>
</tbody>
</table>

A [run](terms.qmd#term-run) is a sequence of tokens with no spaces
between them. [Syntax](syntax.qmd#runs) gives the rules for runs.

## Brackets

Brackets are used to write vectors. Inside brackets, spaces separate
items:

``` bpl
a←1
b←2
[a b]
```

    1 2

An item can be any expression without spaces:

``` bpl
[a+b a×b]
```

    3 2

An item can use a name that an earlier item assigns, because items are
evaluated left to right:

``` bpl
[c←1 c+1]
```

    1 2

An item that needs spaces goes in parentheses:

``` bpl
x←2 4 9
[(+/x) ≢x]
```

    15 3ₓ

When several items need spaces, separate them with `;` and write each
item as you would outside brackets:

``` bpl
[+/x ; +/x ÷ ≢x]
```

    15 5

A `;` list can run over several lines, because a line break after `;`
separates nothing:

``` bpl
[+/x ;
 +/x ÷ ≢x]
```

    15 5

With `⋄` or a line break, a bracket list is an array whose major cells
are the rows:

``` bpl
m←[1 2 3
   4 5 6]
m
```

    1 2 3
    4 5 6

Rows of different lengths are padded with fill:

``` bpl
[1 2 ⋄ 3 4 5]
```

    1 2 0
    3 4 5

One pair of brackets can’t use both `;` and `⋄`.

Brackets don’t index. Selection uses [Index](glyphs/squad.qmd), `⌷`, or
a [subscript](scripts.ipynb#subscripts) for one position.

## Parentheses

Parentheses group one expression, read as it would be at the top level:

``` bpl
(2×3)+4
```

    10

With `⋄`, a parenthesised list is a vector of rows of any length. A row
with one item is still a vector:

``` bpl
rows←(4 ⋄ 4 5)
rows
⍴¨rows
```

    (4 ⋄ 4 5)

    (1 ⋄ 2)ₓ

Inside parentheses, a line break starts a new row, as `⋄` does, rather
than continuing the expression:

``` bpl
("ab"
 "cd")
```

    ("ab" ⋄ "cd")

In brackets, the same rows form one array, padded with fill:

``` bpl
[4 ⋄ 4 5]
```

    4 0
    4 5

## Braces

Braces define a function, whose statements are separated by `⋄` or line
breaks:

``` bpl
{x←⍵
 x+1}2
```

    3

When a body’s predicate `C?` is false, evaluation moves on to the next
body after `;`:

``` bpl
{⍵<0?-⍵;⍵}¯3
```

    3

## The top level

Outside any bracket, `⋄` and line breaks separate statements. A `;`
there is a `SYNTAX` error.
