1
0
Fork 0
cl-sites/HyperSpec-7-0/HyperSpec/Body/22_cfb.htm
2024-04-01 10:24:07 +02:00

44 lines
6 KiB
HTML

<!-- Common Lisp HyperSpec (TM), version 7.0 generated by Kent M. Pitman on Mon, 11-Apr-2005 2:31am EDT -->
<HTML>
<HEAD>
<TITLE>CLHS: Section 22.3.6.2</TITLE>
<LINK HREF="../Data/clhs.css" REL="stylesheet" TYPE="text/css" />
<META HTTP-EQUIV="Author" CONTENT="Kent M. Pitman">
<META HTTP-EQUIV="Organization" CONTENT="LispWorks Ltd.">
<LINK REL=TOP HREF="../Front/index.htm">
<LINK REL=COPYRIGHT HREF="../Front/Help.htm#Legal">
<LINK REL=DISCLAIMER HREF="../Front/Help.htm#Disclaimer">
<LINK REL=PREV HREF="22_cfa.htm">
<LINK REL=UP HREF="22_cf.htm">
<LINK REL=NEXT HREF="22_cfc.htm">
</HEAD>
<BODY>
<H1><A REV=MADE HREF="http://www.lispworks.com/"><IMG WIDTH=80 HEIGHT=65 ALT="[LISPWORKS]" SRC="../Graphics/LWSmall.gif" ALIGN=Bottom></A><A REL=TOP HREF="../Front/index.htm"><IMG WIDTH=237 HEIGHT=65 ALT="[Common Lisp HyperSpec (TM)]" SRC="../Graphics/CLHS_Sm.gif" ALIGN=Bottom></A> <A REL=PREV HREF="22_cfa.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="22_cf.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="22_cfc.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<H2>
22.3.6.2 Tilde Less-Than-Sign: Justification</H2> <P>
<TT>~</TT><I>mincol</I><TT>,</TT><I>colinc</I><TT>,</TT><I>minpad</I><TT>,</TT><I>padchar</I><TT>&lt;</TT><I>str</I><TT>~&gt;</TT> <P>
This justifies the text produced by processing <I>str</I> within a field at least <I>mincol</I> columns wide. <I>str</I> may be divided up into segments with <TT>~;</TT>, in which case the spacing is evenly divided between the text segments. <P>
With no modifiers, the leftmost text segment is left justified in the field, and the rightmost text segment is right justified. If there is only one text element, as a special case, it is right justified. The <TT>:</TT> modifier causes spacing to be introduced before the first text segment; the <TT>@</TT> modifier causes spacing to be added after the last. The <I>minpad</I> parameter (default <TT>0</TT>) is the minimum number of padding characters to be output between each segment. The padding character is supplied by <I>padchar</I>, which defaults to the space character. If the total width needed to satisfy these constraints is greater than <I>mincol</I>, then the width used is <I>mincol</I>+<I>k</I>*<I>colinc</I> for the smallest possible non-negative integer value <I>k</I>. <I>colinc</I> defaults to <TT>1</TT>, and <I>mincol</I> defaults to <TT>0</TT>. <P>
Note that <I>str</I> may include <A REL=DEFINITION HREF="f_format.htm#format"><B>format</B></A> directives. All the clauses in <I>str</I> are processed in order; it is the resulting pieces of text that are justified. <P>
The <TT>~^</TT> directive may be used to terminate processing of the clauses prematurely, in which case only the completely processed clauses are justified. <P>
If the first clause of a <TT>~&lt;</TT> is terminated with <TT>~:;</TT> instead of <TT>~;</TT>, then it is used in a special way. All of the clauses are processed (subject to <TT>~^</TT>, of course), but the first one is not used in performing the spacing and padding. When the padded result has been determined, then if it will fit on the current line of output, it is output, and the text for the first clause is discarded. If, however, the padded text will not fit on the current line, then the text segment for the first clause is output before the padded text. The first clause ought to contain a newline (such as a <TT>~%</TT> directive). The first clause is always processed, and so any arguments it refers to will be used; the decision is whether to use the resulting segment of text, not whether to process the first clause. If the <TT>~:;</TT> has a prefix parameter <I>n</I>, then the padded text must fit on the current line with <I>n</I> character positions to spare to avoid outputting the first clause's text. For example, the control string <P>
<PRE>
&quot;~%;; ~{ ~&lt;~%;; ~1:; ~S~&gt;~^ ,~} .~%&quot;
</PRE>
</TT> <P>
can be used to print a list of items separated by commas without breaking items over line boundaries, beginning each line with <TT>;; </TT>. The prefix parameter <TT>1</TT> in <TT>~1:;</TT> accounts for the width of the comma that will follow the justified item if it is not the last element in the list, or the period if it is. If <TT>~:;</TT> has a second prefix parameter, then it is used as the width of the line, thus overriding the natural line width of the output stream. To make the preceding example use a line width of 50, one would write <P>
<PRE>
&quot;~%;; ~{ ~&lt;~%;; ~1,50:; ~S~&gt;~^ ,~} .~%&quot;
</PRE>
</TT> If the second argument is not supplied, then <A REL=DEFINITION HREF="f_format.htm#format"><B>format</B></A> uses the line width of the <I>destination</I> output stream. If this cannot be determined (for example, when producing a <A REL=DEFINITION HREF="26_glo_s.htm#string"><I>string</I></A> result), then <A REL=DEFINITION HREF="f_format.htm#format"><B>format</B></A> uses <TT>72</TT> as the line length. <P>
See also <A REL=CHILD HREF="22_ceb.htm">Section 22.3.5.2 (Tilde Less-Than-Sign: Logical Block)</A>. <P>
<HR>
<A REL=NAVIGATOR HREF="../Front/StartPts.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Starting Points]" SRC="../Graphics/StartPts.gif" ALIGN=Bottom></A><A REL=TOC HREF="../Front/Contents.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Contents]" SRC="../Graphics/Contents.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Master.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Index]" SRC="../Graphics/Index.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Symbol.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Symbols]" SRC="../Graphics/Symbols.gif" ALIGN=Bottom></A><A REL=GLOSSARY HREF="../Body/26_a.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Glossary]" SRC="../Graphics/Glossary.gif" ALIGN=Bottom></A><A HREF="../Front/X3J13Iss.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Issues]" SRC="../Graphics/Issues.gif" ALIGN=Bottom></A><BR>
<A REL=COPYRIGHT HREF="../Front/Help.htm#Legal"><I>Copyright 1996-2005, LispWorks Ltd. All rights reserved.</I></A><P>
</BODY>
</HTML>