THE FORMAT FUNCTION



DO FORMATTED OUTPUT

(format <stream> <fmt> [<arg>...])

The format string can contain characters that should be copied directly to the output and formatting directives. The formatting directives are:

	~A or ~a	print next argument using princ
	~S or ~s	print next argument using prin1
	~D or ~d	print next argument as decimal integer
	~E or ~e	print next argument in exponential form
	~F or ~f	print next argument in fixed point form
	~G or ~g	print next argument using either ~E or ~F depending on magnitude
	~O or ~o	print next argument as octal integer
	~X or ~x	print next argument as hexidecimal integer
	~%	start a new line
	~&	start a new line if not on a new line
	~|	start a new page
	~?	use next argument as recursive format string
	~( ~)	process format string with case conversion
	~{ ~}	process format string repetitively
	~[ ~; ~]	process format string conditionally
	~*	skip arguments
	~t or ~T	go to a specified column
	~~	print a tilde character
	~\n	ignore return and following whitespace
The format directives can contain optional prefix and optional colon (:) or at-sign (@) modifiers between the tilde and directive character. Prefix characters are unsigned integers, the character '#' which represents the remaining number of arguments, the character 'v' to indicate the number is taken from the next argument, or a single quote (') followed by a single character for those parameters that should be a single character.

For ~A and ~S the full form is:

	~mincol,colinc,minpad,padchar:@A	(or S)
If : is given, NIL will print as "()" rather than "NIL". The string is padded on the right (or left, if @ is given) with at least "minpad" copies of the "padchar". Padding characters are then inserted "colinc" characters at a time until the total width is at least "mincol". The defaults are 0 for mincol and minpad, 1 for colinc, and #\space for padchar. For example:

	~15,,2,'.@A
The output is padded on the left with at least 2 periods until the output is at least 15 characters wide.

For ~D, ~O, and ~X the full form is ("D" shown):

	~mincol,padchar@D
If the argument is not a FIXNUM, then the format "~mincolA" is used. If "mincol" is specified then the number is padded on the left to be at least that many characters long using "padchar". "padchar" defaults to #\space. If @ is used and the value is positive, then a leading plus sign is printed before the first digit.

For ~E ~F and ~G the full form is:

	~mincol,round,padchar@E		(or F or G)
(This implementation is not Common Lisp compatible.) If the argument is not a real number (FIXNUM, RATIO, or FLONUM), then the format "~mincol,padcharD" is used. The number is printed using the C language e, f, or g formats. If the number could potentially take more than 100 digits to print, then F format is forced to E format, although some C libraries will do this at a lower number of digits. If "round" is specified, than that is the number of digits to the right of the decimal point that will be printed, otherwise six digits (or whatever is necessary in G format) are printed. In G format, trailing zeroes are deleted and exponential notation is used if the exponent of the number is greater than the precision or less than -4. If the @ modifier is used, a leading plus sign is printed before positive values. If "mincol" is specified, the number is padded on the left to be at least "mincol" characters long using "padchar". "padchar" defaults to #\space.

For ~%, ~|, and ~~, the full form is ~n%, ~n|, or ~n~. "n" copies (default=1) of the character are output.

For ~&, the full form is ~n&. ~0& does nothing. Otherwise enough new line characters are emited to move down to the "n"th new line (default=1).

For ~?, the next argument is taken as a format string, upon completion execution resumes in the current format string. The argument after is taken as the list of arguments used for the new format string unless the @ modifier is used, in which case the current argument list is used.

For ~(, the full form is ~(string~). The string is processed as a format string, however case conversion is performed on the output. If no modifiers are used, the string is converted to lowercase. If the colon modifier is used alone then all words are capitalized. If the @ modifier is used alone then the first character is converted to upper case and all remaining to lowercase. If both modifiers are used, all characters are converted to uppercase.

For ~{, the full form is ~n{string~}. Repeatedly processes string as a format string, or if the string is zero length, takes the next argument as the string. Iteration stops when processing has occured n times or no arguments remain. If the colon modifier is used on the ~} command, and n is non-zero then the string will be processed at least once. If no modifiers are used on ~{, then the arguments are taken from the next argument (like in ~?). If the colon modifier is used, the arguments are taken from the next argument which must be a list of sublists -- the sublists are used in turn to provide arguments on each iteration. In either case, the @ modifier will cause the current arguement list to be used rather than a single list argument.

For ~[, there are three formats. The first form is ~n[clause0~;clause1...~;clausen~]. Only one clause string is used, depending on the value of n. When n is absent, its value is taken from the argument list (as though 'v' had been used.) The last clause is treated as an "otherwise" clause if a colon modifier is used in its leading ~; command. The second form is ~:[clauset~;clausenil~]. The next argument is examined (but not consumed), and if nil clausenil is used, otherwise clauset is used. The third form is ~@[string~]. If then next argument is non-nil, then it is not used up and the format string is used, otherwise the argument is used up and the string is not used.

For ~*, the full form is ~n*. The count, n, defaults to 1 and is the number of arguments to skip. If the colon modifier is used, n is negated and skipping is backwards. The @ modifier causes n to be an absolute argument position (with default of 0), where the first argument is argument 0. Attempts to position before the first argument will position at the first argument, while attempts to position after the last argument signals an error.

For ~T, the full form is:

	~count,tabwidth@T
The cursor is moved to column "count" (default 1). If the cursor is initially at count or beyond, then the cursor is moved forward to the next position that is a multiple of "tabwidth" (default 1) columns beyond count. When the @ modifier is used, then positioning is relative. "count" spaces are printed, then additional spaces are printed to make the column number be a multiple of "tabwidth". Note that column calcuations will be incorrect if ASCII tab characters or ANSI cursor positioning sequences are used.

For ~\n, if the colon modifier is used, then the format directive is ignored (allowing embedded returns in the source for enhanced readability). If the at-sign modifier is used, then a carriage return is emitted, and following whitespace is ignored.


XLISP-PLUS - Version 2.1g - Tom Almy tom.almy@tek.com - 18 JUL 94
Generated with
WebMaker