Commands for manipulating the operand stack in PostScript.

1. Overview

The operand stack is fundamental to PostScript execution. These operators provide essential capabilities for managing stack contents, including duplicating, exchanging, copying, and removing elements.

2. Stack Manipulation Commands

Command Description

pop

Remove the top element from the stack

exch

Exchange the top two stack elements

dup

Duplicate the top element

copy

Copy top n elements or duplicate composite object values

psindex

Duplicate the nth element from the top

roll

Roll n elements j times

count

Count elements on the stack

clear

Remove all elements from the stack

mark

Push a mark object onto the stack

cleartomark

Pop elements down to and including a mark

counttomark

Count elements down to a mark

3. Common Patterns

Stack manipulation operators are often used in combination:

% Duplicate and swap
5 dup exch          % Create two copies and swap positions

% Copy multiple elements
1 2 3 3 copy        % Duplicate top 3 elements

% Access deep element
a b c d 3 index     % Copy element 3 positions down

4. See Also