Types of brackets

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

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 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]
1 2

An item that needs spaces goes in parentheses:

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:

[+/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

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

Brackets don’t index. Selection uses 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 of any length. 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+1}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 ; there is a SYNTAX error.