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

54 lines
8.3 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: Section 3.1.2.1.1</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="03_aba.htm">
<LINK REL=UP HREF="03_aba.htm">
<LINK REL=NEXT HREF="03_abaaa.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="03_aba.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="03_aba.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="03_abaaa.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<H2>
3.1.2.1.1 Symbols as Forms</H2> <P>
If a <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A> is a <A REL=DEFINITION HREF="26_glo_s.htm#symbol"><I>symbol</I></A>, then it is either a <A REL=DEFINITION HREF="26_glo_s.htm#symbol_macro"><I>symbol macro</I></A> or a <A REL=DEFINITION HREF="26_glo_v.htm#variable"><I>variable</I></A>. <P>
The <A REL=DEFINITION HREF="26_glo_s.htm#symbol"><I>symbol</I></A> names a <A REL=DEFINITION HREF="26_glo_s.htm#symbol_macro"><I>symbol macro</I></A> if there is a <A REL=DEFINITION HREF="26_glo_b.htm#binding"><I>binding</I></A> of the <A REL=DEFINITION HREF="26_glo_s.htm#symbol"><I>symbol</I></A> as a <A REL=DEFINITION HREF="26_glo_s.htm#symbol_macro"><I>symbol macro</I></A> in the current <A REL=DEFINITION HREF="26_glo_l.htm#lexical_environment"><I>lexical environment</I></A> (see <A REL=DEFINITION HREF="m_defi_1.htm#define-symbol-macro"><B>define-symbol-macro</B></A> and <A REL=DEFINITION HREF="s_symbol.htm#symbol-macrolet"><B>symbol-macrolet</B></A>). If the <A REL=DEFINITION HREF="26_glo_s.htm#symbol"><I>symbol</I></A> is a <A REL=DEFINITION HREF="26_glo_s.htm#symbol_macro"><I>symbol macro</I></A>, its expansion function is obtained. The expansion function is a function of two arguments, and is invoked by calling the <A REL=DEFINITION HREF="26_glo_m.htm#macroexpand_hook"><I>macroexpand hook</I></A> with the expansion function as its first argument, the <A REL=DEFINITION HREF="26_glo_s.htm#symbol"><I>symbol</I></A> as its second argument, and an <A REL=DEFINITION HREF="26_glo_e.htm#environment_object"><I>environment object</I></A> (corresponding to the current <A REL=DEFINITION HREF="26_glo_l.htm#lexical_environment"><I>lexical environment</I></A>) as its third argument. The <A REL=DEFINITION HREF="26_glo_m.htm#macroexpand_hook"><I>macroexpand hook</I></A>, in turn, calls the expansion function with the <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A> as its first argument and the <A REL=DEFINITION HREF="26_glo_e.htm#environment"><I>environment</I></A> as its second argument. The <A REL=DEFINITION HREF="26_glo_v.htm#value"><I>value</I></A> of the expansion function, which is passed through by the <A REL=DEFINITION HREF="26_glo_m.htm#macroexpand_hook"><I>macroexpand hook</I></A>, is a <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A>. This resulting <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A> is processed in place of the original <A REL=DEFINITION HREF="26_glo_s.htm#symbol"><I>symbol</I></A>. <P>
If a <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A> is a <A REL=DEFINITION HREF="26_glo_s.htm#symbol"><I>symbol</I></A> that is not a <A REL=DEFINITION HREF="26_glo_s.htm#symbol_macro"><I>symbol macro</I></A>, then it is the <A REL=DEFINITION HREF="26_glo_n.htm#name"><I>name</I></A> of a <A REL=DEFINITION HREF="26_glo_v.htm#variable"><I>variable</I></A>, and the <A REL=DEFINITION HREF="26_glo_v.htm#value"><I>value</I></A> of that <A REL=DEFINITION HREF="26_glo_v.htm#variable"><I>variable</I></A> is returned. There are three kinds of variables: <A REL=DEFINITION HREF="26_glo_l.htm#lexical_variable"><I>lexical variables</I></A>, <A REL=DEFINITION HREF="26_glo_d.htm#dynamic_variable"><I>dynamic variables</I></A>, and <A REL=DEFINITION HREF="26_glo_c.htm#constant_variable"><I>constant variables</I></A>. A <A REL=DEFINITION HREF="26_glo_v.htm#variable"><I>variable</I></A> can store one <A REL=DEFINITION HREF="26_glo_o.htm#object"><I>object</I></A>. The main operations on a <A REL=DEFINITION HREF="26_glo_v.htm#variable"><I>variable</I></A> are to <A REL=DEFINITION HREF="26_glo_r.htm#read"><I>read</I></A>[1] and to <A REL=DEFINITION HREF="26_glo_w.htm#write"><I>write</I></A>[1] its <A REL=DEFINITION HREF="26_glo_v.htm#value"><I>value</I></A>. <P>
An error of <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> <A REL=DEFINITION HREF="e_unbo_1.htm#unbound-variable"><B>unbound-variable</B></A> should be signaled if an <A REL=DEFINITION HREF="26_glo_u.htm#unbound_variable"><I>unbound variable</I></A> is referenced. <P>
<A REL=DEFINITION HREF="26_glo_n.htm#non-constant_variable"><I>Non-constant variables</I></A> can be <I>assigned</I> by using <A REL=DEFINITION HREF="s_setq.htm#setq"><B>setq</B></A> or <A REL=DEFINITION HREF="26_glo_b.htm#bound"><I>bound</I></A>[3] by using <A REL=DEFINITION HREF="s_let_l.htm#let"><B>let</B></A>. The next figure lists some <A REL=DEFINITION HREF="26_glo_d.htm#defined_name"><I>defined names</I></A> that are applicable to assigning, binding, and defining <A REL=DEFINITION HREF="26_glo_v.htm#variable"><I>variables</I></A>. <P>
<PRE>
<A REL=DEFINITION HREF="f_boundp.htm#boundp">boundp</A> <A REL=DEFINITION HREF="s_let_l.htm#let">let</A> <A REL=DEFINITION HREF="s_progv.htm#progv">progv</A>
<A REL=DEFINITION HREF="m_defcon.htm#defconstant">defconstant</A> <A REL=DEFINITION HREF="s_let_l.htm#letST">let*</A> <A REL=DEFINITION HREF="m_psetq.htm#psetq">psetq</A>
<A REL=DEFINITION HREF="m_defpar.htm#defparameter">defparameter</A> <A REL=DEFINITION HREF="f_makunb.htm#makunbound">makunbound</A> <A REL=DEFINITION HREF="f_set.htm#set">set</A>
<A REL=DEFINITION HREF="m_defpar.htm#defvar">defvar</A> <A REL=DEFINITION HREF="m_multip.htm#multiple-value-bind">multiple-value-bind</A> <A REL=DEFINITION HREF="s_setq.htm#setq">setq</A>
<A REL=DEFINITION HREF="a_lambda.htm#lambda">lambda</A> <A REL=DEFINITION HREF="m_mult_2.htm#multiple-value-setq">multiple-value-setq</A> <A REL=DEFINITION HREF="f_symb_5.htm#symbol-value">symbol-value</A>
</PRE>
<P><B>Figure 3-1. Some Defined Names Applicable to Variables</B> <P>
The following is a description of each kind of variable. <P>
<A REL=CHILD HREF="03_abaaa.htm"><H2>
3.1.2.1.1.1 Lexical Variables</H2></A><P>
<A REL=CHILD HREF="03_abaab.htm"><H2>
3.1.2.1.1.2 Dynamic Variables</H2></A><P>
<A REL=CHILD HREF="03_abaac.htm"><H2>
3.1.2.1.1.3 Constant Variables</H2></A><P>
<A REL=CHILD HREF="03_abaad.htm"><H2>
3.1.2.1.1.4 Symbols Naming Both Lexical and Dynamic Variables</H2></A><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/iss198.htm">ISO-COMPATIBILITY:ADD-SUBSTRATE</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>