g000001 / lambda.output

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

output

This package consists mainly of a a collection of useful formatted output functions. All use \*STANDARD-OUTPUT*; none require an argument to specify the stream. The arguments follow a convention, usually, but there are exceptions. The first argument is usually the datum to be output. The second is usually the number of columns (minimum) to use. Then come any number of options, which are keywords followed by values.

Most functions accept an option :TAB-PERIOD, followed by a number, which specifies how far apart the padding points are. If the minimum width of the field is 10 and the tab-period is 5, then if the datum requires 12 columns it will be padded out to 15 columns (10 plus a multiple of 5). Another option which most functions allow is :PAD-CHAR, followed by the character to pad with (instead of Space). Another option is :MINPAD, followed by the minimum number of padding characters to use. Each function’s documentation says which options it accepts.

Use ONUM to output a number. You can specify the radix, the number of columns, and other padding options. Use OFLOAT to output a floating point number with a specified number of digits.

Use OCHAR to output a character. Three formats are available: one is a READable format using #\, one is the form ZWEI uses to describe a character (“Control-Rubout”, etc.), and one is the SAIL way of describing a character (“^BX”, etc).

Use OSTRING to output a string with padding. If no padding is desired PRINC is fine. Use OPRINT to PRIN1 an object with padding.

Use PLURAL to output a word in either singular or plural according to the value of a number. You specify only the singular and PLURAL computes the plural. If the plural is too irregular, you can specify it too. (PLURAL (ONUM X) ” frob”) prints X followed by ” frob” or ” frobs”.

Use PAD to perform more complicated padding functions. PAD can print several things with padding between them to pad the whole thing out to a desired width. Special cases include right or left justification or centering of any output within a desired width.

Use TAB to move to a specific column in the output (as opposed to padding a field to a specific width, which is independent of where the field starts). Or move to the next multiple of a tab-period; or TERPRI if already past the column.

Use BREAKLINE to go to a new line before some output if that output will not fit in the rest of the current line. You must specify the linel since the Lisp machine system has no convention for asking the stream.

Use OUTPUT to concatenate several pieces of output. OUTPUT is unlike the other functions in that the first argument specifies a stream; or NIL means cons up a string, or T means use \*STANDARD-OUTPUT*. NIL and T must appear explicitly because they are checked for at macro expansion time. The remaining args to OUTPUT perform output. A string is simply printed. Anything else is executed to perform the output and its value is ignored.

OUTFMT is like (LIST (OUTPUT NIL …)). It is good for places which expect a format control string; it causes FORMAT to be passed something which causes it to print exactly the output specified in the args to OUTFMT.

There is nothing in this package for outputting a new line. TERPRI is fine for that.

Example of use of this package: print the elements of a list, separated by commas, going to a new line before an element which doesn’t fit.

(defun pcl (list linel)
 (do ((l list (cdr l))) ((null l))
   (breakline linel "  "
     (princ (car l))
     (and (cdr l) (princ ", ")))))

Another example

 (output t "Total: " (plural (onum n-events) " event") ".")

This prints "Total: 1 event." or "Total: 5 events."

About


Languages

Language:Common Lisp 100.0%