annotate man/lispref/streams.texi @ 5889:bd644055ef44

Correct a bug in #'check-type, non-setf'able PLACEs lisp/ChangeLog addition: 2015-04-11 Aidan Kehoe <kehoea@parhasard.net> * cl-macs.el: * cl-macs.el (check-type): Correct the sense of the type test here when PLACE is not setf'able, something which gave confusing errors with literal fixnums or, e.g., (+ 30 40). tests/ChangeLog addition: 2015-04-11 Aidan Kehoe <kehoea@parhasard.net> * automated/lisp-tests.el: Check for a bug just fixed in cl-macs.el.
author Aidan Kehoe <kehoea@parhasard.net>
date Sat, 11 Apr 2015 18:06:17 +0100
parents 9fae6227ede5
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 @c -*-texinfo-*-
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 @c This is part of the XEmacs Lisp Reference Manual.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 @c See the file lispref.texi for copying conditions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 @setfilename ../../info/streams.info
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 @node Read and Print, Minibuffers, Debugging, Top
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 @chapter Reading and Printing Lisp Objects
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 @dfn{Printing} and @dfn{reading} are the operations of converting Lisp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 objects to textual form and vice versa. They use the printed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 representations and read syntax described in @ref{Lisp Data Types}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 This chapter describes the Lisp functions for reading and printing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 It also describes @dfn{streams}, which specify where to get the text (if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 reading) or where to put it (if printing).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 @menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 * Streams Intro:: Overview of streams, reading and printing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 * Input Streams:: Various data types that can be used as input streams.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 * Input Functions:: Functions to read Lisp objects from text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 * Output Streams:: Various data types that can be used as output streams.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 * Output Functions:: Functions to print Lisp objects as text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 * Output Variables:: Variables that control what the printing functions do.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 @end menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 444
diff changeset
26 @node Streams Intro, Input Streams, Read and Print, Read and Print
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 @section Introduction to Reading and Printing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 @cindex Lisp reader
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 @cindex printing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 @cindex reading
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 @dfn{Reading} a Lisp object means parsing a Lisp expression in textual
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 form and producing a corresponding Lisp object. This is how Lisp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 programs get into Lisp from files of Lisp code. We call the text the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 @dfn{read syntax} of the object. For example, the text @samp{(a .@: 5)}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 is the read syntax for a cons cell whose @sc{car} is @code{a} and whose
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 @sc{cdr} is the number 5.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 @dfn{Printing} a Lisp object means producing text that represents that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 object---converting the object to its printed representation. Printing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 the cons cell described above produces the text @samp{(a .@: 5)}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 Reading and printing are more or less inverse operations: printing the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 object that results from reading a given piece of text often produces
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 the same text, and reading the text that results from printing an object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 usually produces a similar-looking object. For example, printing the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 symbol @code{foo} produces the text @samp{foo}, and reading that text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 returns the symbol @code{foo}. Printing a list whose elements are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 @code{a} and @code{b} produces the text @samp{(a b)}, and reading that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 text produces a list (but not the same list) with elements @code{a}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 and @code{b}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 However, these two operations are not precisely inverses. There are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 three kinds of exceptions:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 @itemize @bullet
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 Printing can produce text that cannot be read. For example, buffers,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 windows, frames, subprocesses and markers print into text that starts
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 with @samp{#}; if you try to read this text, you get an error. There is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 no way to read those data types.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 One object can have multiple textual representations. For example,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 @samp{1} and @samp{01} represent the same integer, and @samp{(a b)} and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 @samp{(a .@: (b))} represent the same list. Reading will accept any of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 the alternatives, but printing must choose one of them.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 Comments can appear at certain points in the middle of an object's
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 read sequence without affecting the result of reading it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 @end itemize
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 444
diff changeset
74 @node Input Streams, Input Functions, Streams Intro, Read and Print
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 @section Input Streams
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 @cindex stream (for reading)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 @cindex input stream
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 Most of the Lisp functions for reading text take an @dfn{input stream}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 as an argument. The input stream specifies where or how to get the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 characters of the text to be read. Here are the possible types of input
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 stream:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 @table @asis
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 @item @var{buffer}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 @cindex buffer input stream
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 The input characters are read from @var{buffer}, starting with the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 character directly after point. Point advances as characters are read.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 @item @var{marker}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 @cindex marker input stream
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 The input characters are read from the buffer that @var{marker} is in,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 starting with the character directly after the marker. The marker
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 position advances as characters are read. The value of point in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 buffer has no effect when the stream is a marker.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 @item @var{string}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 @cindex string input stream
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 The input characters are taken from @var{string}, starting at the first
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 character in the string and using as many characters as required.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 @item @var{function}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 @cindex function input stream
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 The input characters are generated by @var{function}, one character per
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 call. Normally @var{function} is called with no arguments, and should
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 return a character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 @cindex unreading
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 Occasionally @var{function} is called with one argument (always a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 character). When that happens, @var{function} should save the argument
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 and arrange to return it on the next call. This is called
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 @dfn{unreading} the character; it happens when the Lisp reader reads one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 character too many and wants to ``put it back where it came from''.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 @item @code{t}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 @cindex @code{t} input stream
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 @code{t} used as a stream means that the input is read from the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 minibuffer. In fact, the minibuffer is invoked once and the text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 given by the user is made into a string that is then used as the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 input stream.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 @item @code{nil}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 @cindex @code{nil} input stream
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 @code{nil} supplied as an input stream means to use the value of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 @code{standard-input} instead; that value is the @dfn{default input
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 stream}, and must be a non-@code{nil} input stream.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 @item @var{symbol}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 A symbol as input stream is equivalent to the symbol's function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 definition (if any).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 @end table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 Here is an example of reading from a stream that is a buffer, showing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 where point is located before and after:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 This@point{} is the contents of foo.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 (read (get-buffer "foo"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 @result{} is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 (read (get-buffer "foo"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 @result{} the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 This is the@point{} contents of foo.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 Note that the first read skips a space. Reading skips any amount of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 whitespace preceding the significant text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 In Emacs 18, reading a symbol discarded the delimiter terminating the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 symbol. Thus, point would end up at the beginning of @samp{contents}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 rather than after @samp{the}. The Emacs 19 behavior is superior because
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 it correctly handles input such as @samp{bar(foo)}, where the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 open-parenthesis that ends one object is needed as the beginning of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 another object.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 Here is an example of reading from a stream that is a marker,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 initially positioned at the beginning of the buffer shown. The value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 read is the symbol @code{This}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 This is the contents of foo.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 (setq m (set-marker (make-marker) 1 (get-buffer "foo")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 @result{} #<marker at 1 in foo>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 (read m)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 @result{} This
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 m
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 @result{} #<marker at 5 in foo> ;; @r{Before the first space.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 Here we read from the contents of a string:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 (read "(When in) the course")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 @result{} (When in)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 The following example reads from the minibuffer. The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 prompt is: @w{@samp{Lisp expression: }}. (That is always the prompt
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 used when you read from the stream @code{t}.) The user's input is shown
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 following the prompt.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 (read t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 @result{} 23
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 ---------- Buffer: Minibuffer ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 Lisp expression: @kbd{23 @key{RET}}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 ---------- Buffer: Minibuffer ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 Finally, here is an example of a stream that is a function, named
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 @code{useless-stream}. Before we use the stream, we initialize the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 variable @code{useless-list} to a list of characters. Then each call to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 the function @code{useless-stream} obtains the next character in the list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 or unreads a character by adding it to the front of the list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 (setq useless-list (append "XY()" nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 @result{} (88 89 40 41)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 (defun useless-stream (&optional unread)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 (if unread
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 (setq useless-list (cons unread useless-list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 (prog1 (car useless-list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 (setq useless-list (cdr useless-list)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 @result{} useless-stream
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 Now we read using the stream thus constructed:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 (read 'useless-stream)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 @result{} XY
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 useless-list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 @result{} (40 41)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 Note that the open and close parentheses remains in the list. The Lisp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 reader encountered the open parenthesis, decided that it ended the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 input, and unread it. Another attempt to read from the stream at this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 point would read @samp{()} and return @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 @ignore @c Not in XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 @defun get-file-char
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 This function is used internally as an input stream to read from the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 input file opened by the function @code{load}. Don't use this function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 yourself.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 @end ignore
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 444
diff changeset
271 @node Input Functions, Output Streams, Input Streams, Read and Print
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 @section Input Functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 This section describes the Lisp functions and variables that pertain
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 to reading.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 In the functions below, @var{stream} stands for an input stream (see
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 the previous section). If @var{stream} is @code{nil} or omitted, it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 defaults to the value of @code{standard-input}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 @kindex end-of-file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 An @code{end-of-file} error is signaled if reading encounters an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 unterminated list, vector, or string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 @defun read &optional stream
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 This function reads one textual Lisp expression from @var{stream},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 returning it as a Lisp object. This is the basic Lisp input function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 @defun read-from-string string &optional start end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 @cindex string to object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 This function reads the first textual Lisp expression from the text in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 @var{string}. It returns a cons cell whose @sc{car} is that expression,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 and whose @sc{cdr} is an integer giving the position of the next
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 remaining character in the string (i.e., the first one not read).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 If @var{start} is supplied, then reading begins at index @var{start} in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 the string (where the first character is at index 0). If @var{end} is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 also supplied, then reading stops just before that index, as if the rest
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 of the string were not there.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 For example:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 (read-from-string "(setq x 55) (setq y 5)")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 @result{} ((setq x 55) . 11)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 (read-from-string "\"A short string\"")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 @result{} ("A short string" . 16)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 ;; @r{Read starting at the first character.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 (read-from-string "(list 112)" 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 @result{} ((list 112) . 10)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 ;; @r{Read starting at the second character.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 (read-from-string "(list 112)" 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 @result{} (list . 5)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 ;; @r{Read starting at the seventh character,}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 ;; @r{and stopping at the ninth.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 (read-from-string "(list 112)" 6 8)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 @result{} (11 . 8)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 @defvar standard-input
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 This variable holds the default input stream---the stream that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 @code{read} uses when the @var{stream} argument is @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 444
diff changeset
338 @node Output Streams, Output Functions, Input Functions, Read and Print
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 @section Output Streams
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 @cindex stream (for printing)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 @cindex output stream
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 An output stream specifies what to do with the characters produced
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 by printing. Most print functions accept an output stream as an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 optional argument. Here are the possible types of output stream:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 @table @asis
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 @item @var{buffer}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 @cindex buffer output stream
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 The output characters are inserted into @var{buffer} at point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 Point advances as characters are inserted.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 @item @var{marker}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 @cindex marker output stream
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 The output characters are inserted into the buffer that @var{marker}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 points into, at the marker position. The marker position advances as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 characters are inserted. The value of point in the buffer has no effect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 on printing when the stream is a marker.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 @item @var{function}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 @cindex function output stream
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 The output characters are passed to @var{function}, which is responsible
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 for storing them away. It is called with a single character as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 argument, as many times as there are characters to be output, and is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 free to do anything at all with the characters it receives.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 @item @code{t}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 @cindex @code{t} output stream
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 The output characters are displayed in the echo area.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 @item @code{nil}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 @cindex @code{nil} output stream
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 @code{nil} specified as an output stream means to the value of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 @code{standard-output} instead; that value is the @dfn{default output
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 stream}, and must be a non-@code{nil} output stream.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 @item @var{symbol}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 A symbol as output stream is equivalent to the symbol's function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 definition (if any).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 @end table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 Many of the valid output streams are also valid as input streams. The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 difference between input and output streams is therefore mostly one of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 how you use a Lisp object, not a distinction of types of object.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 Here is an example of a buffer used as an output stream. Point is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 initially located as shown immediately before the @samp{h} in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 @samp{the}. At the end, point is located directly before that same
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 @samp{h}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 @cindex print example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 This is t@point{}he contents of foo.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 (print "This is the output" (get-buffer "foo"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 @result{} "This is the output"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 This is t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 "This is the output"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 @point{}he contents of foo.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 Now we show a use of a marker as an output stream. Initially, the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 marker is in buffer @code{foo}, between the @samp{t} and the @samp{h} in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 the word @samp{the}. At the end, the marker has advanced over the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 inserted text so that it remains positioned before the same @samp{h}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 Note that the location of point, shown in the usual fashion, has no
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 effect.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 "This is the @point{}output"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 m
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 @result{} #<marker at 11 in foo>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 (print "More output for foo." m)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 @result{} "More output for foo."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 "This is t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 "More output for foo."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 he @point{}output"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 m
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 @result{} #<marker at 35 in foo>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 The following example shows output to the echo area:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 (print "Echo Area output" t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 @result{} "Echo Area output"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 ---------- Echo Area ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 "Echo Area output"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 ---------- Echo Area ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 Finally, we show the use of a function as an output stream. The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 function @code{eat-output} takes each character that it is given and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 conses it onto the front of the list @code{last-output} (@pxref{Building
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 Lists}). At the end, the list contains all the characters output, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 in reverse order.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 (setq last-output nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 (defun eat-output (c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 (setq last-output (cons c last-output)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 @result{} eat-output
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 (print "This is the output" 'eat-output)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 @result{} "This is the output"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 last-output
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 @result{} (?\n ?\" ?t ?u ?p ?t ?u ?o ?\ ?e ?h ?t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 ?\ ?s ?i ?\ ?s ?i ?h ?T ?\" ?\n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 Now we can put the output in the proper order by reversing the list:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 (concat (nreverse last-output))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 @result{} "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 \"This is the output\"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 Calling @code{concat} converts the list to a string so you can see its
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 contents more clearly.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 444
diff changeset
507 @node Output Functions, Output Variables, Output Streams, Read and Print
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 @section Output Functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 This section describes the Lisp functions for printing Lisp objects.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 @cindex @samp{"} in printing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 @cindex @samp{\} in printing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 @cindex quoting characters in printing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 @cindex escape characters in printing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 Some of the XEmacs printing functions add quoting characters to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 output when necessary so that it can be read properly. The quoting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 characters used are @samp{"} and @samp{\}; they distinguish strings from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 symbols, and prevent punctuation characters in strings and symbols from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 being taken as delimiters when reading. @xref{Printed Representation},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 for full details. You specify quoting or no quoting by the choice of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 printing function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 If the text is to be read back into Lisp, then it is best to print
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 with quoting characters to avoid ambiguity. Likewise, if the purpose is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 to describe a Lisp object clearly for a Lisp programmer. However, if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 the purpose of the output is to look nice for humans, then it is better
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 to print without quoting.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 Printing a self-referent Lisp object requires an infinite amount of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 text. In certain cases, trying to produce this text leads to a stack
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 overflow. XEmacs detects such recursion and prints @samp{#@var{level}}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 instead of recursively printing an object already being printed. For
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 example, here @samp{#0} indicates a recursive reference to the object at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 level 0 of the current print operation:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 (setq foo (list nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 @result{} (nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 (setcar foo foo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 @result{} (#0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 In the functions below, @var{stream} stands for an output stream.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 (See the previous section for a description of output streams.) If
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 @var{stream} is @code{nil} or omitted, it defaults to the value of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 @code{standard-output}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 @defun print object &optional stream
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 @cindex Lisp printer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 The @code{print} function is a convenient way of printing. It outputs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 the printed representation of @var{object} to @var{stream}, printing in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 addition one newline before @var{object} and another after it. Quoting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 characters are used. @code{print} returns @var{object}. For example:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 (progn (print 'The\ cat\ in)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 (print "the hat")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 (print " came back"))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
561 @print{}
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 @print{} The\ cat\ in
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
563 @print{}
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 @print{} "the hat"
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
565 @print{}
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 @print{} " came back"
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
567 @print{}
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 @result{} " came back"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 @defun prin1 object &optional stream
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 This function outputs the printed representation of @var{object} to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 @var{stream}. It does not print newlines to separate output as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 @code{print} does, but it does use quoting characters just like
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 @code{print}. It returns @var{object}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 @group
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
581 (progn (prin1 'The\ cat\ in)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
582 (prin1 "the hat")
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 (prin1 " came back"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 @print{} The\ cat\ in"the hat"" came back"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 @result{} " came back"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 @defun princ object &optional stream
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 This function outputs the printed representation of @var{object} to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 @var{stream}. It returns @var{object}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 This function is intended to produce output that is readable by people,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 not by @code{read}, so it doesn't insert quoting characters and doesn't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 put double-quotes around the contents of strings. It does not add any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 spacing between calls.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 (princ 'The\ cat)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 (princ " in the \"hat\""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 @print{} The cat in the "hat"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 @result{} " in the \"hat\""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 @defun terpri &optional stream
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 @cindex newline in print
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 This function outputs a newline to @var{stream}. The name stands
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 for ``terminate print''.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 @defun write-char character &optional stream
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 This function outputs @var{character} to @var{stream}. It returns
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 @var{character}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 @defun prin1-to-string object &optional noescape
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 @cindex object to string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 This function returns a string containing the text that @code{prin1}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 would have printed for the same argument.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 (prin1-to-string 'foo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 @result{} "foo"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 (prin1-to-string (mark-marker))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 @result{} "#<marker at 2773 in strings.texi>"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 If @var{noescape} is non-@code{nil}, that inhibits use of quoting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 characters in the output. (This argument is supported in Emacs versions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 19 and later.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 (prin1-to-string "foo")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 @result{} "\"foo\""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 (prin1-to-string "foo" t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 @result{} "foo"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 See @code{format}, in @ref{String Conversion}, for other ways to obtain
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 the printed representation of a Lisp object as a string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 444
diff changeset
656 @node Output Variables, , Output Functions, Read and Print
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 @section Variables Affecting Output
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 @defvar standard-output
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 The value of this variable is the default output stream---the stream
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 that print functions use when the @var{stream} argument is @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 @defvar print-escape-newlines
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 @cindex @samp{\n} in print
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 @cindex escape characters
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 If this variable is non-@code{nil}, then newline characters in strings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 are printed as @samp{\n} and formfeeds are printed as @samp{\f}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 Normally these characters are printed as actual newlines and formfeeds.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671 This variable affects the print functions @code{prin1} and @code{print},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 as well as everything that uses them. It does not affect @code{princ}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 Here is an example using @code{prin1}:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 (prin1 "a\nb")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 @print{} "a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 @print{} b"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 @result{} "a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 b"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 (let ((print-escape-newlines t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 (prin1 "a\nb"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 @print{} "a\nb"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 @result{} "a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689 b"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 In the second expression, the local binding of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 @code{print-escape-newlines} is in effect during the call to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 @code{prin1}, but not during the printing of the result.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 @defvar print-readably
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 @cindex printing readably
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 If non-@code{nil}, then all objects will be printed in a readable form.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 If an object has no readable representation, then an error is signalled.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703 When @code{print-readably} is true, compiled-function objects will be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 written in @samp{#[...]} form instead of in @samp{#<compiled-function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 [...]>} form, and two-element lists of the form @samp{(quote object)}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 will be written as the equivalent @samp{'object}. Do not @emph{set}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707 this variable; bind it instead.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 @defvar print-length
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 @cindex printing limits
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 The value of this variable is the maximum number of elements of a list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 that will be printed. If a list being printed has more than this many
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 elements, it is abbreviated with an ellipsis.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716 If the value is @code{nil} (the default), then there is no limit.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 (setq print-length 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 @result{} 2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 (print '(1 2 3 4 5))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 @print{} (1 2 ...)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 @result{} (1 2 ...)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 @defvar print-level
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 The value of this variable is the maximum depth of nesting of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 parentheses and brackets when printed. Any list or vector at a depth
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 exceeding this limit is abbreviated with an ellipsis. A value of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 @code{nil} (which is the default) means no limit.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 This variable exists in version 19 and later versions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 @defvar print-string-length
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 @cindex string length, maximum when printing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 The value of this variable is the maximum number of characters of a string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 that will be printed. If a string being printed has more than this many
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 characters, it is abbreviated with an ellipsis.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 @defvar print-gensym
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 @cindex printing uninterned symbols
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 @cindex uninterned symbols, printing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 If non-@code{nil}, then uninterned symbols will be printed specially.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 Uninterned symbols are those which are not present in @code{obarray},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 that is, those which were made with @code{make-symbol} or by calling
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 @code{intern} with a second argument.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 When @code{print-gensym} is true, such symbols will be preceded by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 @samp{#:}, which causes the reader to create a new symbol instead of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 interning and returning an existing one. Beware: The @samp{#:} syntax
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 creates a new symbol each time it is seen, so if you print an object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 which contains two pointers to the same uninterned symbol, @code{read}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 will not duplicate that structure.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 Also, since XEmacs has no real notion of packages, there is no way for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 the printer to distinguish between symbols interned in no obarray, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 symbols interned in an alternate obarray.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 @defvar float-output-format
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 @cindex printing floating-point numbers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 @cindex floating-point numbers, printing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 This variable holds the format descriptor string that Lisp uses to print
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 floats. This is a @samp{%}-spec like those accepted by @code{printf} in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 C, but with some restrictions. It must start with the two characters
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 @samp{%.}. After that comes an integer precision specification, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 then a letter which controls the format. The letters allowed are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 @samp{e}, @samp{f} and @samp{g}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 @itemize @bullet
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 Use @samp{e} for exponential notation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 @samp{@var{dig}.@var{digits}e@var{expt}}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 Use @samp{f} for decimal point notation @samp{DIGITS.DIGITS}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784 Use @samp{g} to choose the shorter of those two formats for the number
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 at hand.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 @end itemize
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 The precision in any of these cases is the number of digits following
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789 the decimal point. With @samp{f}, a precision of 0 means to omit the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 decimal point. 0 is not allowed with @samp{f} or @samp{g}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
792 A value of @code{nil} means to use @samp{%.16g}.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 Regardless of the value of @code{float-output-format}, a floating point
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 number will never be printed in such a way that it is ambiguous with an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 integer; that is, a floating-point number will always be printed with a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 decimal point and/or an exponent, even if the digits following the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 decimal point are all zero. This is to preserve read-equivalence.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 @end defvar