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

96 lines
8.8 KiB
HTML

<!-- Common Lisp HyperSpec (TM), version 7.0 generated by Kent M. Pitman on Mon, 11-Apr-2005 2:31am EDT -->
<HTML>
<HEAD>
<TITLE>CLHS: Function WRITE-TO-STRING, PRIN1-TO-STRING...</TITLE>
<LINK HREF="../Data/clhs.css" REL="stylesheet" TYPE="text/css" />
<META HTTP-EQUIV="Author" CONTENT="Kent M. Pitman">
<META HTTP-EQUIV="Organization" CONTENT="LispWorks Ltd.">
<LINK REL=TOP HREF="../Front/index.htm">
<LINK REL=COPYRIGHT HREF="../Front/Help.htm#Legal">
<LINK REL=DISCLAIMER HREF="../Front/Help.htm#Disclaimer">
<LINK REL=PREV HREF="f_wr_pr.htm">
<LINK REL=UP HREF="c_printe.htm">
<LINK REL=NEXT HREF="v_pr_ar.htm">
</HEAD>
<BODY>
<H1><A REV=MADE HREF="http://www.lispworks.com/"><IMG WIDTH=80 HEIGHT=65 ALT="[LISPWORKS]" SRC="../Graphics/LWSmall.gif" ALIGN=Bottom></A><A REL=TOP HREF="../Front/index.htm"><IMG WIDTH=237 HEIGHT=65 ALT="[Common Lisp HyperSpec (TM)]" SRC="../Graphics/CLHS_Sm.gif" ALIGN=Bottom></A> <A REL=PREV HREF="f_wr_pr.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="c_printe.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="v_pr_ar.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<A NAME="write-to-string"><A NAME="prin1-to-string"><A NAME="princ-to-string"><I>Function</I> <B>WRITE-TO-STRING, PRIN1-TO-STRING, PRINC-TO-STRING</B></A></A></A> <P>
<P><B>Syntax:</B><P>
<P>
<B>write-to-string</B> <I>object <TT>&amp;key</TT> array base case circle escape gensym length level lines miser-width pprint-dispatch pretty radix readably right-margin </I><P> =&gt; <I>string</I><P>
<P>
<B>prin1-to-string</B> <I>object</I> =&gt; <I>string</I><P>
<P>
<B>princ-to-string</B> <I>object</I> =&gt; <I>string</I><P>
<P>
<P><B>Arguments and Values:</B><P>
<P>
<I>object</I>---an <A REL=DEFINITION HREF="26_glo_o.htm#object"><I>object</I></A>. <P>
<I>array</I>---a <A REL=DEFINITION HREF="26_glo_g.htm#generalized_boolean"><I>generalized boolean</I></A>. <P>
<I>base</I>---a <A REL=DEFINITION HREF="26_glo_r.htm#radix"><I>radix</I></A>. <P>
<I>case</I>---a <A REL=DEFINITION HREF="26_glo_s.htm#symbol"><I>symbol</I></A> of <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> <TT>(member :upcase :downcase :capitalize)</TT>. <P>
<I>circle</I>---a <A REL=DEFINITION HREF="26_glo_g.htm#generalized_boolean"><I>generalized boolean</I></A>. <P>
<I>escape</I>---a <A REL=DEFINITION HREF="26_glo_g.htm#generalized_boolean"><I>generalized boolean</I></A>. <P>
<I>gensym</I>---a <A REL=DEFINITION HREF="26_glo_g.htm#generalized_boolean"><I>generalized boolean</I></A>. <P>
<I>length</I>---a non-negative <A REL=DEFINITION HREF="26_glo_i.htm#integer"><I>integer</I></A>, or <A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A>. <P>
<I>level</I>---a non-negative <A REL=DEFINITION HREF="26_glo_i.htm#integer"><I>integer</I></A>, or <A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A>. <P>
<I>lines</I>---a non-negative <A REL=DEFINITION HREF="26_glo_i.htm#integer"><I>integer</I></A>, or <A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A>. <P>
<I>miser-width</I>---a non-negative <A REL=DEFINITION HREF="26_glo_i.htm#integer"><I>integer</I></A>, or <A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A>. <P>
<I>pprint-dispatch</I>---a <A REL=DEFINITION HREF="26_glo_p.htm#pprint_dispatch_table"><I>pprint dispatch table</I></A>. <P>
<I>pretty</I>---a <A REL=DEFINITION HREF="26_glo_g.htm#generalized_boolean"><I>generalized boolean</I></A>. <P>
<I>radix</I>---a <A REL=DEFINITION HREF="26_glo_g.htm#generalized_boolean"><I>generalized boolean</I></A>. <P>
<I>readably</I>---a <A REL=DEFINITION HREF="26_glo_g.htm#generalized_boolean"><I>generalized boolean</I></A>. <P>
<I>right-margin</I>---a non-negative <A REL=DEFINITION HREF="26_glo_i.htm#integer"><I>integer</I></A>, or <A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A>. <P>
<I>string</I>---a <A REL=DEFINITION HREF="26_glo_s.htm#string"><I>string</I></A>. <P>
<P><B>Description:</B><P>
<P>
<A REL=DEFINITION HREF="#write-to-string"><B>write-to-string</B></A>, <A REL=DEFINITION HREF="#prin1-to-string"><B>prin1-to-string</B></A>, and <A REL=DEFINITION HREF="#princ-to-string"><B>princ-to-string</B></A> are used to create a <A REL=DEFINITION HREF="26_glo_s.htm#string"><I>string</I></A> consisting of the printed representation of <I>object</I>. <I>Object</I> is effectively printed as if by <A REL=DEFINITION HREF="f_wr_pr.htm#write"><B>write</B></A>, <A REL=DEFINITION HREF="f_wr_pr.htm#prin1"><B>prin1</B></A>, or <A REL=DEFINITION HREF="f_wr_pr.htm#princ"><B>princ</B></A>, respectively, and the <A REL=DEFINITION HREF="26_glo_c.htm#character"><I>characters</I></A> that would be output are made into a <A REL=DEFINITION HREF="26_glo_s.htm#string"><I>string</I></A>. <P>
<A REL=DEFINITION HREF="#write-to-string"><B>write-to-string</B></A> is the general output function. It has the ability to specify all the parameters applicable to the printing of <I>object</I>. <P>
<A REL=DEFINITION HREF="#prin1-to-string"><B>prin1-to-string</B></A> acts like <A REL=DEFINITION HREF="#write-to-string"><B>write-to-string</B></A> with <TT>:escape t</TT>, that is, escape characters are written where appropriate. <P>
<A REL=DEFINITION HREF="#princ-to-string"><B>princ-to-string</B></A> acts like <A REL=DEFINITION HREF="#write-to-string"><B>write-to-string</B></A> with <TT>:escape nil :readably nil</TT>. Thus no <A REL=DEFINITION HREF="26_glo_e.htm#escape"><I>escape</I></A> <A REL=DEFINITION HREF="26_glo_c.htm#character"><I>characters</I></A> are written. <P>
All other keywords that would be specified to <A REL=DEFINITION HREF="#write-to-string"><B>write-to-string</B></A> are default values when <A REL=DEFINITION HREF="#prin1-to-string"><B>prin1-to-string</B></A> or <A REL=DEFINITION HREF="#princ-to-string"><B>princ-to-string</B></A> is invoked. <P>
The meanings and defaults for the keyword arguments to <A REL=DEFINITION HREF="#write-to-string"><B>write-to-string</B></A> are the same as those for <A REL=DEFINITION HREF="f_wr_pr.htm#write"><B>write</B></A>. <P>
<P><B>Examples:</B><P>
<P>
<PRE>
(prin1-to-string &quot;abc&quot;) =&gt; &quot;\&quot;abc\&quot;&quot;
(princ-to-string &quot;abc&quot;) =&gt; &quot;abc&quot;
</PRE>
</TT> <P>
<P><B>Side Effects:</B> None.
<P>
<P><B>Affected By:</B><P>
<P>
<A REL=DEFINITION HREF="v_pr_esc.htm#STprint-escapeST"><B>*print-escape*</B></A>, <A REL=DEFINITION HREF="v_pr_bas.htm#STprint-radixST"><B>*print-radix*</B></A>, <A REL=DEFINITION HREF="v_pr_bas.htm#STprint-baseST"><B>*print-base*</B></A>, <A REL=DEFINITION HREF="v_pr_cir.htm#STprint-circleST"><B>*print-circle*</B></A>, <A REL=DEFINITION HREF="v_pr_pre.htm#STprint-prettyST"><B>*print-pretty*</B></A>, <A REL=DEFINITION HREF="v_pr_lev.htm#STprint-levelST"><B>*print-level*</B></A>, <A REL=DEFINITION HREF="v_pr_lev.htm#STprint-lengthST"><B>*print-length*</B></A>, <A REL=DEFINITION HREF="v_pr_cas.htm#STprint-caseST"><B>*print-case*</B></A>, <A REL=DEFINITION HREF="v_pr_gen.htm#STprint-gensymST"><B>*print-gensym*</B></A>, <A REL=DEFINITION HREF="v_pr_ar.htm#STprint-arrayST"><B>*print-array*</B></A>, <A REL=DEFINITION HREF="v_rd_def.htm#STread-default-float-formatST"><B>*read-default-float-format*</B></A>. <P>
<P><B>Exceptional Situations:</B> None.
<P><B>See Also:</B><P>
<P>
<A REL=DEFINITION HREF="f_wr_pr.htm#write"><B>write</B></A> <P>
<P><B>Notes:</B><P>
<P>
<PRE>
(write-to-string object {key argument}*)
== (with-output-to-string (#1=#:string-stream)
(write object :stream #1# {key argument}*))
(princ-to-string object)
== (with-output-to-string (string-stream)
(princ object string-stream))
(prin1-to-string object)
== (with-output-to-string (string-stream)
(prin1 object string-stream))
</PRE>
</TT> <P><HR>The following <A REL=META HREF="../Front/X3J13Iss.htm">X3J13 cleanup issue</A>, <I>not part of the specification</I>, applies to this section:<P><UL><LI> <A REL=CHILD HREF="../Issues/iss271.htm">PRINC-READABLY:X3J13-DEC-91</A><P></UL><HR>
<A REL=NAVIGATOR HREF="../Front/StartPts.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Starting Points]" SRC="../Graphics/StartPts.gif" ALIGN=Bottom></A><A REL=TOC HREF="../Front/Contents.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Contents]" SRC="../Graphics/Contents.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Master.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Index]" SRC="../Graphics/Index.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Symbol.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Symbols]" SRC="../Graphics/Symbols.gif" ALIGN=Bottom></A><A REL=GLOSSARY HREF="../Body/26_a.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Glossary]" SRC="../Graphics/Glossary.gif" ALIGN=Bottom></A><A HREF="../Front/X3J13Iss.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Issues]" SRC="../Graphics/Issues.gif" ALIGN=Bottom></A><BR>
<A REL=COPYRIGHT HREF="../Front/Help.htm#Legal"><I>Copyright 1996-2005, LispWorks Ltd. All rights reserved.</I></A><P>
</BODY>
</HTML>