summaryrefslogtreecommitdiff
path: root/docsrc/xlisp/xlisp-doc/reference/format.htm
blob: 8a8bdca26519a59962808175ebc17c14e16aba67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<html><head><title>XLISP format</title>

<link rel="stylesheet" type="text/css" href="reference.css">

</head>

<body>

<a href="../start.htm">Nyquist / XLISP 2.0</a>&nbsp; -&nbsp;
<a href="../manual/contents.htm">Contents</a> |
<a href="../tutorials/tutorials.htm">Tutorials</a> |
<a href="../examples/examples.htm">Examples</a> |
<a href="reference-index.htm">Reference</a>

<hr>

<h1>format</h1>

<hr>

<p><table cellpadding="0" cellspacing="0" style="margin-left:10px"><tbody>
<tr valign="top">
  <td><nobr>Type:</nobr></td>
  <td><nobr>&nbsp;&nbsp;-&nbsp;&nbsp;</nobr></td>
  <td width="100%"><nobr>function (subr)</nobr></td>
</tr>
<tr valign="top">
  <td><nobr>Source:</nobr></td>
  <td><nobr>&nbsp;&nbsp;-&nbsp;&nbsp;</nobr></td>
  <td width="100%"><nobr>xlfio.c</nobr></td>
</tr>
</tbody></table></p>

<h2>Syntax</h2>

<dl>
<dt>(format destination format [expr1 ... ])</dt>
<dd><i>destination</i> - a required destination [see below]<br>
<i>format</i> - a format string<br>
<i>exprN</i> - an expression<br>
returns - output string if stream is
<nobr><a href="nil.htm">NIL</a> ,</nobr>
<a href="nil.htm">NIL</a> otherwise</dd>
</dl>

<p>The 'destination' must be a file pointer, a stream,
<a href="nil.htm">NIL</a> [to create a string] or
<a href="t.htm">&nbsp;T&nbsp;</a> [to print to
<a href="global-standard-output.htm">*standard-output*</a>].</p>

<h2>Description</h2>

<p>The 'format' function prints the specified expressions [if any] to the
specified 'destination' using the 'format' string to control the print
format. If the 'destination' is
<nobr><a href="nil.htm">NIL</a> ,</nobr> a string is created and
returned with the contents of the 'format'. If the 'destination' is
<nobr><a href="t.htm">&nbsp;T&nbsp;</a> ,</nobr> the printing
occurs to <a href="global-standard-output.htm">*standard-output*</a>. The 'format'
function returns <nobr><a href="nil.htm">NIL</a> ,</nobr> if
the 'destination' was non-<a href="nil.htm">NIL</a>. The 'format'
string is a string [surrounded by double-quote characters]. This string
contains ASCII text to be printed along with formatting directives
[identified by a preceeding tilde '~' character]. The character following
the tilde character is not case sensitive ['~a' and '~A' will function
equivalently].</p>

<h2>Examples</h2>

<pre class="example">
(format T "Now is the time for")         <font color="#008844">; prints  Now is the time for</font>
(format T "all ~A ~S to" 'good 'men)     <font color="#008844">; prints  all GOOD MEN to</font>
(format T "come to the")                 <font color="#008844">; prints  come to the</font>
(format T "~A of their ~S"               <font color="#008844">; prints  aid of their "party"</font>
          "aid" "party")
(format *standard-ouput* "Hello there")  <font color="#008844">; prints  Hello there</font>
(format nil "ho ho ~S" 'ho)              <font color="#008844">; returns "ho ho HO"</font>
(format T "this is ~%a break")           <font color="#008844">; prints  this is</font>
                                         <font color="#008844">;         a break</font>
(format T "this is a long ~
           string")                      <font color="#008844">; prints  this is a long string</font>
</pre>

<p><b>Supported format directives:</b> The 'format' string in XLISP supports
the following format directives:</p>

<p><table cellpadding="0" cellspacing="0" style="margin-left:10px"><tbody>
<tr valign="top">
  <td><nobr><code>~A</code></nobr></td>
  <td><nobr>&nbsp;&nbsp;-&nbsp;&nbsp;</nobr></td>
  <td width="100%">ASCII, prints the 'expr'. If it is a string print it
    without quotes. This is like the <a href="princ.htm">princ</a>
    function.</td>
</tr>
<tr>
  <td><nobr><font size="-2">&nbsp;</font></nobr></td>
</tr>
<tr valign="top">
  <td><nobr><code>~S</code></nobr></td>
  <td><nobr>&nbsp;&nbsp;-&nbsp;&nbsp;</nobr></td>
  <td width="100%">s-expr, prints the 'expr'. If it is a string print it
    with quotes. This is like the <a href="prin1.htm">prin1</a>
    function.</td>
</tr>
<tr>
  <td><nobr><font size="-2">&nbsp;</font></nobr></td>
</tr>
<tr valign="top">
  <td><nobr><code>~%</code></nobr></td>
  <td><nobr>&nbsp;&nbsp;-&nbsp;&nbsp;</nobr></td>
  <td width="100%">prints a 'newline' control character.</td>
</tr>
<tr>
  <td><nobr><font size="-2">&nbsp;</font></nobr></td>
</tr>
<tr valign="top">
  <td><nobr><code>~~</code></nobr></td>
  <td><nobr>&nbsp;&nbsp;-&nbsp;&nbsp;</nobr></td>
  <td width="100%">prints a single tilde '~' character.</td>
</tr>
<tr>
  <td><nobr><font size="-2">&nbsp;</font></nobr></td>
</tr>
<tr valign="top">
  <td><nobr><code>~&lt;newline&gt;</code></nobr></td>
  <td><nobr>&nbsp;&nbsp;-&nbsp;&nbsp;</nobr></td>
  <td width="100%">continue the 'format' string on the next line. This
    signals a line break in the format. The 'format' function will ignore
    all white-space [blanks, tabs, newlines]. This is useful when the
    'format' string is longer than a program line. Note that the 'newline'
    character must immediately follow the tilde character.</td>
</tr>
</tbody></table></p>

<p><b>Common Lisp:</b> The 'format' function in Common Lisp is quite
impressive. It includes 26 different formatting directives. XLISP, as shown
above, does not include most of these. The more difficult ones that you
might encounter are the decimal, octal, hexidecimal, fixed-format
floating-point and exponential floating-point. It is possible to print in
octal and hexadecimal notation by setting
<a href="global-integer-format.htm">*integer-format*</a>. It is possible to print
in fixed format and exponential by setting
<a href="global-float-format.htm">*float-format*</a>. However, neither of these
system variables are supported in Common Lisp and neither gives control over
field size.</p>

<p>See the
<a href="../manual/xlisp-man-028.htm#format">format</a>
function in the <nobr>XLISP 2.0</nobr> manual.</p>

<p><nobr>&nbsp;&nbsp;<a href="#top">Back to Top</nobr></a></p>

<hr>

<a href="../start.htm">Nyquist / XLISP 2.0</a>&nbsp; -&nbsp;
<a href="../manual/contents.htm">Contents</a> |
<a href="../tutorials/tutorials.htm">Tutorials</a> |
<a href="../examples/examples.htm">Examples</a> |
<a href="reference-index.htm">Reference</a>

</body></html>