This section describes the Lisp functions for printing Lisp objects.
Some of the SXEmacs printing functions add quoting characters to the output when necessary so that it can be read properly. The quoting characters used are ‘"’ and ‘\’; they distinguish strings from symbols, and prevent punctuation characters in strings and symbols from being taken as delimiters when reading. See Printed Representation, for full details. You specify quoting or no quoting by the choice of printing function.
If the text is to be read back into Lisp, then it is best to print with quoting characters to avoid ambiguity. Likewise, if the purpose is to describe a Lisp object clearly for a Lisp programmer. However, if the purpose of the output is to look nice for humans, then it is better to print without quoting.
Printing a self-referent Lisp object requires an infinite amount of text. In certain cases, trying to produce this text leads to a stack overflow. SXEmacs detects such recursion and prints ‘#level’ instead of recursively printing an object already being printed. For example, here ‘#0’ indicates a recursive reference to the object at level 0 of the current print operation:
(setq foo (list nil)) ⇒ (nil) (setcar foo foo) ⇒ (#0)
In the functions below, stream stands for an output stream.
(See the previous section for a description of output streams.) If
nil or omitted, it defaults to the value of
(progn (print 'The\ cat\ in) (print "the hat") (print " came back")) -| -| The\ cat\ in -| -| "the hat" -| -| " came back" -| ⇒ " came back"
This function outputs the printed representation of object to
stream. It does not print newlines to separate output as
(progn (prin1 'The\ cat\ in) (prin1 "the hat") (prin1 " came back")) -| The\ cat\ in"the hat"" came back" ⇒ " came back"
This function outputs the printed representation of object to stream. It returns object.
This function is intended to produce output that is readable by people,
read, so it doesn’t insert quoting characters and doesn’t
put double-quotes around the contents of strings. It does not add any
spacing between calls.
(progn (princ 'The\ cat) (princ " in the \"hat\"")) -| The cat in the "hat" ⇒ " in the \"hat\""
This function outputs a newline to stream. The name stands for “terminate print”.
This function outputs character to stream. It returns character.
This function returns a string containing the text that
would have printed for the same argument.
(prin1-to-string 'foo) ⇒ "foo"
(prin1-to-string (mark-marker)) ⇒ "#<marker at 2773 in strings.texi>"
If noescape is non-
nil, that inhibits use of quoting
characters in the output. (This argument is supported in Emacs versions
19 and later.)
(prin1-to-string "foo") ⇒ "\"foo\""
(prin1-to-string "foo" t) ⇒ "foo"
format, in String Conversion, for other ways to obtain
the printed representation of a Lisp object as a string.