1
0
Fork 0
cl-sites/HyperSpec-7-0/HyperSpec/Body/m_defcon.htm

72 lines
7.5 KiB
HTML
Raw Permalink Normal View History

2024-04-01 10:24:07 +02:00
<!-- Common Lisp HyperSpec (TM), version 7.0 generated by Kent M. Pitman on Mon, 11-Apr-2005 2:31am EDT -->
<HTML>
<HEAD>
<TITLE>CLHS: Macro DEFCONSTANT</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="v_lamb_1.htm">
<LINK REL=UP HREF="c_data_a.htm">
<LINK REL=NEXT HREF="m_defpar.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="v_lamb_1.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="c_data_a.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="m_defpar.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<A NAME="defconstant"><I>Macro</I> <B>DEFCONSTANT</B></A> <P>
<P><B>Syntax:</B><P>
<P>
<B>defconstant</B> <I>name initial-value [documentation]</I> =&gt; <I>name</I><P>
<P>
<P><B>Arguments and Values:</B><P>
<P>
<I>name</I>---a <A REL=DEFINITION HREF="26_glo_s.htm#symbol"><I>symbol</I></A>; not evaluated. <P>
<I>initial-value</I>---a <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A>; evaluated. <P>
<I>documentation</I>---a <A REL=DEFINITION HREF="26_glo_s.htm#string"><I>string</I></A>; not evaluated. <P>
<P><B>Description:</B><P>
<P>
<A REL=DEFINITION HREF="#defconstant"><B>defconstant</B></A> causes the global variable named by <I>name</I> to be given a value that is the result of evaluating <I>initial-value</I>. <P>
A constant defined by <A REL=DEFINITION HREF="#defconstant"><B>defconstant</B></A> can be redefined with <A REL=DEFINITION HREF="#defconstant"><B>defconstant</B></A>. However, the consequences are undefined if an attempt is made to assign a <A REL=DEFINITION HREF="26_glo_v.htm#value"><I>value</I></A> to the <A REL=DEFINITION HREF="26_glo_s.htm#symbol"><I>symbol</I></A> using another operator, or to assign it to a <A REL=DEFINITION HREF="26_glo_d.htm#different"><I>different</I></A> <A REL=DEFINITION HREF="26_glo_v.htm#value"><I>value</I></A> using a subsequent <A REL=DEFINITION HREF="#defconstant"><B>defconstant</B></A>. <P>
If <I>documentation</I> is supplied, it is attached to <I>name</I> as a <A REL=DEFINITION HREF="26_glo_d.htm#documentation_string"><I>documentation string</I></A> of kind <A REL=DEFINITION HREF="f_docume.htm#variable"><B>variable</B></A>. <P>
<A REL=DEFINITION HREF="#defconstant"><B>defconstant</B></A> normally appears as a <A REL=DEFINITION HREF="26_glo_t.htm#top_level_form"><I>top level form</I></A>, but it is meaningful for it to appear as a <A REL=DEFINITION HREF="26_glo_n.htm#non-top-level_form"><I>non-top-level form</I></A>. However, the compile-time side effects described below only take place when <A REL=DEFINITION HREF="#defconstant"><B>defconstant</B></A> appears as a <A REL=DEFINITION HREF="26_glo_t.htm#top_level_form"><I>top level form</I></A>. <P>
The consequences are undefined if there are any <A REL=DEFINITION HREF="26_glo_b.htm#binding"><I>bindings</I></A> of the variable named by <I>name</I> at the time <A REL=DEFINITION HREF="#defconstant"><B>defconstant</B></A> is executed or if the value is not <A REL=DEFINITION HREF="f_eql.htm#eql"><B>eql</B></A> to the value of <I>initial-value</I>. <P>
The consequences are undefined when constant <A REL=DEFINITION HREF="26_glo_s.htm#symbol"><I>symbols</I></A> are rebound as either lexical or dynamic variables. In other words, a reference to a <A REL=DEFINITION HREF="26_glo_s.htm#symbol"><I>symbol</I></A> declared with <A REL=DEFINITION HREF="#defconstant"><B>defconstant</B></A> always refers to its global value. <P>
The side effects of the execution of <A REL=DEFINITION HREF="#defconstant"><B>defconstant</B></A> must be equivalent to at least the side effects of the execution of the following code: <P>
<PRE>
(setf (symbol-value 'name) initial-value)
(setf (documentation 'name 'variable) 'documentation)
</PRE>
</TT> <P>
If a <A REL=DEFINITION HREF="#defconstant"><B>defconstant</B></A> <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A> appears as a <A REL=DEFINITION HREF="26_glo_t.htm#top_level_form"><I>top level form</I></A>, the <A REL=DEFINITION HREF="26_glo_c.htm#compiler"><I>compiler</I></A> must recognize that <I>name</I> names a <A REL=DEFINITION HREF="26_glo_c.htm#constant_variable"><I>constant variable</I></A>. An implementation may choose to evaluate the value-form at compile time, load time, or both. Therefore, users must ensure that the <I>initial-value</I> can be <I>evaluated</I> at compile time (regardless of whether or not references to <I>name</I> appear in the file) and that it always <A REL=DEFINITION HREF="26_glo_e.htm#evaluate"><I>evaluates</I></A> to the same value. <P>
<P>
<P><B>Examples:</B><P>
<PRE>
(defconstant this-is-a-constant 'never-changing &quot;for a test&quot;) =&gt; THIS-IS-A-CONSTANT
this-is-a-constant =&gt; NEVER-CHANGING
(documentation 'this-is-a-constant 'variable) =&gt; &quot;for a test&quot;
(constantp 'this-is-a-constant) =&gt; <A REL=DEFINITION HREF="26_glo_t.htm#true">true</A>
</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="m_declai.htm#declaim"><B>declaim</B></A>, <A REL=DEFINITION HREF="m_defpar.htm#defparameter"><B>defparameter</B></A>, <A REL=DEFINITION HREF="m_defpar.htm#defvar"><B>defvar</B></A>, <A REL=DEFINITION HREF="f_docume.htm#documentation"><B>documentation</B></A>, <A REL=DEFINITION HREF="f_procla.htm#proclaim"><B>proclaim</B></A>, <A REL=CHILD HREF="03_abaac.htm">Section 3.1.2.1.1.3 (Constant Variables)</A>, <A REL=CHILD HREF="03_b.htm">Section 3.2 (Compilation)</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/iss059.htm">COMPILE-FILE-HANDLING-OF-TOP-LEVEL-FORMS:CLARIFY</A><LI> <A REL=CHILD HREF="../Issues/iss099.htm">DEFCONSTANT-SPECIAL:NO</A><LI> <A REL=CHILD HREF="../Issues/iss104.htm">DEFINING-MACROS-NON-TOP-LEVEL:ALLOW</A><LI> <A REL=CHILD HREF="../Issues/iss123.htm">DEFVAR-DOCUMENTATION:UNEVALUATED</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>