81 lines
6.3 KiB
HTML
81 lines
6.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: Accessor MACRO-FUNCTION</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_defmac.htm">
|
|
<LINK REL=UP HREF="c_evalua.htm">
|
|
<LINK REL=NEXT HREF="f_mexp_.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_defmac.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="f_mexp_.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
|
|
|
<HR>
|
|
|
|
<A NAME="macro-function"><I>Accessor</I> <B>MACRO-FUNCTION</B></A> <P>
|
|
<P><B>Syntax:</B><P>
|
|
<P>
|
|
|
|
<B>macro-function</B> <I>symbol <TT>&optional</TT> environment</I> => <I>function</I><P>
|
|
|
|
<TT>(setf (</TT><B>macro-function</B> <I>symbol <TT>&optional</TT> environment</I><TT>) </TT><I>new-function</I><TT>)</TT><P>
|
|
<P>
|
|
<P><B>Arguments and Values:</B><P>
|
|
<P>
|
|
<I>symbol</I>---a <A REL=DEFINITION HREF="26_glo_s.htm#symbol"><I>symbol</I></A>. <P>
|
|
<I>environment</I>---an <A REL=DEFINITION HREF="26_glo_e.htm#environment"><I>environment</I></A> <A REL=DEFINITION HREF="26_glo_o.htm#object"><I>object</I></A>. <P>
|
|
<I>function</I>---a <A REL=DEFINITION HREF="26_glo_m.htm#macro_function"><I>macro function</I></A> or <A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A>. <P>
|
|
<I>new-function</I>---a <A REL=DEFINITION HREF="26_glo_m.htm#macro_function"><I>macro function</I></A>. <P>
|
|
<P><B>Description:</B><P>
|
|
<P>
|
|
Determines whether <I>symbol</I> has a function definition as a macro in the specified <I>environment</I>. <P>
|
|
If so, the macro expansion function, a function of two arguments, is returned. If <I>symbol</I> has no function definition in the lexical environment <I>environment</I>, or its definition is not a <A REL=DEFINITION HREF="26_glo_m.htm#macro"><I>macro</I></A>, <A REL=DEFINITION HREF="#macro-function"><B>macro-function</B></A> returns <A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A>. <P>
|
|
<P>
|
|
<P>
|
|
It is possible for both <A REL=DEFINITION HREF="#macro-function"><B>macro-function</B></A> and <A REL=DEFINITION HREF="f_specia.htm#special-operator-p"><B>special-operator-p</B></A> to return <A REL=DEFINITION HREF="26_glo_t.htm#true"><I>true</I></A> of <I>symbol</I>. The <A REL=DEFINITION HREF="26_glo_m.htm#macro"><I>macro</I></A> definition must be available for use by programs that understand only the standard Common Lisp <A REL=DEFINITION HREF="26_glo_s.htm#special_form"><I>special forms</I></A>. <P>
|
|
<P><B>Examples:</B><P>
|
|
|
|
<PRE>
|
|
(defmacro macfun (x) '(macro-function 'macfun)) => MACFUN
|
|
(not (macro-function 'macfun)) => <A REL=DEFINITION HREF="26_glo_f.htm#false">false</A>
|
|
</PRE>
|
|
</TT>
|
|
<PRE>
|
|
(macrolet ((foo (&environment env)
|
|
(if (macro-function 'bar env)
|
|
''yes
|
|
''no)))
|
|
(list (foo)
|
|
(macrolet ((bar () :beep))
|
|
(foo))))
|
|
|
|
=> (NO YES)
|
|
</PRE>
|
|
</TT> <P>
|
|
<P><B>Affected By:</B><P>
|
|
<TT>(setf macro-function)</TT>, <A REL=DEFINITION HREF="m_defmac.htm#defmacro"><B>defmacro</B></A>, and <A REL=DEFINITION HREF="s_flet_.htm#macrolet"><B>macrolet</B></A>. <P>
|
|
<P><B>Exceptional Situations:</B><P>
|
|
<P>
|
|
The consequences are undefined if <I>environment</I> is <A REL=DEFINITION HREF="26_glo_n.htm#non-nil"><I>non-nil</I></A> in a use of <A REL=DEFINITION HREF="m_setf_.htm#setf"><B>setf</B></A> of <A REL=DEFINITION HREF="#macro-function"><B>macro-function</B></A>. <P>
|
|
<P><B>See Also:</B><P>
|
|
<P>
|
|
<A REL=DEFINITION HREF="m_defmac.htm#defmacro"><B>defmacro</B></A>, <A REL=CHILD HREF="03_a.htm">Section 3.1 (Evaluation)</A> <P>
|
|
<P><B>Notes:</B><P>
|
|
<P>
|
|
<A REL=DEFINITION HREF="m_setf_.htm#setf"><B>setf</B></A> can be used with <A REL=DEFINITION HREF="#macro-function"><B>macro-function</B></A> to install a <A REL=DEFINITION HREF="26_glo_m.htm#macro"><I>macro</I></A> as a symbol's global function definition: <P>
|
|
<PRE>
|
|
(setf (macro-function symbol) fn)
|
|
</PRE>
|
|
</TT> The value installed must be a <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A> that accepts two arguments, the entire macro call and an <A REL=DEFINITION HREF="26_glo_e.htm#environment"><I>environment</I></A>, and computes the expansion for that call. Performing this operation causes <I>symbol</I> to have only that macro definition as its global function definition; any previous definition, whether as a <A REL=DEFINITION HREF="26_glo_m.htm#macro"><I>macro</I></A> or as a <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A>, is lost. <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/iss321.htm">SPECIAL-FORM-P-MISNOMER:RENAME</A><LI> <A REL=CHILD HREF="../Issues/iss230.htm">MACRO-FUNCTION-ENVIRONMENT</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>
|