Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Reid G.C.Thinking in PostScript.1990.pdf
Скачиваний:
17
Добавлен:
23.08.2013
Размер:
846.44 Кб
Скачать

CONDITIONALS ARE NOT MAGIC

A conditional statement is not magic. There is no operator in the PostScript language that is different from the others. Even though you will learn to think of the entire conditional as a single construction, it is not. Only the execution of the if and ifelse operators make something into a conditional. Otherwise, and until you execute one of those operators, the rest of the code is just a couple of procedures and a boolean on the operand stack.

Just to confuse you and to reinforce this point, let’s look at a simple conditional rearranged in a perfectly legal, although somewhat unusual, configuration. The first conditional (Example 7.9) is very straightforward. The second program (Example 7.10) has the same result, but is constructed very differently. The procedures for the true and false clauses are defined like any other procedure, then brought up on the operand with the load operator, ready for the final execution of ifelse. As an added twist, a random string is put on the stack in between, and then moved out of the way.

Example 7.9: Basic Conditional Statement

currentpoint exch pop 72 le { %ifelse showpage 72 650 moveto

}{

0 -12 rmoveto

} ifelse

Example 7.10: The Same Conditional Built on the Fly

%set up procedures to generate a boolean and to act as the

%“true” and “false” procedure bodies for “ifelse”

/off_bottom_of_page

% off_bottom_of_page bool

{ %def

 

 

currentpoint exch pop 72 le

% boolean is on stack

} bind def

/off_bottom_proc { showpage 72 650 moveto } bind def /regular_proc { 0 -12 rmoveto } bind def

%now invoke the conditional by loading the boolean and

%the two procedures onto the stack and rearranging them a

%little bit to show there is no magic:

86

Chapter 7: BUILDING CONDITIONAL STATEMENTS