Skip to main content

Types of brackets

What spaces, ;, ◇ and line breaks mean inside brackets, parentheses and braces

BPL has three kinds of bracket: brackets [ ], parentheses ( ) and braces { }. The separators space, ; and ◇ have different meanings in each kind of bracket. 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 and Dfns.

Inside Space ; ◇ or a line break
[ ] Separates items Separates items that contain spaces Separates rows of an array
( ) Separates runs Not allowed Separates rows of a vector
{ } Separates runs Separates bodies Separates statements
Top level Separates runs Not allowed Separates statements

A run is a sequence of tokens with no spaces between them. Syntax gives the rules for runs.

Brackets

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

a←1
b←2
[a b]
1 2

An item can be any expression without spaces:

[a+b a×b]
3 2

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

[c←1 ≥c]
1 2

To keep an expression containing spaces as one bracket item, put it in parentheses.

x←2 4 9
[(+/x ÷ ≢x) ≢x]
5 3ₓ

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

[+/x ; +/x ÷ ≢x]
15 5

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

[+/x ;
 +/x ÷ ≢x]
15 5

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

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

Rows of different lengths are padded with fill:

[1 2◇3 4 5]
1 2 0
3 4 5

You can’t use both ; and ◇ inside the same pair of brackets.

Brackets are not used for indexing. To select from an array, use Index ⌷, or a subscript for one position.

Parentheses

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

(2×3)+4
10

With ◇, a parenthesised list is a vector of rows, which can have different lengths. A row with one item is still a vector:

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:

("ab"
 "cd")
("ab"◇"cd")

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

[4◇4 5]
4 0
4 5

Braces

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

{x←ω
 ≥x}2
3

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

{ω<0?-ω;ω}¯3
3

The top level

Outside any bracket, ◇ and line breaks separate statements. A ; at the top level raises a SYNTAX error.