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

88 lines
13 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: Symbol DECLARE</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="m_declai.htm">
<LINK REL=UP HREF="c_evalua.htm">
<LINK REL=NEXT HREF="d_ignore.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="m_declai.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="c_evalua.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="d_ignore.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<A NAME="declare"><I>Symbol</I> <B>DECLARE</B></A> <P>
<P><B>Syntax:</B><P>
<P>
<B>declare</B> <I><I>declaration-specifier</I><B>*</B></I><P>
<P>
<P><B>Arguments:</B><P>
<P>
<I>declaration-specifier</I>---a <A REL=DEFINITION HREF="26_glo_d.htm#declaration_specifier"><I>declaration specifier</I></A>; not evaluated. <P>
<P><B>Description:</B><P>
<P>
A <A REL=DEFINITION HREF="#declare"><B>declare</B></A> <A REL=DEFINITION HREF="26_glo_e.htm#expression"><I>expression</I></A>, sometimes called a <A REL=DEFINITION HREF="26_glo_d.htm#declaration"><I>declaration</I></A>, can occur only at the beginning of the bodies of certain <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>forms</I></A>; that is, it may be preceded only by other <A REL=DEFINITION HREF="#declare"><B>declare</B></A> <A REL=DEFINITION HREF="26_glo_e.htm#expression"><I>expressions</I></A>, or by a <A REL=DEFINITION HREF="26_glo_d.htm#documentation_string"><I>documentation string</I></A> if the context permits. <P>
A <A REL=DEFINITION HREF="#declare"><B>declare</B></A> <A REL=DEFINITION HREF="26_glo_e.htm#expression"><I>expression</I></A> can occur in a <A REL=DEFINITION HREF="26_glo_l.htm#lambda_expression"><I>lambda expression</I></A> or in any of the <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>forms</I></A> listed in the next figure. <P>
<PRE>
<A REL=DEFINITION HREF="m_defgen.htm#defgeneric">defgeneric</A> <A REL=DEFINITION HREF="m_do_sym.htm#do-external-symbols">do-external-symbols</A> <A REL=DEFINITION HREF="m_prog_.htm#prog">prog</A>
<A REL=DEFINITION HREF="m_define.htm#define-compiler-macro">define-compiler-macro</A> <A REL=DEFINITION HREF="m_do_sym.htm#do-symbols">do-symbols</A> <A REL=DEFINITION HREF="m_prog_.htm#progST">prog*</A>
<A REL=DEFINITION HREF="m_defi_4.htm#define-method-combination">define-method-combination</A> <A REL=DEFINITION HREF="m_dolist.htm#dolist">dolist</A> <A REL=DEFINITION HREF="m_rst_ca.htm#restart-case">restart-case</A>
<A REL=DEFINITION HREF="m_defi_3.htm#define-setf-expander">define-setf-expander</A> <A REL=DEFINITION HREF="m_dotime.htm#dotimes">dotimes</A> <A REL=DEFINITION HREF="s_symbol.htm#symbol-macrolet">symbol-macrolet</A>
<A REL=DEFINITION HREF="m_defmac.htm#defmacro">defmacro</A> <A REL=DEFINITION HREF="s_flet_.htm#flet">flet</A> <A REL=DEFINITION HREF="m_w_acce.htm#with-accessors">with-accessors</A>
<A REL=DEFINITION HREF="m_defmet.htm#defmethod">defmethod</A> <A REL=DEFINITION HREF="m_hand_1.htm#handler-case">handler-case</A> <A REL=DEFINITION HREF="m_w_hash.htm#with-hash-table-iterator">with-hash-table-iterator</A>
<A REL=DEFINITION HREF="m_defset.htm#defsetf">defsetf</A> <A REL=DEFINITION HREF="s_flet_.htm#labels">labels</A> <A REL=DEFINITION HREF="m_w_in_f.htm#with-input-from-string">with-input-from-string</A>
<A REL=DEFINITION HREF="m_deftp.htm#deftype">deftype</A> <A REL=DEFINITION HREF="s_let_l.htm#let">let</A> <A REL=DEFINITION HREF="m_w_open.htm#with-open-file">with-open-file</A>
<A REL=DEFINITION HREF="m_defun.htm#defun">defun</A> <A REL=DEFINITION HREF="s_let_l.htm#letST">let*</A> <A REL=DEFINITION HREF="m_w_op_1.htm#with-open-stream">with-open-stream</A>
<A REL=DEFINITION HREF="m_destru.htm#destructuring-bind">destructuring-bind</A> <A REL=DEFINITION HREF="s_locall.htm#locally">locally</A> <A REL=DEFINITION HREF="m_w_out_.htm#with-output-to-string">with-output-to-string</A>
<A REL=DEFINITION HREF="m_do_do.htm#do">do</A> <A REL=DEFINITION HREF="s_flet_.htm#macrolet">macrolet</A> <A REL=DEFINITION HREF="m_w_pkg_.htm#with-package-iterator">with-package-iterator</A>
<A REL=DEFINITION HREF="m_do_do.htm#doST">do*</A> <A REL=DEFINITION HREF="m_multip.htm#multiple-value-bind">multiple-value-bind</A> <A REL=DEFINITION HREF="m_w_slts.htm#with-slots">with-slots</A>
<A REL=DEFINITION HREF="m_do_sym.htm#do-all-symbols">do-all-symbols</A> <A REL=DEFINITION HREF="m_ppr_lo.htm#pprint-logical-block">pprint-logical-block</A>
</PRE>
<P><B>Figure 3-23. Standardized Forms In Which Declarations Can Occur</B> <P>
A <A REL=DEFINITION HREF="#declare"><B>declare</B></A> <A REL=DEFINITION HREF="26_glo_e.htm#expression"><I>expression</I></A> can only occur where specified by the syntax of these <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>forms</I></A>. The consequences of attempting to evaluate a <A REL=DEFINITION HREF="#declare"><B>declare</B></A> <A REL=DEFINITION HREF="26_glo_e.htm#expression"><I>expression</I></A> are undefined. In situations where such <A REL=DEFINITION HREF="26_glo_e.htm#expression"><I>expressions</I></A> can appear, explicit checks are made for their presence and they are never actually evaluated; it is for this reason that they are called ``<A REL=DEFINITION HREF="#declare"><B>declare</B></A> <A REL=DEFINITION HREF="26_glo_e.htm#expression"><I>expressions</I></A>'' rather than ``<A REL=DEFINITION HREF="#declare"><B>declare</B></A> <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>forms</I></A>.'' <P>
<A REL=DEFINITION HREF="26_glo_m.htm#macro_form"><I>Macro forms</I></A> cannot expand into declarations; <A REL=DEFINITION HREF="#declare"><B>declare</B></A> <A REL=DEFINITION HREF="26_glo_e.htm#expression"><I>expressions</I></A> must appear as actual <A REL=DEFINITION HREF="26_glo_s.htm#subexpression"><I>subexpressions</I></A> of the <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A> to which they refer. <P>
The next figure shows a list of <A REL=DEFINITION HREF="26_glo_d.htm#declaration_identifier"><I>declaration identifiers</I></A> that can be used with <A REL=DEFINITION HREF="#declare"><B>declare</B></A>. <P>
<PRE>
<A REL=DEFINITION HREF="d_dynami.htm#dynamic-extent">dynamic-extent</A> <A REL=DEFINITION HREF="d_ignore.htm#ignore">ignore</A> <A REL=DEFINITION HREF="d_optimi.htm#optimize">optimize</A>
<A REL=DEFINITION HREF="d_ftype.htm#ftype">ftype</A> <A REL=DEFINITION HREF="d_inline.htm#inline">inline</A> <A REL=DEFINITION HREF="d_specia.htm#special">special</A>
<A REL=DEFINITION HREF="d_ignore.htm#ignorable">ignorable</A> <A REL=DEFINITION HREF="d_inline.htm#notinline">notinline</A> <A REL=DEFINITION HREF="a_type.htm#type">type</A>
</PRE>
<P><B>Figure 3-24. Local Declaration Specifiers</B> <P>
An implementation is free to support other (<A REL=DEFINITION HREF="26_glo_i.htm#implementation-defined"><I>implementation-defined</I></A>) <A REL=DEFINITION HREF="26_glo_d.htm#declaration_identifier"><I>declaration identifiers</I></A> as well. <P>
<P><B>Examples:</B><P>
<P>
<PRE>
(defun nonsense (k x z)
(foo z x) ;First call to foo
(let ((j (foo k x)) ;Second call to foo
(x (* k k)))
(declare (inline foo) (special x z))
(foo x j z))) ;Third call to foo
</PRE>
</TT> <P>
In this example, the <A REL=DEFINITION HREF="d_inline.htm#inline"><B>inline</B></A> declaration applies only to the third call to <TT>foo</TT>, but not to the first or second ones. The <A REL=DEFINITION HREF="d_specia.htm#special"><B>special</B></A> declaration of <TT>x</TT> causes <A REL=DEFINITION HREF="s_let_l.htm#let"><B>let</B></A> to make a dynamic <A REL=DEFINITION HREF="26_glo_b.htm#binding"><I>binding</I></A> for <TT>x</TT>, and causes the reference to <TT>x</TT> in the body of <A REL=DEFINITION HREF="s_let_l.htm#let"><B>let</B></A> to be a dynamic reference. The reference to <TT>x</TT> in the second call to <TT>foo</TT> is a local reference to the second parameter of <TT>nonsense</TT>. The reference to <TT>x</TT> in the first call to <TT>foo</TT> is a local reference, not a <A REL=DEFINITION HREF="d_specia.htm#special"><B>special</B></A> one. The <A REL=DEFINITION HREF="d_specia.htm#special"><B>special</B></A> declaration of <TT>z</TT> causes the reference to <TT>z</TT> in the third call to <TT>foo</TT> to be a dynamic reference; it does not refer to the parameter to <TT>nonsense</TT> named <TT>z</TT>, because that parameter <A REL=DEFINITION HREF="26_glo_b.htm#binding"><I>binding</I></A> has not been declared to be <A REL=DEFINITION HREF="d_specia.htm#special"><B>special</B></A>. (The <A REL=DEFINITION HREF="d_specia.htm#special"><B>special</B></A> declaration of <TT>z</TT> does not appear in the body of <A REL=DEFINITION HREF="m_defun.htm#defun"><B>defun</B></A>, but in an inner <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A>, and therefore does not affect the <A REL=DEFINITION HREF="26_glo_b.htm#binding"><I>binding</I></A> of the <A REL=DEFINITION HREF="26_glo_p.htm#parameter"><I>parameter</I></A>.) <P>
<P><B>Affected By:</B> None.
<P>
<P><B>Exceptional Situations:</B><P>
<P>
The consequences of trying to use a <A REL=DEFINITION HREF="#declare"><B>declare</B></A> <A REL=DEFINITION HREF="26_glo_e.htm#expression"><I>expression</I></A> as a <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A> to be <I>evaluated</I> are undefined. <P>
<P>
<P><B>See Also:</B><P>
<P>
<A REL=DEFINITION HREF="f_procla.htm#proclaim"><B>proclaim</B></A>, <A REL=CHILD HREF="04_bc.htm">Section 4.2.3 (Type Specifiers)</A>, <A REL=DEFINITION HREF="d_declar.htm#declaration"><B>declaration</B></A>, <A REL=DEFINITION HREF="d_dynami.htm#dynamic-extent"><B>dynamic-extent</B></A>, <A REL=DEFINITION HREF="d_ftype.htm#ftype"><B>ftype</B></A>, <A REL=DEFINITION HREF="d_ignore.htm#ignorable"><B>ignorable</B></A>, <A REL=DEFINITION HREF="d_ignore.htm#ignore"><B>ignore</B></A>, <A REL=DEFINITION HREF="d_inline.htm#inline"><B>inline</B></A>, <A REL=DEFINITION HREF="d_inline.htm#notinline"><B>notinline</B></A>, <A REL=DEFINITION HREF="d_optimi.htm#optimize"><B>optimize</B></A>, <A REL=DEFINITION HREF="d_type.htm#type"><B>type</B></A> <P>
<P><B>Notes:</B> None.
<P>
<P><HR>The following <A REL=META HREF="../Front/X3J13Iss.htm">X3J13 cleanup issues</A>, <I>not part of the specification</I>, apply to this section:<P><UL><LI> <A REL=CHILD HREF="../Issues/iss094.htm">DECLARE-FUNCTION-AMBIGUITY:DELETE-FTYPE-ABBREVIATION</A><LI> <A REL=CHILD HREF="../Issues/iss142.htm">DYNAMIC-EXTENT:NEW-DECLARATION</A><LI> <A REL=CHILD HREF="../Issues/iss095.htm">DECLARE-MACROS:FLUSH</A><LI> <A REL=CHILD HREF="../Issues/iss181.htm">GENERIC-FLET-POORLY-DESIGNED:DELETE</A><LI> <A REL=CHILD HREF="../Issues/iss359.htm">WITH-ADDED-METHODS:DELETE</A><LI> <A REL=CHILD HREF="../Issues/iss337.htm">SYMBOL-MACROLET-DECLARE:ALLOW</A><LI> <A REL=CHILD HREF="../Issues/iss308.htm">SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS</A><LI> <A REL=CHILD HREF="../Issues/iss097.htm">DECLS-AND-DOC</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>