1. [ and ] (Array Brackets)

Array construction operators that work together to create literal arrays in PostScript.

1.1. Overview

The bracket operators [ and ] provide the most convenient syntax for constructing arrays with known contents:

  • [ marks the beginning of array construction by pushing a mark on the operand stack

  • ] ends array construction by collecting all objects above the mark into a new array

These operators are typically used together as a pair to define literal arrays in PostScript code.

1.2. Syntax

1.2.1. [ (Left Bracket)

– [ → mark

1.2.2. ] (Right Bracket)

mark obj₀ ... objₙ₋₁ ] → array

1.3. Stack Effects

1.3.1. [ (Left Bracket)

Table 1. Before
Level Object

(empty or any objects)

Table 2. After
Level Object

0

mark (array construction marker)

1.3.2. ] (Right Bracket)

Table 3. Before
Level Object

n+1

mark

n

obj₀

…​

…​

0

objₙ₋₁

Table 4. After
Level Object

0

array (containing obj₀ through objₙ₋₁)

1.4. Description

1.4.1. How Array Construction Works

The [ operator pushes a special mark object on the operand stack to indicate the beginning of an array being constructed. It is functionally equivalent to the mark operator, but its use with ] gives it special significance for array construction.

The ] operator completes array construction by:

  1. Counting all objects on the operand stack down to the topmost mark

  2. Removing those objects from the stack

  3. Creating a new array containing those objects in order

  4. Removing the mark

  5. Pushing the new array on the stack

The resulting array is created with the literal attribute and allocated in local or global VM according to the current VM allocation mode.

1.5. PostScript Level

Level 1 and later

1.6. Examples

Simple array construction
[ 1 2 3 ]        % Creates array [1 2 3]
Mixed-type array
[ 42 (hello) /name true ]  % Array with different types
Nested arrays
[ 1 [ 2 3 ] 4 ]  % Array containing another array
% Result: [1 [2 3] 4]
Empty array
[ ]              % Creates empty array []
Computed values in arrays
[ 1 2 add 3 4 mul ]  % Expressions evaluated before array creation
% Result: [3 12]

[ 10 20 add 30 ]     % Creates [30 30]
Building array from existing stack values
1 2 3            % Stack: 1 2 3
mark exch exch exch  % Stack: mark 1 2 3
]                % Stack: [1 2 3]

1.7. Common Use Cases

1.7.1. Literal Data Structures

/colors [ /red /green /blue ] def
/coordinates [ 100 200 ] def
/primes [ 2 3 5 7 11 13 ] def

1.7.2. Procedure Arguments

[ 1 2 3 ] { 10 mul } forall  % Pass array to forall

1.7.3. Matrix Definitions

[ 1 0 0 1 0 0 ]  % Identity transformation matrix

1.7.4. Coordinate Pairs and Points

/point [ 100 200 ] def

1.7.5. Color Definitions

/red [ 1 0 0 ] def      % RGB
/cyan [ 0 1 1 1 ] def   % CMYK

1.8. Common Pitfalls

Unmatched Brackets - Every [ must have a corresponding ]. Unmatched brackets cause a [syntaxerror] or [unmatchedmark] error.
[ 1 2 3   % Missing ] causes syntaxerror
1 2 3 ]   % Missing [ causes unmatchedmark error
Execution vs. Literal - Objects between [ and ] are evaluated before being placed in the array.
[ 1 2 add ]      % Results in [3], not [1 2 add]

[ /x 5 def ]     % Executes def, creates [5]
                 % NOT [/x 5 def]
Literal vs. Executable Arrays - Arrays created by [ …​ ] have the literal attribute by default. To create an array without evaluating its contents, use the procedure syntax { …​ }. Use cvx to make a literal array executable if needed.
/proc { 1 2 add } def   % Procedure (unevaluated)
[ 1 2 add ]             % Array [3] (evaluated)

1.9. Error Conditions

Error Condition

[stackoverflow]

Operand stack overflow when pushing mark, or resulting array would overflow stack

[syntaxerror]

No matching ] before end of file/string

[unmatchedmark]

No mark on stack when ] is executed (no matching [)

[VMerror]

Insufficient VM to allocate array

1.10. Implementation Notes

  • The [ operator is functionally equivalent to mark

  • The ] operator is syntactic sugar recognized during parsing

  • Marks are used for error recovery and can be detected with counttomark

  • When scanned, [ …​ ] creates a literal array object

  • The objects are placed in the array in the order they appeared between brackets

  • Index 0 contains the first object after [

  • The interpreter treats [ and ] specially during scanning for array literal syntax

1.11. Relationship to Other Operators

1.11.1. Equivalence with mark

The [ operator is functionally equivalent to mark:

mark 1 2 3 ]     % Same as [ 1 2 3 ]
[ 1 2 3          % Must be closed with ]

However, [ and ] provide clearer syntax for array construction.

1.11.2. Comparison with astore

The ] operator is similar to astore but more convenient:

% Using [ ]
[ 1 2 3 ]

% Equivalent using astore
1 2 3 3 array astore

The bracket syntax is clearer and doesn’t require knowing the count in advance.

1.12. See Also


Back to top

Copyright © 2025 Ribose. PostScript is a trademark of Adobe. Distributed under the MIT License.