Print library

Previous Page TOC Index Next Page See Page

Mindy Compiler Mindy Debugger Mindy Object Extensions Streams Library Standard IO Print Library Format Library Melange Interface TK Library Collection extensions Table Extensions String extensions Regular Expressions Transcendental Library Time Library Random Library Matrix Library


The Print Library

Designed by the Gwydion Project

Version 1.0 : 04 June 97

This document describes the Print library designed by the Gwydion Project at Carnegie Mellon University. This library provides an interface that outputs an object in Dylan literal syntax if the object can be represented as a Dylan literal, and otherwise, outputs the object in an implementation-dependent manner. There are essentially two functions, print and print-object. The print function accepts keyword arguments that form a print request, controlling features such as circular printing, how deep within a data structure to print, how many elements in long sequences to print before using an ellipsis notation, whether pretty printing is desired, and so on. Users extend print’s ability to print various objects by adding methods to the print-object function. The print function handles most of the overhead to satisfy special print requests, outputting any special notations required, and it only calls print-object when it is necessary to print objects. Users should always call the print function to output objects, especially recursively from within print-object methods to output an object’s components. Users should never call print-object directly.

The Print library exports two modules, Print and Pprint. The Gwydion implementation of this library requires the Gwydion Streams library.

1. Print Functions

The Print module offers two functions for users to call to print objects, print and print-to-string.

*default-level* [Variable]

*default-length* [Variable]

*default-circle?* [Variable]

*default-pretty?* [Variable]

print [Function]

Arguments

length :: false-or(<fixed-integer>) = *default-level*,

circle? :: <boolean> = *default-circle?*,

pretty? :: <boolean> = *default-pretty?*

Values
Description

print-to-string [Function]

Arguments

length :: false-or(<fixed-integer>) = *default-level*,

circle? :: <boolean> = *default-circle?*,

pretty? :: <boolean> = *default-pretty?*

Values
Description

print-object [Generic Function]

Arguments
Values
Description

2. Print Request Inspection Functions

The Print module exports the following functions for querying the print request and current print state:

print-length [Function]

Arguments
Values
Description

print-level [Function]

Arguments
Values
Description

print-depth [Function]

Arguments
Values
Description

print-circle? [Function]

Arguments
Values
Description

print-pretty? [Function]

Arguments
Values
Description

3. Pretty Printing

The Print library implements most of the pretty printing technology described by Richard C. Waters in Common Lisp The Language, second edition. The interface is slightly different because Mindy does not have macros. This section only summarizes the pretty printing functionality to provide a quick reference for users of the Print library, and readers should refer to the Common Lisp manual for more details.

When writing print-object methods, users can ignore whether pretty printing is in effect. If you write your print-object method using pretty printing functions, then when pretty printing is in effect, the output will be pretty printed. When pretty printing is not in effect, your method will produce output as though you had not written it to use pretty printing. All print-object methods that are written to do pretty printing must call the pretty printing functions within the dynamic scope of a call to pprint-logical-block; otherwise, the pretty printing functions are no-ops.

The Pprint module exports the following variables:

*default-line-length* [Variable]

*print-miser-width* [Variable]

pprint-logical-block [Function]

Arguments

per-line-prefix :: false-or(<byte-string>)

body :: <function>

suffix :: false-or(<byte-string>)

column :: limited(<fixed-integer>, min: 0)

Values
Description

pprint-newline [Function]

Arguments
Values
Description

Emit a newline if the current section of output does not fit on one line.

Emit a newline if any #"linear" newline in the current section needs to be emitted. That is, if a current section of output cannot fit on one line, and any one of the #"linear" newlines in the section needs to be emitted, then emit them all.

Emit a newline as if it were a #"linear" newline, but only when miser mode is in effect. Miser style is in effect when a logical block starts past a particular column of output.

Emit a newline always. Establish that any containing sections cannot be printed on a single line so that #"linear" and #"miser" newlines will be emitted as appropriate.

pprint-indent [Function]

Arguments
Values
Description

pprint-tab [Function]

Arguments
Values
Description

Tab to output column colnum. If the output is already at or beyond colnum, then add colinc to colnum until printing can continue at a column beyond the end of the output already on the line.

Output colnum spaces. Then output enough spaces to tab to a column that is a multiple of colinc from the beginning of the line.

This is similar to #"line", but column counting is relative to the beginning of the current section rather than the beginning of the line.

This is similar to #"line-relative", but column counting is relative to the beginning of the current section rather than the beginning of the line.

Mindy Compiler Mindy Debugger Mindy Object Extensions Streams Library Standard IO Print Library Format Library Melange Interface TK Library Collection extensions Table Extensions String extensions Regular Expressions Transcendental Library Time Library Random Library Matrix Library

Previous Page TOC Index Next Page See Page

Copyright 1994, 1995, 1996, 1997 Carnegie Mellon University. All rights reserved.

Send comments and bug reports to gwydion-bugs@cs.cmu.edu