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

making the basic language easy to learn, but offering a very rich and sometimes intimidating array of possibilities.

Data are not shared in the same way in the UNIX shell as they are in the PostScript language, since the shell provides a pipeline mechanism for communicating between processes, whereas the PostScript language has an operand stack where all operators look for their operands (and leave their results).

The comparison with the UNIX operating system is offered only to trick you into thinking about the language as a set of powerful operators set in the framework of a simple interpreted programming language. If you are an experienced UNIX programmer, you probably have developed a feel for the kinds of problems that are best solved with shell scripts versus those that require the writing of full-fledged C programs. If your PostScript programming task is in an environment where you have the opportunity to balance the work load between a C program and a PostScript program (in a client / server environment for example), this analogy may give you a feel for the kinds of tasks that might be more appropriate for each side of the equation.

INPUT, OUTPUT, AND THROUGHPUT

A program is usually only as good as the data you put through it. Most programs do not come with data already in them, you have to provide the data, and wait for the program to provide output based on the input. This is also true with PostScript, although the input and output may depend on the environment in which the program operates. For example, a PostScript program is often just a vehicle for printing or displaying information. In this sense, the data are provided en masse from a document, and the output of the program is simply the display or printing of the data in the document.

The input and output of a program depend greatly upon the environment in which the program is running. If your PostScript program is running on an interpreter built into your laser printer, there are few choices for input and output. The input can either come from the cable leading into the laser printer (which is also where the program comes from, typically) or it can come from an internal disk system built into the printer. The choices of output are the same, although the output can also be the printed page itself

14

Chapter 2: POSTSCRIPT IS NOT LIKE C

(which is normally the whole point of PostScript programming). In this case, the throughput of the program can be measured by how fast the pages print when you send it your program to draw pictures. And it is very much up to you and your program to control how fast those pages print.

The vast majority of all computer programs in existence today simply read data from a file, let you edit the data in some way, and then write it back to a file again. These are thought of as editors, word processors, spread sheets, drawing programs, statistical packages, and so forth. The files they read and write are documents. For the most part, documents are not interchangeable between systems or programs, so you just read into and write out from your single program, and hope to glean something useful from the data itself when the document is visible in the program.

PostScript programs rarely operate directly on files and usually are not constructed just to rearrange bodies of data. PostScript is a language designed for expression of visual images, communication of data to remote systems, and one-way data manipulation. Throughput is everything. PostScript programs are perhaps more analogous to utility programs or device drivers, where the task is not to perform a specific application task, but to provide a general mechanism for accomplishing data transfer, imaging, or device control. The input may well be arbitrary (as opposed to a carefully constructed data file), and the output may be simply a sheet of paper with some marks on the surface.

CONCLUDING THOUGHTS

This chapter positions PostScript alongside popular conventional languages such as C, to point out the similarities and differences in a slightly abstract sense. The ideas presented may raise more questions than they provide answers, but they should arm you with a sense of perspective on the PostScript language that will help you approach challenging programming tasks with some imagination, confidence, and with open eyes. The comparison with C, in particular, might help by convincing you to revisit some old habits of programming as you implement the guts of your program. Writing loops, making simple ifelse statements, and inventing variables should be done with a full appreciation of the language and understanding of its strengths and weaknesses.

Chapter 2: POSTSCRIPT IS NOT LIKE C

15

The next chapters get increasingly specific about the PostScript language and help you to build a solid foundation of programming skills.

EXERCISES

1. Rewrite the following C program segment in PostScript:

factorial = 1;

for ( index = 10; index > 0; index-- )

{

factorial = factorial * index;

}

printf ( “10 factorial is %d\n”, factorial );

2.What would you say are PostScript’s greatest strengths as a generalpurpose programming language? What are its greatest weakness?

3.Name four basic language constructs that are available in both the C and PostScript languages (or, if you don’t know C, pick any language of your choice).

4.Name three things provided in the PostScript language that are not provided as a standard part of any other language.

16

Chapter 2: POSTSCRIPT IS NOT LIKE C