blob: 9304d0fce924cea8b2c73d65d15433e8884cd331 (
plain)
1
2
3
4
5
6
7
8
9
|
<h3 class="section">Introduction to Reading and Printing</h3> <p><em>Reading</em> a Lisp object means parsing a Lisp expression in textual form and producing a corresponding Lisp object. This is how Lisp programs get into Lisp from files of Lisp code. We call the text the <em>read syntax</em> of the object. For example, the text ‘<samp>(a . 5)</samp>’ is the read syntax for a cons cell whose <small>CAR</small> is <code>a</code> and whose <small>CDR</small> is the number 5. </p> <p><em>Printing</em> a Lisp object means producing text that represents that object—converting the object to its <em>printed representation</em> (see <a href="printed-representation">Printed Representation</a>). Printing the cons cell described above produces the text ‘<samp>(a . 5)</samp>’. </p> <p>Reading and printing are more or less inverse operations: printing the object that results from reading a given piece of text often produces the same text, and reading the text that results from printing an object usually produces a similar-looking object. For example, printing the symbol <code>foo</code> produces the text ‘<samp>foo</samp>’, and reading that text returns the symbol <code>foo</code>. Printing a list whose elements are <code>a</code> and <code>b</code> produces the text ‘<samp>(a b)</samp>’, and reading that text produces a list (but not the same list) with elements <code>a</code> and <code>b</code>. </p> <p>However, these two operations are not precisely inverse to each other. There are three kinds of exceptions: </p> <ul> <li> Printing can produce text that cannot be read. For example, buffers, windows, frames, subprocesses and markers print as text that starts with ‘<samp>#</samp>’; if you try to read this text, you get an error. There is no way to read those data types. </li>
<li> One object can have multiple textual representations. For example, ‘<samp>1</samp>’ and ‘<samp>01</samp>’ represent the same integer, and ‘<samp>(a b)</samp>’ and ‘<samp>(a . (b))</samp>’ represent the same list. Reading will accept any of the alternatives, but printing must choose one of them. </li>
<li> Comments can appear at certain points in the middle of an object’s read sequence without affecting the result of reading it. </li>
</ul><div class="_attribution">
<p class="_attribution-p">
Copyright © 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br>
<a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Streams-Intro.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Streams-Intro.html</a>
</p>
</div>
|