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

CONCLUDING THOUGHTS

Although the data structures we have discussed in this chapter are very sound principles in computer science, they may not be the most appropriate storage paradigm in your PostScript program. Think very carefully about the relationships between your data elements and the way that they will be created, used, and destroyed. Consider the benefits and drawbacks of arrays, dictionaries, and the operand stack before deciding on the final representation for your data structures. Keep these points in mind as you read about program data and instructions in the next chapter.

EXERCISES

1.When drawing a vertical line, you only need the x coordinate once, since it is the same for both endpoints of the line. Design a procedure called V that draws only vertical lines. Your procedure should be able to draw a line at any thickness, at any x,y location, and of any length.

2.In order to underline some text, you must determine the position and thickness to draw the line.

a.What are the disadvantages to performing this calculation in your PostScript code?

b.What are the disadvantages to performing the underlining calculation in your word processor application?

3.Create a data structure that could serve as a stack (you can restrict its size to 50 elements). Write two procedures called stackpush and stackget that will let you place objects on your stack and then retrieve them back again. The stackpush procedure should take just one argu- ment—the object to be pushed onto the stack data structure. The stackget procedure should return one value onto the operand stack—the value retrieved from the stack data structure. Don’t worry about stack overflow or underflow error conditions.

156

Chapter 12: STORING AND USING DATA