lang/postscript/ PostscriptStackOperations1


Taken from: http://www.linuxfocus.org/English/July1999/article80.html

pop: This operator discards the topmost element (last entered) of the operand stack

exch: This operator exchanges the two topmost elements of the operand stack

dup: This operator creates a copy of the last entered element of the operand stack and pushes it into the operand stack. In other words, it duplicates the topmost element.

copy: This operator needs an integer operand (parameter) which must be given to the operand stack before the operator acts. If we say n for this integer parameter then the command will be given as n copy. When this is done, the copy of the set of n topmost elements will be created and located into the operand stack as the last entered elements. In other words, copy is a set duplication operator.

index: This operator needs an integer operand which must be given to the operand stack before the operator acts. If we say n for this integer parameter then the command will be given as n index. When this is done, the copy of n-th topmost element will be created and located into the operand stack as the last entered element. In other words, index can select an internal element and create and locate its copy into the operand stack. The indexing of the elements starts from the topmost element with 0.

roll: This operator needs two integer parameters which must be given to the operand stack before the operator acts. If we say m and n for these integer parameters then the command will be given as m n index. Here, m denotes how many elements will be rolled while n characterizes the number of the rolls. One roll is defined in such a way that the topmost element of the operand stack becomes the m-th element while the set of m-1 elements below the topmost element is shifted one place to top. This scheme is valid when n is equal to 1. If it would be 2 then two consecutive rolls will be occurred. In other words m 2 roll is same with m 1 roll m 1 roll. The parameter n can take negative values. If this occurs, it reverses the action that happens when n is positive. This means that the global effect of the command m n roll m -n roll is neutral. It leaves the operand stack unchanged. The indexing of the elements starts from the topmost element with 0.

clear: This operator discards all elements of the operand stack.

count: This operator counts the elements of the operand stack. The result is pushed to the operand stack as a new element. If you do not want this new element then you can issue the composite command count pstack pop where pop removes the new element created by count after the result of the counting is displayed through the action of the file operator pstack.

mark: This operator puts a marktype (-marktype-) element into the operand stack. This element can be used to divide the set of elements in the operand stack into subsets. Two other operators cleartomark and counttomark seek this element for their actions. If not found then an error message is issued.

cleartomark: This operator removes all elements from the topmost one to the first -marktype-. This -marktype- object is also removed. If there is no marktype object in the operand stack then an error message is issued.

counttomark: This operator counts the elements starting from the topmost element until the marktype object is encountered. The result which is an integer value is pushed into the operand stack as the last element. The first encountered marktype element is not included in the result. If there is no marktype element in the operand stack then PostScript complains and does nothing.