Workshop: Towards Highly Portable Software Jakarta, 20 – 23 January 2003 Diselenggarakan oleh...

9
Workshop: Towards Highly Portable Software Jakarta, 20 – 23 January 2003 Diselenggarakan oleh Universitas Indonesia Using Pretty Printing Combinator Dr. Ir. I.S.W.B. Prasetya [email protected] A. Azurat S.Kom. [email protected]

Transcript of Workshop: Towards Highly Portable Software Jakarta, 20 – 23 January 2003 Diselenggarakan oleh...

Page 1: Workshop: Towards Highly Portable Software Jakarta, 20 – 23 January 2003 Diselenggarakan oleh Universitas IndonesiaUniversitas Indonesia Using Pretty Printing.

Workshop: Towards Highly Portable SoftwareJakarta, 20 – 23 January 2003

Diselenggarakan oleh Universitas Indonesia

Using Pretty Printing Combinator

Dr. Ir. I.S.W.B. Prasetya [email protected]. Azurat S.Kom. [email protected]

Page 2: Workshop: Towards Highly Portable Software Jakarta, 20 – 23 January 2003 Diselenggarakan oleh Universitas IndonesiaUniversitas Indonesia Using Pretty Printing.

2

Pretty Printing Library

How to pretty print some output nicely based on some layout

→ use lay out combinator (use UU_Pretty Library)

Run hugs with option :

hugs -98 +o –P:”c:\tools\UU.lib”

height

width

last line

Page 3: Workshop: Towards Highly Portable Software Jakarta, 20 – 23 January 2003 Diselenggarakan oleh Universitas IndonesiaUniversitas Indonesia Using Pretty Printing.

3

PP Document

The basic building blocks for pretty-printing are PP documents (of type PP_Doc).

You obtain PP documents either by :1. using the primitive text 2. combining PP documents with the pretty-printing

operators.

Page 4: Workshop: Towards Highly Portable Software Jakarta, 20 – 23 January 2003 Diselenggarakan oleh Universitas IndonesiaUniversitas Indonesia Using Pretty Printing.

4

Basic interface

Interface Comments

emptyThe empty PP document and null element for the operations beside and above

text s Converts the string s into a PP document

render ppd pw

Prints the PP document ppd (to IO ()) in a page pw (>=0) wide

Page 5: Workshop: Towards Highly Portable Software Jakarta, 20 – 23 January 2003 Diselenggarakan oleh Universitas IndonesiaUniversitas Indonesia Using Pretty Printing.

5

example

We are ready to try out the first examples:

> tenplus = "01234567890 ha!"

> t_text = render (text tenplus) 15

whose output is 0123456789 ha!.

But:

> t_error = render (text tenplus) 10

will result in <************>, because the page is not wide enough. The number of characters of the output line is the actual width of the input string.

Page 6: Workshop: Towards Highly Portable Software Jakarta, 20 – 23 January 2003 Diselenggarakan oleh Universitas IndonesiaUniversitas Indonesia Using Pretty Printing.

6

Basic Combinator

x >|< y x beside y

x >-< y x above y

Page 7: Workshop: Towards Highly Portable Software Jakarta, 20 – 23 January 2003 Diselenggarakan oleh Universitas IndonesiaUniversitas Indonesia Using Pretty Printing.

7

example

Horizontal (beside) and vertical (above) composition are the principal combinators used to build more complex documents.

For example:

> hello = "hello"

> world = "world!"

> h_beside_w = hello >|< world

> t_beside = render h_beside_w 20

(Hint: Try to use >#< instead of >|< , what is the difference ? )

Page 8: Workshop: Towards Highly Portable Software Jakarta, 20 – 23 January 2003 Diselenggarakan oleh Universitas IndonesiaUniversitas Indonesia Using Pretty Printing.

8

Exercise

Run hugs with option :

-98 +o –P:”c:\tools\UU.lib”

Page 9: Workshop: Towards Highly Portable Software Jakarta, 20 – 23 January 2003 Diselenggarakan oleh Universitas IndonesiaUniversitas Indonesia Using Pretty Printing.

9