75 lines
10 KiB
HTML
75 lines
10 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: Function COMPILE</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_lambda.htm">
|
|
<LINK REL=UP HREF="c_evalua.htm">
|
|
<LINK REL=NEXT HREF="f_eval.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_lambda.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_eval.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
|
|
|
<HR>
|
|
|
|
<A NAME="compile"><I>Function</I> <B>COMPILE</B></A> <P>
|
|
<P>
|
|
<P><B>Syntax:</B><P>
|
|
<P>
|
|
|
|
<B>compile</B> <I>name <TT>&optional</TT> definition</I> => <I>function, warnings-p, failure-p</I><P>
|
|
<P>
|
|
<P><B>Arguments and Values:</B><P>
|
|
<P>
|
|
<I>name</I>---a <A REL=DEFINITION HREF="26_glo_f.htm#function_name"><I>function name</I></A>, or <A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A>. <P>
|
|
<I>definition</I>---a <A REL=DEFINITION HREF="26_glo_l.htm#lambda_expression"><I>lambda expression</I></A> or a <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A>. The default is the function definition of <I>name</I> if it names a <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A>, or the <A REL=DEFINITION HREF="26_glo_m.htm#macro_function"><I>macro function</I></A> of <I>name</I> if it names a <A REL=DEFINITION HREF="26_glo_m.htm#macro"><I>macro</I></A>. The consequences are undefined if no <I>definition</I> is supplied when the <I>name</I> is <A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A>. <P>
|
|
<I>function</I>---the <I>function-name</I>, or a <A REL=DEFINITION HREF="26_glo_c.htm#compiled_function"><I>compiled function</I></A>. <P>
|
|
<I>warnings-p</I>---a <A REL=DEFINITION HREF="26_glo_g.htm#generalized_boolean"><I>generalized boolean</I></A>. <P>
|
|
<I>failure-p</I>---a <A REL=DEFINITION HREF="26_glo_g.htm#generalized_boolean"><I>generalized boolean</I></A>. <P>
|
|
<P><B>Description:</B><P>
|
|
<P>
|
|
Compiles an <A REL=DEFINITION HREF="26_glo_i.htm#interpreted_function"><I>interpreted function</I></A>. <P>
|
|
<A REL=DEFINITION HREF="#compile"><B>compile</B></A> produces a <A REL=DEFINITION HREF="26_glo_c.htm#compiled_function"><I>compiled function</I></A> from <I>definition</I>. If the <I>definition</I> is a <A REL=DEFINITION HREF="26_glo_l.htm#lambda_expression"><I>lambda expression</I></A>, it is coerced to a <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A>. If the <I>definition</I> is already a <A REL=DEFINITION HREF="26_glo_c.htm#compiled_function"><I>compiled function</I></A>, <A REL=DEFINITION HREF="#compile"><B>compile</B></A> either produces that function itself (i.e., is an identity operation) or an equivalent function. <P>
|
|
If the <I>name</I> is <A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A>, the resulting <A REL=DEFINITION HREF="26_glo_c.htm#compiled_function"><I>compiled function</I></A> is returned directly as the <A REL=DEFINITION HREF="26_glo_p.htm#primary_value"><I>primary value</I></A>. If a <A REL=DEFINITION HREF="26_glo_n.htm#non-nil"><I>non-nil</I></A> <I>name</I> is given, then the resulting <A REL=DEFINITION HREF="26_glo_c.htm#compiled_function"><I>compiled function</I></A> replaces the existing <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A> definition of <I>name</I> and the <I>name</I> is returned as the <A REL=DEFINITION HREF="26_glo_p.htm#primary_value"><I>primary value</I></A>; if <I>name</I> is a <A REL=DEFINITION HREF="26_glo_s.htm#symbol"><I>symbol</I></A> that names a <A REL=DEFINITION HREF="26_glo_m.htm#macro"><I>macro</I></A>, its <A REL=DEFINITION HREF="26_glo_m.htm#macro_function"><I>macro function</I></A> is updated and the <I>name</I> is returned as the <A REL=DEFINITION HREF="26_glo_p.htm#primary_value"><I>primary value</I></A>. <P>
|
|
<A REL=DEFINITION HREF="26_glo_l.htm#literal"><I>Literal</I></A> <A REL=DEFINITION HREF="26_glo_o.htm#object"><I>objects</I></A> appearing in code processed by the <A REL=DEFINITION HREF="#compile"><B>compile</B></A> function are neither copied nor <I>coalesced</I>. The code resulting from the execution of <A REL=DEFINITION HREF="#compile"><B>compile</B></A> references <A REL=DEFINITION HREF="26_glo_o.htm#object"><I>objects</I></A> that are <A REL=DEFINITION HREF="f_eql.htm#eql"><B>eql</B></A> to the corresponding <A REL=DEFINITION HREF="26_glo_o.htm#object"><I>objects</I></A> in the source code. <P>
|
|
<A REL=DEFINITION HREF="#compile"><B>compile</B></A> is permitted, but not required, to <A REL=DEFINITION HREF="26_glo_e.htm#establish"><I>establish</I></A> a <A REL=DEFINITION HREF="26_glo_h.htm#handler"><I>handler</I></A> for <A REL=DEFINITION HREF="26_glo_c.htm#condition"><I>conditions</I></A> of <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> <A REL=DEFINITION HREF="e_error.htm#error"><B>error</B></A>. For example, the <A REL=DEFINITION HREF="26_glo_h.htm#handler"><I>handler</I></A> might issue a warning and restart compilation from some <A REL=DEFINITION HREF="26_glo_i.htm#implementation-dependent"><I>implementation-dependent</I></A> point in order to let the compilation proceed without manual intervention. <P>
|
|
The <A REL=DEFINITION HREF="26_glo_s.htm#secondary_value"><I>secondary value</I></A>, <I>warnings-p</I>, is <A REL=DEFINITION HREF="26_glo_f.htm#false"><I>false</I></A> if no <A REL=DEFINITION HREF="26_glo_c.htm#condition"><I>conditions</I></A> of <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> <A REL=DEFINITION HREF="e_error.htm#error"><B>error</B></A> or <A REL=DEFINITION HREF="e_warnin.htm#warning"><B>warning</B></A> were detected by the compiler, and <A REL=DEFINITION HREF="26_glo_t.htm#true"><I>true</I></A> otherwise. <P>
|
|
The <A REL=DEFINITION HREF="26_glo_t.htm#tertiary_value"><I>tertiary value</I></A>, <I>failure-p</I>, is <A REL=DEFINITION HREF="26_glo_f.htm#false"><I>false</I></A> if no <A REL=DEFINITION HREF="26_glo_c.htm#condition"><I>conditions</I></A> of <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> <A REL=DEFINITION HREF="e_error.htm#error"><B>error</B></A> or <A REL=DEFINITION HREF="e_warnin.htm#warning"><B>warning</B></A> (other than <A REL=DEFINITION HREF="e_style_.htm#style-warning"><B>style-warning</B></A>) were detected by the compiler, and <A REL=DEFINITION HREF="26_glo_t.htm#true"><I>true</I></A> otherwise. <P>
|
|
<P><B>Examples:</B><P>
|
|
<P>
|
|
<PRE>
|
|
(defun foo () "bar") => FOO
|
|
(compiled-function-p #'foo) => <A REL=DEFINITION HREF="26_glo_i.htm#implementation-dependent">implementation-dependent</A>
|
|
(compile 'foo) => FOO
|
|
(compiled-function-p #'foo) => <A REL=DEFINITION HREF="26_glo_t.htm#true">true</A>
|
|
(setf (symbol-function 'foo)
|
|
(compile nil '(lambda () "replaced"))) => #<Compiled-Function>
|
|
(foo) => "replaced"
|
|
</PRE>
|
|
</TT> <P>
|
|
<P><B>Affected By:</B><P>
|
|
<P>
|
|
<A REL=DEFINITION HREF="v_debug_.htm#STerror-outputST"><B>*error-output*</B></A>, <A REL=DEFINITION HREF="v_mexp_h.htm#STmacroexpand-hookST"><B>*macroexpand-hook*</B></A>. <P>
|
|
The presence of macro definitions and proclamations. <P>
|
|
<P><B>Exceptional Situations:</B><P>
|
|
<P>
|
|
The consequences are undefined if the <A REL=DEFINITION HREF="26_glo_l.htm#lexical_environment"><I>lexical environment</I></A> surrounding the <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A> to be compiled contains any <A REL=DEFINITION HREF="26_glo_b.htm#binding"><I>bindings</I></A> other than those for <A REL=DEFINITION HREF="26_glo_m.htm#macro"><I>macros</I></A>, <A REL=DEFINITION HREF="26_glo_s.htm#symbol_macro"><I>symbol macros</I></A>, or <A REL=DEFINITION HREF="26_glo_d.htm#declaration"><I>declarations</I></A>. <P>
|
|
<P>
|
|
For information about errors detected during the compilation process, see <A REL=CHILD HREF="03_be.htm">Section 3.2.5 (Exceptional Situations in the Compiler)</A>. <P>
|
|
<P><B>See Also:</B><P>
|
|
<P>
|
|
<A REL=DEFINITION HREF="f_cmp_fi.htm#compile-file"><B>compile-file</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/iss068.htm">COMPILER-WARNING-STREAM</A><LI> <A REL=CHILD HREF="../Issues/iss065.htm">COMPILER-DIAGNOSTICS:USE-HANDLER</A><LI> <A REL=CHILD HREF="../Issues/iss282.htm">QUOTE-SEMANTICS:NO-COPYING</A><LI> <A REL=CHILD HREF="../Issues/iss058.htm">COMPILE-ARGUMENT-PROBLEMS-AGAIN:FIX</A><LI> <A REL=CHILD HREF="../Issues/iss064.htm">COMPILED-FUNCTION-REQUIREMENTS:TIGHTEN</A><LI> <A REL=CHILD HREF="../Issues/iss174.htm">FUNCTION-NAME:LARGE</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>
|