87 lines
7.2 KiB
HTML
87 lines
7.2 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: Standard Generic Function DESCRIBE-OBJECT</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_descri.htm">
|
|
<LINK REL=UP HREF="c_enviro.htm">
|
|
<LINK REL=NEXT HREF="m_tracec.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_descri.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="c_enviro.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="m_tracec.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
|
|
|
<HR>
|
|
|
|
<A NAME="describe-object"><I>Standard Generic Function</I> <B>DESCRIBE-OBJECT</B></A> <P>
|
|
<P>
|
|
<P><B>Syntax:</B><P>
|
|
<P>
|
|
|
|
<B>describe-object</B> <I>object stream</I> => <I><A REL=DEFINITION HREF="26_glo_i.htm#implementation-dependent"><I>implementation-dependent</I></A></I><P>
|
|
<P>
|
|
<P><B>Method Signatures:</B><P>
|
|
<P>
|
|
|
|
<B>describe-object</B> <I>(<I>object</I> standard-object) <I>stream</I></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>stream</I>---a <A REL=DEFINITION HREF="26_glo_s.htm#stream"><I>stream</I></A>. <P>
|
|
<P><B>Description:</B><P>
|
|
<P>
|
|
The generic function <A REL=DEFINITION HREF="#describe-object"><B>describe-object</B></A> prints a description of <I>object</I> to a <I>stream</I>. <A REL=DEFINITION HREF="#describe-object"><B>describe-object</B></A> is called by <A REL=DEFINITION HREF="f_descri.htm#describe"><B>describe</B></A>; it must not be called by the user. <P>
|
|
Each implementation is required to provide a <A REL=DEFINITION HREF="26_glo_m.htm#method"><I>method</I></A> on the <A REL=DEFINITION HREF="26_glo_c.htm#class"><I>class</I></A> <A REL=DEFINITION HREF="t_std_ob.htm#standard-object"><B>standard-object</B></A> and <A REL=DEFINITION HREF="26_glo_m.htm#method"><I>methods</I></A> on enough other <A REL=DEFINITION HREF="26_glo_c.htm#class"><I>classes</I></A> so as to ensure that there is always an applicable <A REL=DEFINITION HREF="26_glo_m.htm#method"><I>method</I></A>. Implementations are free to add <A REL=DEFINITION HREF="26_glo_m.htm#method"><I>methods</I></A> for other <A REL=DEFINITION HREF="26_glo_c.htm#class"><I>classes</I></A>. Users can write <A REL=DEFINITION HREF="26_glo_m.htm#method"><I>methods</I></A> for <A REL=DEFINITION HREF="#describe-object"><B>describe-object</B></A> for their own <A REL=DEFINITION HREF="26_glo_c.htm#class"><I>classes</I></A> if they do not wish to inherit an implementation-supplied <A REL=DEFINITION HREF="26_glo_m.htm#method"><I>method</I></A>. <P>
|
|
<A REL=DEFINITION HREF="26_glo_m.htm#method"><I>Methods</I></A> on <A REL=DEFINITION HREF="#describe-object"><B>describe-object</B></A> can recursively call <A REL=DEFINITION HREF="f_descri.htm#describe"><B>describe</B></A>. Indentation, depth limits, and circularity detection are all taken care of automatically, provided that each <A REL=DEFINITION HREF="26_glo_m.htm#method"><I>method</I></A> handles exactly one level of structure and calls <A REL=DEFINITION HREF="f_descri.htm#describe"><B>describe</B></A> recursively if there are more structural levels. The consequences are undefined if this rule is not obeyed. <P>
|
|
In some implementations the <I>stream</I> argument passed to a <A REL=DEFINITION HREF="#describe-object"><B>describe-object</B></A> method is not the original <I>stream</I>, but is an intermediate <A REL=DEFINITION HREF="26_glo_s.htm#stream"><I>stream</I></A> that implements parts of <A REL=DEFINITION HREF="f_descri.htm#describe"><B>describe</B></A>. <A REL=DEFINITION HREF="26_glo_m.htm#method"><I>Methods</I></A> should therefore not depend on the identity of this <A REL=DEFINITION HREF="26_glo_s.htm#stream"><I>stream</I></A>. <P>
|
|
<P><B>Examples:</B><P>
|
|
<P>
|
|
<PRE>
|
|
(defclass spaceship ()
|
|
((captain :initarg :captain :accessor spaceship-captain)
|
|
(serial# :initarg :serial-number :accessor spaceship-serial-number)))
|
|
|
|
(defclass federation-starship (spaceship) ())
|
|
|
|
(defmethod describe-object ((s spaceship) stream)
|
|
(with-slots (captain serial#) s
|
|
(format stream "~&~S is a spaceship of type ~S,~
|
|
~%with ~A at the helm ~
|
|
and with serial number ~D.~%"
|
|
s (type-of s) captain serial#)))
|
|
|
|
(make-instance 'federation-starship
|
|
:captain "Rachel Garrett"
|
|
:serial-number "NCC-1701-C")
|
|
=> #<FEDERATION-STARSHIP 26312465>
|
|
|
|
(describe *)
|
|
>> #<FEDERATION-STARSHIP 26312465> is a spaceship of type FEDERATION-STARSHIP,
|
|
>> with Rachel Garrett at the helm and with serial number NCC-1701-C.
|
|
=> <no values>
|
|
</PRE>
|
|
</TT> <P>
|
|
<P><B>Affected By:</B> None.
|
|
<P>
|
|
<P><B>Exceptional Situations:</B> None.
|
|
<P>
|
|
<P><B>See Also:</B><P>
|
|
<P>
|
|
<A REL=DEFINITION HREF="f_descri.htm#describe"><B>describe</B></A> <P>
|
|
<P><B>Notes:</B><P>
|
|
<P>
|
|
The same implementation techniques that are applicable to <A REL=DEFINITION HREF="f_pr_obj.htm#print-object"><B>print-object</B></A> are applicable to <A REL=DEFINITION HREF="#describe-object"><B>describe-object</B></A>. <P>
|
|
The reason for making the return values for <A REL=DEFINITION HREF="#describe-object"><B>describe-object</B></A> unspecified is to avoid forcing users to include explicit <TT>(values)</TT> in all of their <A REL=DEFINITION HREF="26_glo_m.htm#method"><I>methods</I></A>. <A REL=DEFINITION HREF="f_descri.htm#describe"><B>describe</B></A> takes care of that. <P>
|
|
<P>
|
|
<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/iss128.htm">DESCRIBE-UNDERSPECIFIED:DESCRIBE-OBJECT</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>
|