1. astore

Stores stack elements into an array.

1.1. Syntax

any₀ ... anyₙ₋₁ array astore → array

1.2. Stack Effects

Table 1. Before
Level Object

n

any₀

…​

…​

1

anyₙ₋₁

0

array (length n)

Table 2. After
Level Object

0

array (filled with any₀ through anyₙ₋₁)

1.3. Description

astore stores objects from the operand stack into an array:

  1. Removes the array from the stack and determines its length n

  2. Removes n objects from the stack

  3. Stores them into the array (topmost stack element → array[n-1], bottommost → array[0])

  4. Pushes the array back onto the stack

The array must have been previously created with the correct length. astore cannot be performed on packed arrays (they are read-only).

1.4. PostScript Level

Level 1 and later

1.5. Examples

Basic storage
(a) (bcd) (ef) 3 array astore
% Result: [(a) (bcd) (ef)]
Building array from computations
10 20 add   % 30
30 40 add   % 70
50 60 add   % 110
3 array astore
% Result: [30 70 110]
Coordinate storage
100 200 2 array astore
/point exch def  % Store as /point

1.6. Common Use Cases

1.6.1. Matrix Construction

1 0 0 1 0 0 6 array astore  % Identity matrix
/identitymatrix exch def

1.6.2. Collecting Results

% Collect multiple function results
func1  % Returns value1
func2  % Returns value2
func3  % Returns value3
3 array astore  % [value1 value2 value3]

1.6.3. Parameter Arrays

/red 1 def /green 0 def /blue 0 def
red green blue 3 array astore
/rgbcolor exch def

1.7. Common Pitfalls

Array Size Must Match - The array must be exactly the right size for the number of objects on the stack.
1 2 3 4 array astore  % Only stores 3 items
% 4th element remains null
Stack Order - Objects are stored in reverse stack order: topmost stack element → highest array index.
1 2 3 3 array astore  % Result: [1 2 3]
                       % NOT [3 2 1]
Global/Local VM Restrictions - If the array is in global VM and any stored object is in local VM, [invalidaccess] error occurs.
Pre-create Array - Always create the array first with the correct size using array.

1.8. Error Conditions

Error Condition

[invalidaccess]

Array is in global VM and contains local VM objects, or array is read-only

[stackunderflow]

Fewer than n+1 objects on stack

[typecheck]

Operand is not an array

1.9. Implementation Notes

  • Cannot be used with packed arrays (they are read-only)

  • Elements are stored by reference (not copied) for composite objects

  • The array is modified in place

  • Most efficient for small to medium-sized arrays

1.10. Comparison with [ ]

% Using astore
1 2 3 3 array astore  % [1 2 3]

% Using [ ]
[ 1 2 3 ]             % [1 2 3] (more convenient)

The [ ] syntax is usually more convenient for literal arrays, but astore is useful when the array size is computed dynamically.

1.11. See Also

  • aload - Load array elements onto stack

  • array - Create new array

  • put - Put single value into array

  • putinterval - Put subarray into array

  • [ / ] - Array literal syntax


Back to top

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