The cl-wadler-pprint Reference Manual

Next: , Previous: , Up: (dir)   [Contents][Index]

The cl-wadler-pprint Reference Manual

This is the cl-wadler-pprint Reference Manual, version 0.1.0, generated automatically by Declt version 4.0 beta 2 "William Riker" on Thu Sep 15 04:17:12 2022 GMT+0.

Table of Contents


1 Introduction

cl-wadler-pprint

An implementation of "A Prettier Printer" by Philip Wadler in Common Lisp.

Example

(defclass foo ()
  ((bar :initarg :bar :reader bar)
   (baz :initarg :baz :reader quux)))

(def-pretty-object foo ()
  (bar baz))

; at width 80
(pretty t (make-instance 'foo :bar 1 :baz 2))
; #<FOO :BAR 1 :BAZ 2>

; at width 20
(pretty t (make-instance 'foo :bar 1 :baz 2))
; #<FOO :BAR 1
;       :BAZ 2>

TODOs

Notes

ABCL

In my entrypoint (written in Java), I've got a method:

import java.io.IOException;
import java.util.Scanner;
import org.armedbear.lisp.JavaObject;
import org.armedbear.lisp.Packages;

public static void updateRightMargin() {
	int rightMargin;
	try {
		Process proc = new ProcessBuilder("tput", "cols")
			.inheritIO()
			.redirectOutput(ProcessBuilder.Redirect.PIPE)
			.start();
		rightMargin = new Scanner(proc.getInputStream()).nextInt();
		if(proc.waitFor() != 0) {
			logError("Failed to update *PRINT-RIGHT-MARGIN*.");
			return;
		}
	} catch(InterruptedException ex) {
		logError("Failed to update *PRINT-RIGHT-MARGIN*: " + ex);
		return;
	} catch(IOException ex) {
		logError("Failed to update *PRINT-RIGHT-MARGIN*: " + ex);
		return;
	}

	Packages.findPackage("COMMON-LISP")
		.findAccessibleSymbol("*PRINT-RIGHT-MARGIN*")
		.setSymbolValue(JavaObject.getInstance(rightMargin, true));
}

and in main, code like:

import sun.misc.Signal;
import sun.misc.SignalHandler;

Signal.handle(new Signal("WINCH"), new SignalHandler() {
	public void handle(Signal sig) {
		Main.updateRightMargin();
	}
});
updateRightMargin();

2 Systems

The main system appears first, followed by any subsystem dependency.


Previous: , Up: Systems   [Contents][Index]

2.1 cl-wadler-pprint

An implementation of A Prettier Printer in Common Lisp.

Author

Nathan Ringo <nathan@remexre.xyz>

License

Apache-2.0/MIT

Version

0.1.0

Source

cl-wadler-pprint.asd.

Child Components

3 Files

Files are sorted by type and then listed depth-first from the systems components trees.


Previous: , Up: Files   [Contents][Index]

3.1 Lisp


Next: , Previous: , Up: Lisp   [Contents][Index]

3.1.1 cl-wadler-pprint/cl-wadler-pprint.asd

Source

cl-wadler-pprint.asd.

Parent Component

cl-wadler-pprint (system).

ASDF Systems

cl-wadler-pprint.


3.1.2 cl-wadler-pprint/package.lisp

Source

cl-wadler-pprint.asd.

Parent Component

cl-wadler-pprint (system).

Packages

wadler-pprint.


3.1.3 cl-wadler-pprint/wadler-pprint.lisp

Dependency

package.lisp (file).

Source

cl-wadler-pprint.asd.

Parent Component

cl-wadler-pprint (system).

Public Interface
Internals

4 Packages

Packages are listed by definition order.


Previous: , Up: Packages   [Contents][Index]

4.1 wadler-pprint

Source

package.lisp.

Use List

common-lisp.

Public Interface
Internals

5 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.


Next: , Previous: , Up: Definitions   [Contents][Index]

5.1 Public Interface


5.1.1 Macros

Macro: def-pretty-object (class (&key print-object) (&rest slots))
Package

wadler-pprint.

Source

wadler-pprint.lisp.


5.1.2 Ordinary functions

Function: bracket (l r &rest body)
Package

wadler-pprint.

Source

wadler-pprint.lisp.

Function: group (&rest doc)
Package

wadler-pprint.

Source

wadler-pprint.lisp.

Function: nest (width &rest doc)
Package

wadler-pprint.

Source

wadler-pprint.lisp.

Function: newline-or (str)
Package

wadler-pprint.

Source

wadler-pprint.lisp.

Function: pretty (stream value &key width)

Pretty-prints a VALUE to the given STREAM, with the given WIDTH.

Package

wadler-pprint.

Source

wadler-pprint.lisp.

Function: pretty* (stream doc &key width)

Pretty-prints a DOCument to the given STREAM, with the given WIDTH.

Package

wadler-pprint.

Source

wadler-pprint.lisp.

Function: spread (&rest docs)
Package

wadler-pprint.

Source

wadler-pprint.lisp.

Function: stack (&rest docs)
Package

wadler-pprint.

Source

wadler-pprint.lisp.

Function: text (str)
Package

wadler-pprint.

Source

wadler-pprint.lisp.


5.1.3 Generic functions

Generic Function: pretty-object (object)

Converts an object to a document.

Package

wadler-pprint.

Source

wadler-pprint.lisp.

Methods
Method: pretty-object (obj)
Method: pretty-object ((obj vector))
Method: pretty-object ((obj cons))

5.1.4 Structures

Structure: nest
Package

wadler-pprint.

Source

wadler-pprint.lisp.

Direct superclasses

structure-object.

Direct slots
Slot: width
Type

fixnum

Initform

(error "must provide width")

Readers

nest-width.

Writers

(setf nest-width).

Slot: doc
Type

wadler-pprint::doc

Initform

(error "must provide doc")

Readers

nest-doc.

Writers

(setf nest-doc).

Structure: text
Package

wadler-pprint.

Source

wadler-pprint.lisp.

Direct superclasses

structure-object.

Direct slots
Slot: string
Package

common-lisp.

Type

string

Initform

(error "must provide string")

Readers

text-string.

Writers

(setf text-string).


5.2 Internals


Next: , Previous: , Up: Internals   [Contents][Index]

5.2.1 Ordinary functions

Function: be (width posn docs)
Package

wadler-pprint.

Source

wadler-pprint.lisp.

Function: best (width posn doc)
Package

wadler-pprint.

Source

wadler-pprint.lisp.

Function: better (width posn x y)
Package

wadler-pprint.

Source

wadler-pprint.lisp.

Function: copy-flatten (instance)
Package

wadler-pprint.

Source

wadler-pprint.lisp.

Function: copy-nest (instance)
Package

wadler-pprint.

Source

wadler-pprint.lisp.

Function: copy-newline (instance)
Package

wadler-pprint.

Source

wadler-pprint.lisp.

Function: copy-text (instance)
Package

wadler-pprint.

Source

wadler-pprint.lisp.

Function: copy-union-doc (instance)
Package

wadler-pprint.

Source

wadler-pprint.lisp.

Function: docp (doc)

Returns whether the given value is a document.

Package

wadler-pprint.

Source

wadler-pprint.lisp.

Function: first-layout (docs)
Package

wadler-pprint.

Source

wadler-pprint.lisp.

Function: fits (width layout-doc)

Returns whether a given LAYOUT-DOC occupies no more than WIDTH bytes.

Package

wadler-pprint.

Source

wadler-pprint.lisp.

Function: flatten (doc)
Package

wadler-pprint.

Source

wadler-pprint.lisp.

Reader: flatten-doc (instance)
Writer: (setf flatten-doc) (instance)
Package

wadler-pprint.

Source

wadler-pprint.lisp.

Target Slot

doc.

Function: flatten-p (object)
Package

wadler-pprint.

Source

wadler-pprint.lisp.

Function: join (list sep)
Package

wadler-pprint.

Source

wadler-pprint.lisp.

Function: make-flatten (&key doc)
Package

wadler-pprint.

Source

wadler-pprint.lisp.

Function: make-nest (&key width doc)
Package

wadler-pprint.

Source

wadler-pprint.lisp.

Function: make-newline (&key string)
Package

wadler-pprint.

Source

wadler-pprint.lisp.

Function: make-text (&key string)
Package

wadler-pprint.

Source

wadler-pprint.lisp.

Function: make-union-doc (&key lhs rhs)
Package

wadler-pprint.

Source

wadler-pprint.lisp.

Reader: nest-doc (instance)
Writer: (setf nest-doc) (instance)
Package

wadler-pprint.

Source

wadler-pprint.lisp.

Target Slot

doc.

Function: nest-p (object)
Package

wadler-pprint.

Source

wadler-pprint.lisp.

Reader: nest-width (instance)
Writer: (setf nest-width) (instance)
Package

wadler-pprint.

Source

wadler-pprint.lisp.

Target Slot

width.

Function: newline-p (object)
Package

wadler-pprint.

Source

wadler-pprint.lisp.

Reader: newline-string (instance)
Writer: (setf newline-string) (instance)
Package

wadler-pprint.

Source

wadler-pprint.lisp.

Target Slot

string.

Function: pretty-tail (obj)
Package

wadler-pprint.

Source

wadler-pprint.lisp.

Function: text-p (object)
Package

wadler-pprint.

Source

wadler-pprint.lisp.

Reader: text-string (instance)
Writer: (setf text-string) (instance)
Package

wadler-pprint.

Source

wadler-pprint.lisp.

Target Slot

string.

Reader: union-doc-lhs (instance)
Writer: (setf union-doc-lhs) (instance)
Package

wadler-pprint.

Source

wadler-pprint.lisp.

Target Slot

lhs.

Function: union-doc-p (object)
Package

wadler-pprint.

Source

wadler-pprint.lisp.

Reader: union-doc-rhs (instance)
Writer: (setf union-doc-rhs) (instance)
Package

wadler-pprint.

Source

wadler-pprint.lisp.

Target Slot

rhs.


Next: , Previous: , Up: Internals   [Contents][Index]

5.2.2 Structures

Structure: flatten
Package

wadler-pprint.

Source

wadler-pprint.lisp.

Direct superclasses

structure-object.

Direct slots
Slot: doc
Type

wadler-pprint::doc

Initform

(error "must provide doc")

Readers

flatten-doc.

Writers

(setf flatten-doc).

Structure: newline
Package

wadler-pprint.

Source

wadler-pprint.lisp.

Direct superclasses

structure-object.

Direct slots
Slot: string
Package

common-lisp.

Type

string

Initform

(error "must provide string")

Readers

newline-string.

Writers

(setf newline-string).

Structure: union-doc
Package

wadler-pprint.

Source

wadler-pprint.lisp.

Direct superclasses

structure-object.

Direct slots
Slot: lhs
Type

wadler-pprint::doc

Initform

(error "must provide lhs")

Readers

union-doc-lhs.

Writers

(setf union-doc-lhs).

Slot: rhs
Type

wadler-pprint::doc

Initform

(error "must provide rhs")

Readers

union-doc-rhs.

Writers

(setf union-doc-rhs).


Previous: , Up: Internals   [Contents][Index]

5.2.3 Types

Type: doc ()

An imprecise check for whether a value is a document.

Package

wadler-pprint.

Source

wadler-pprint.lisp.


Appendix A Indexes


Next: , Previous: , Up: Indexes   [Contents][Index]

A.1 Concepts


Next: , Previous: , Up: Indexes   [Contents][Index]

A.2 Functions

Jump to:   (  
B   C   D   F   G   J   M   N   P   S   T   U  
Index Entry  Section

(
(setf flatten-doc): Private ordinary functions
(setf nest-doc): Private ordinary functions
(setf nest-width): Private ordinary functions
(setf newline-string): Private ordinary functions
(setf text-string): Private ordinary functions
(setf union-doc-lhs): Private ordinary functions
(setf union-doc-rhs): Private ordinary functions

B
be: Private ordinary functions
best: Private ordinary functions
better: Private ordinary functions
bracket: Public ordinary functions

C
copy-flatten: Private ordinary functions
copy-nest: Private ordinary functions
copy-newline: Private ordinary functions
copy-text: Private ordinary functions
copy-union-doc: Private ordinary functions

D
def-pretty-object: Public macros
docp: Private ordinary functions

F
first-layout: Private ordinary functions
fits: Private ordinary functions
flatten: Private ordinary functions
flatten-doc: Private ordinary functions
flatten-p: Private ordinary functions
Function, (setf flatten-doc): Private ordinary functions
Function, (setf nest-doc): Private ordinary functions
Function, (setf nest-width): Private ordinary functions
Function, (setf newline-string): Private ordinary functions
Function, (setf text-string): Private ordinary functions
Function, (setf union-doc-lhs): Private ordinary functions
Function, (setf union-doc-rhs): Private ordinary functions
Function, be: Private ordinary functions
Function, best: Private ordinary functions
Function, better: Private ordinary functions
Function, bracket: Public ordinary functions
Function, copy-flatten: Private ordinary functions
Function, copy-nest: Private ordinary functions
Function, copy-newline: Private ordinary functions
Function, copy-text: Private ordinary functions
Function, copy-union-doc: Private ordinary functions
Function, docp: Private ordinary functions
Function, first-layout: Private ordinary functions
Function, fits: Private ordinary functions
Function, flatten: Private ordinary functions
Function, flatten-doc: Private ordinary functions
Function, flatten-p: Private ordinary functions
Function, group: Public ordinary functions
Function, join: Private ordinary functions
Function, make-flatten: Private ordinary functions
Function, make-nest: Private ordinary functions
Function, make-newline: Private ordinary functions
Function, make-text: Private ordinary functions
Function, make-union-doc: Private ordinary functions
Function, nest: Public ordinary functions
Function, nest-doc: Private ordinary functions
Function, nest-p: Private ordinary functions
Function, nest-width: Private ordinary functions
Function, newline-or: Public ordinary functions
Function, newline-p: Private ordinary functions
Function, newline-string: Private ordinary functions
Function, pretty: Public ordinary functions
Function, pretty*: Public ordinary functions
Function, pretty-tail: Private ordinary functions
Function, spread: Public ordinary functions
Function, stack: Public ordinary functions
Function, text: Public ordinary functions
Function, text-p: Private ordinary functions
Function, text-string: Private ordinary functions
Function, union-doc-lhs: Private ordinary functions
Function, union-doc-p: Private ordinary functions
Function, union-doc-rhs: Private ordinary functions

G
Generic Function, pretty-object: Public generic functions
group: Public ordinary functions

J
join: Private ordinary functions

M
Macro, def-pretty-object: Public macros
make-flatten: Private ordinary functions
make-nest: Private ordinary functions
make-newline: Private ordinary functions
make-text: Private ordinary functions
make-union-doc: Private ordinary functions
Method, pretty-object: Public generic functions
Method, pretty-object: Public generic functions
Method, pretty-object: Public generic functions

N
nest: Public ordinary functions
nest-doc: Private ordinary functions
nest-p: Private ordinary functions
nest-width: Private ordinary functions
newline-or: Public ordinary functions
newline-p: Private ordinary functions
newline-string: Private ordinary functions

P
pretty: Public ordinary functions
pretty*: Public ordinary functions
pretty-object: Public generic functions
pretty-object: Public generic functions
pretty-object: Public generic functions
pretty-object: Public generic functions
pretty-tail: Private ordinary functions

S
spread: Public ordinary functions
stack: Public ordinary functions

T
text: Public ordinary functions
text-p: Private ordinary functions
text-string: Private ordinary functions

U
union-doc-lhs: Private ordinary functions
union-doc-p: Private ordinary functions
union-doc-rhs: Private ordinary functions

Jump to:   (  
B   C   D   F   G   J   M   N   P   S   T   U