1
0
Fork 0
cl-sites/novaspec.org/cl/f_flet.html

1082 lines
22 KiB
HTML
Raw Normal View History

2025-02-05 18:52:26 +01:00
<!DOCTYPE HTML>
<HTML LANG="en-us"
><HEAD
><TITLE
>flet, labels, macrolet | Common Lisp Nova Spec</TITLE
><META CHARSET="US-ASCII"
><LINK REL="canonical" HREF="f_flet.html"
><LINK REL="next" HREF="f_funcall.html" TYPE="text/html" TITLE="funcall"
><LINK REL="prev" HREF="f_fmakunbound.html" TYPE="text/html" TITLE="fmakunbound"
><LINK REL="up" HREF="5_3_Data_and_Control_Flow_Dictionary.html" TYPE="text/html" TITLE="5.3 Data and Control Flow Dictionary"
><LINK REL="start" HREF="index.html" TYPE="text/html" TITLE="Common Lisp Nova Spec"
><META NAME="VIEWPORT" CONTENT="width=device-width, initial-scale=1.0"
><LINK REL="STYLESHEET" HREF="dpans.css%3F3909942064.css"
><SCRIPT SRC="dpans.js%3F3909942064"
></SCRIPT
><SCRIPT SRC="apropos.js%3F3909942064"
></SCRIPT
></HEAD
><BODY
><DIV
><DIV CLASS="topnav"
><DIV CLASS="breadcrumb"
><SPAN CLASS="breadcrumb-item"
><A HREF="index.html"
>Common Lisp Nova Spec</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="5_Data_and_Control_Flow.html"
>5. Data and Control Flow</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="5_3_Data_and_Control_Flow_Dictionary.html"
>5.3 Data and Control Flow Dictionary</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="f_flet.html"
>flet, labels, macrolet</A
></SPAN
></DIV
><DIV CLASS="apropos"
><DIV CLASS="apropos-io"
><A HREF="f_fmakunbound.html" CLASS="prev"
>&#8592;</A
><SPAN ID="apropos-label"
>Apropos </SPAN
><INPUT ID="apropos" AUTOFOCUS="AUTOFOCUS" PLACEHOLDER="Type here to search" ONINPUT="aproposInput(this);" ONKEYUP="aproposKeyup(event);" ONCHANGE="aproposChange(this);" ONFOCUS="aproposFocus(this);" ONFOCUSOUT="aproposFocusout(this);"
><A HREF="f_funcall.html" CLASS="next"
>&#8594;</A
></DIV
><DIV ID="apropos-res"
></DIV
></DIV
></DIV
><DIV CLASS="matter"
><DIV CLASS="com"
><DIV CLASS="begincom"
><HR
><TABLE WIDTH="100%" CELLSPACING="0" CELLPADDING="0"
><TR
><TD ALIGN="LEFT" VALIGN="BASELINE" WIDTH="100%" CLASS="name"
><SPAN CLASS="idx" DATA-KIND="idxref" DATA-TERM="flet, labels, macrolet"
></SPAN
><B
>flet, labels, macrolet</B
></TD
><TD ALIGN="RIGHT" VALIGN="BASELINE" WIDTH="0" NOWRAP="NOWRAP" CLASS="ftype"
><I
>Special</I
> <I
>Operator</I
></TD
></TR
></TABLE
><HR
></DIV
><UL CLASS="subtoc"
></UL
><DL
><DT
><B
>Syntax</B
></DT
><DD
><TABLE CELLPADDING="0" CELLSPACING="0"
><TR
><TD VALIGN="BASELINE" ALIGN="LEFT" NOWRAP="NOWRAP"
><B
>flet</B
><SPAN CLASS="cmr"
>&#160;</SPAN
></TD
><TD VALIGN="BASELINE" ALIGN="LEFT"
><SPAN CLASS="cmr"
>(</SPAN
><SPAN CLASS="cmsy"
>{</SPAN
><SPAN CLASS="cmr"
>(</SPAN
><VAR CLASS="param"
>function-name</VAR
> <VAR CLASS="param"
>lambda-list</VAR
> <SPAN CLASS="cmr"
>&#10214;&#8201;</SPAN
><SPAN CLASS="cmsy"
>{</SPAN
><VAR CLASS="param"
>local-declaration</VAR
><SPAN CLASS="cmsy"
>}</SPAN
><SPAN CLASS="cmr"
>*</SPAN
> <SPAN CLASS="cmsy"
>|</SPAN
> <VAR CLASS="param"
>local-documentation</VAR
>&#8201;<SPAN CLASS="cmr"
>&#8201;&#10215;</SPAN
>&#8201;<SPAN CLASS="cmsy"
>{</SPAN
><VAR CLASS="param"
>local-form</VAR
><SPAN CLASS="cmsy"
>}</SPAN
><SPAN CLASS="cmr"
>*)</SPAN
><SPAN CLASS="cmsy"
>}</SPAN
><SPAN CLASS="cmr"
>*)</SPAN
><BR
><SPAN CLASS="cmsy"
>{</SPAN
><VAR CLASS="param"
>declaration</VAR
><SPAN CLASS="cmsy"
>}</SPAN
><SPAN CLASS="cmr"
>*</SPAN
> <SPAN CLASS="cmsy"
>{</SPAN
><VAR CLASS="param"
>form</VAR
><SPAN CLASS="cmsy"
>}</SPAN
><SPAN CLASS="cmr"
>*</SPAN
></TD
></TR
></TABLE
><DIV
><SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> <SPAN CLASS="cmsy"
>{</SPAN
><VAR CLASS="param"
>result</VAR
><SPAN CLASS="cmsy"
>}</SPAN
><SPAN CLASS="cmr"
>*</SPAN
></DIV
><TABLE CELLPADDING="0" CELLSPACING="0"
><TR
><TD VALIGN="BASELINE" ALIGN="LEFT" NOWRAP="NOWRAP"
><B
>labels</B
><SPAN CLASS="cmr"
>&#160;</SPAN
></TD
><TD VALIGN="BASELINE" ALIGN="LEFT"
><SPAN CLASS="cmr"
>(</SPAN
><SPAN CLASS="cmsy"
>{</SPAN
><SPAN CLASS="cmr"
>(</SPAN
><VAR CLASS="param"
>function-name</VAR
> <VAR CLASS="param"
>lambda-list</VAR
> <SPAN CLASS="cmr"
>&#10214;&#8201;</SPAN
><SPAN CLASS="cmsy"
>{</SPAN
><VAR CLASS="param"
>local-declaration</VAR
><SPAN CLASS="cmsy"
>}</SPAN
><SPAN CLASS="cmr"
>*</SPAN
> <SPAN CLASS="cmsy"
>|</SPAN
> <VAR CLASS="param"
>local-documentation</VAR
>&#8201;<SPAN CLASS="cmr"
>&#8201;&#10215;</SPAN
>&#8201;<SPAN CLASS="cmsy"
>{</SPAN
><VAR CLASS="param"
>local-form</VAR
><SPAN CLASS="cmsy"
>}</SPAN
><SPAN CLASS="cmr"
>*)</SPAN
><SPAN CLASS="cmsy"
>}</SPAN
><SPAN CLASS="cmr"
>*)</SPAN
><BR
><SPAN CLASS="cmsy"
>{</SPAN
><VAR CLASS="param"
>declaration</VAR
><SPAN CLASS="cmsy"
>}</SPAN
><SPAN CLASS="cmr"
>*</SPAN
> <SPAN CLASS="cmsy"
>{</SPAN
><VAR CLASS="param"
>form</VAR
><SPAN CLASS="cmsy"
>}</SPAN
><SPAN CLASS="cmr"
>*</SPAN
></TD
></TR
></TABLE
><DIV
><SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> <SPAN CLASS="cmsy"
>{</SPAN
><VAR CLASS="param"
>result</VAR
><SPAN CLASS="cmsy"
>}</SPAN
><SPAN CLASS="cmr"
>*</SPAN
></DIV
><TABLE CELLPADDING="0" CELLSPACING="0"
><TR
><TD VALIGN="BASELINE" ALIGN="LEFT" NOWRAP="NOWRAP"
><B
>macrolet</B
><SPAN CLASS="cmr"
>&#160;</SPAN
></TD
><TD VALIGN="BASELINE" ALIGN="LEFT"
><SPAN CLASS="cmr"
>(</SPAN
><SPAN CLASS="cmsy"
>{</SPAN
><SPAN CLASS="cmr"
>(</SPAN
><VAR CLASS="param"
>name</VAR
> <VAR CLASS="param"
>lambda-list</VAR
> <SPAN CLASS="cmr"
>&#10214;&#8201;</SPAN
><SPAN CLASS="cmsy"
>{</SPAN
><VAR CLASS="param"
>local-declaration</VAR
><SPAN CLASS="cmsy"
>}</SPAN
><SPAN CLASS="cmr"
>*</SPAN
> <SPAN CLASS="cmsy"
>|</SPAN
> <VAR CLASS="param"
>local-documentation</VAR
>&#8201;<SPAN CLASS="cmr"
>&#8201;&#10215;</SPAN
>&#8201;<SPAN CLASS="cmsy"
>{</SPAN
><VAR CLASS="param"
>local-form</VAR
><SPAN CLASS="cmsy"
>}</SPAN
><SPAN CLASS="cmr"
>*)</SPAN
><SPAN CLASS="cmsy"
>}</SPAN
><SPAN CLASS="cmr"
>*)</SPAN
><BR
><SPAN CLASS="cmsy"
>{</SPAN
><VAR CLASS="param"
>declaration</VAR
><SPAN CLASS="cmsy"
>}</SPAN
><SPAN CLASS="cmr"
>*</SPAN
> <SPAN CLASS="cmsy"
>{</SPAN
><VAR CLASS="param"
>form</VAR
><SPAN CLASS="cmsy"
>}</SPAN
><SPAN CLASS="cmr"
>*</SPAN
></TD
></TR
></TABLE
><DIV
><SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> <SPAN CLASS="cmsy"
>{</SPAN
><VAR CLASS="param"
>result</VAR
><SPAN CLASS="cmsy"
>}</SPAN
><SPAN CLASS="cmr"
>*</SPAN
></DIV
></DD
><DT
><B
>Arguments and Values</B
></DT
><DD
><P CLASS="j"
><VAR CLASS="param"
>function-name</VAR
> &#8212; a <A HREF="26_1_Glossary.html#function_name"
><EM CLASS="term"
>function name</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>name</VAR
> &#8212; a <A HREF="26_1_Glossary.html#symbol"
><EM CLASS="term"
>symbol</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>lambda-list</VAR
> &#8212; a <A HREF="26_1_Glossary.html#lambda_list"
><EM CLASS="term"
>lambda list</EM
></A
>; for <A HREF="f_flet.html" CLASS="specref"
><B
>flet</B
></A
> and <A HREF="f_flet.html" CLASS="specref"
><B
>labels</B
></A
>, it is an <A HREF="26_1_Glossary.html#ordinary_lambda_list"
><EM CLASS="term"
>ordinary lambda list</EM
></A
>; for <A HREF="f_flet.html" CLASS="specref"
><B
>macrolet</B
></A
>, it is a <A HREF="26_1_Glossary.html#macro_lambda_list"
><EM CLASS="term"
>macro lambda list</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>local-declaration</VAR
> &#8212; a <A HREF="m_declare.html" CLASS="misc"
><B
>declare</B
></A
> <A HREF="26_1_Glossary.html#expression"
><EM CLASS="term"
>expression</EM
></A
>; not evaluated. </P
><P CLASS="j"
><VAR CLASS="param"
>declaration</VAR
> &#8212; a <A HREF="m_declare.html" CLASS="misc"
><B
>declare</B
></A
> <A HREF="26_1_Glossary.html#expression"
><EM CLASS="term"
>expression</EM
></A
>; not evaluated. </P
><P CLASS="j"
><VAR CLASS="param"
>local-documentation</VAR
> &#8212; a <A HREF="26_1_Glossary.html#string"
><EM CLASS="term"
>string</EM
></A
>; not evaluated. </P
><P CLASS="j"
><VAR CLASS="param"
>local-forms</VAR
>, <VAR CLASS="param"
>forms</VAR
> &#8212; an <A HREF="26_1_Glossary.html#implicit_progn"
><EM CLASS="term"
>implicit progn</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>results</VAR
> &#8212; the <A HREF="26_1_Glossary.html#value"
><EM CLASS="term"
>values</EM
></A
> of the <VAR CLASS="param"
>forms</VAR
>.</P
></DD
><DT
><B
>Description</B
></DT
><DD
><P CLASS="j"
><A HREF="f_flet.html" CLASS="specref"
><B
>flet</B
></A
>, <A HREF="f_flet.html" CLASS="specref"
><B
>labels</B
></A
>, and <A HREF="f_flet.html" CLASS="specref"
><B
>macrolet</B
></A
> define local <A HREF="26_1_Glossary.html#function"
><EM CLASS="term"
>functions</EM
></A
> and <A HREF="26_1_Glossary.html#macro"
><EM CLASS="term"
>macros</EM
></A
>, and execute <VAR CLASS="param"
>forms</VAR
> using the local definitions. <VAR CLASS="param"
>Forms</VAR
> are executed in order of occurrence. </P
><P CLASS="j"
>The body forms (but not the <A HREF="26_1_Glossary.html#lambda_list"
><EM CLASS="term"
>lambda list</EM
></A
>) of each <A HREF="26_1_Glossary.html#function"
><EM CLASS="term"
>function</EM
></A
> created by <A HREF="f_flet.html" CLASS="specref"
><B
>flet</B
></A
> and <A HREF="f_flet.html" CLASS="specref"
><B
>labels</B
></A
> and each <A HREF="26_1_Glossary.html#macro"
><EM CLASS="term"
>macro</EM
></A
> created by <A HREF="f_flet.html" CLASS="specref"
><B
>macrolet</B
></A
> are enclosed in an <A HREF="26_1_Glossary.html#implicit_block"
><EM CLASS="term"
>implicit block</EM
></A
> whose name is the <A HREF="26_1_Glossary.html#function_block_name"
><EM CLASS="term"
>function block name</EM
></A
> of the <VAR CLASS="param"
>function-name</VAR
> or <VAR CLASS="param"
>name</VAR
>, as appropriate. </P
><P CLASS="j"
>The scope of the <VAR CLASS="param"
>declarations</VAR
> between the list of local function/macro definitions and the body <VAR CLASS="param"
>forms</VAR
> in <A HREF="f_flet.html" CLASS="specref"
><B
>flet</B
></A
> and <A HREF="f_flet.html" CLASS="specref"
><B
>labels</B
></A
> does not include the bodies of the locally defined <A HREF="26_1_Glossary.html#function"
><EM CLASS="term"
>functions</EM
></A
>, except that for <A HREF="f_flet.html" CLASS="specref"
><B
>labels</B
></A
>, any <A HREF="m_inline.html" CLASS="declref"
><B
>inline</B
></A
>, <A HREF="m_inline.html" CLASS="declref"
><B
>notinline</B
></A
>, or <A HREF="m_ftype.html" CLASS="declref"
><B
>ftype</B
></A
> declarations that refer to the locally defined functions do apply to the local function bodies. That is, their <A HREF="26_1_Glossary.html#scope"
><EM CLASS="term"
>scope</EM
></A
> is the same as the function name that they affect. The scope of these <VAR CLASS="param"
>declarations</VAR
> does not include the bodies of the macro expander functions defined by <A HREF="f_flet.html" CLASS="specref"
><B
>macrolet</B
></A
>.</P
><DL
><DT
><B
>flet</B
></DT
><DD
><P CLASS="j"
><A HREF="f_flet.html" CLASS="specref"
><B
>flet</B
></A
> defines locally named <A HREF="26_1_Glossary.html#function"
><EM CLASS="term"
>functions</EM
></A
> and executes a series of <VAR CLASS="param"
>forms</VAR
> with these definition <A HREF="26_1_Glossary.html#binding"
><EM CLASS="term"
>bindings</EM
></A
>. Any number of such local <A HREF="26_1_Glossary.html#function"
><EM CLASS="term"
>functions</EM
></A
> can be defined. </P
><P CLASS="j"
>The <A HREF="26_1_Glossary.html#scope"
><EM CLASS="term"
>scope</EM
></A
> of the name <A HREF="26_1_Glossary.html#binding"
><EM CLASS="term"
>binding</EM
></A
> encompasses only the body. Within the body of <A HREF="f_flet.html" CLASS="specref"
><B
>flet</B
></A
>, <VAR CLASS="param"
>function-names</VAR
> matching those defined by <A HREF="f_flet.html" CLASS="specref"
><B
>flet</B
></A
> refer to the locally defined <A HREF="26_1_Glossary.html#function"
><EM CLASS="term"
>functions</EM
></A
> rather than to the global function definitions of the same name. Also, within the scope of <A HREF="f_flet.html" CLASS="specref"
><B
>flet</B
></A
>, global <A HREF="26_1_Glossary.html#setf_expander"
><EM CLASS="term"
>setf expander</EM
></A
> definitions of the <VAR CLASS="param"
>function-name</VAR
> defined by <A HREF="f_flet.html" CLASS="specref"
><B
>flet</B
></A
> do not apply. Note that this applies to <SPAN CLASS="cmtt"
>(defsetf</SPAN
> <I CLASS="i"
><I
>f</I
></I
> <SPAN CLASS="cmtt"
>...)</SPAN
>, not <SPAN CLASS="cmtt"
>(defmethod</SPAN
> <SPAN CLASS="cmtt"
>(setf</SPAN
> <I CLASS="i"
><I
>f</I
></I
><SPAN CLASS="cmtt"
>)</SPAN
> <SPAN CLASS="cmtt"
>...)</SPAN
>. </P
><P CLASS="j"
>The names of <A HREF="26_1_Glossary.html#function"
><EM CLASS="term"
>functions</EM
></A
> defined by <A HREF="f_flet.html" CLASS="specref"
><B
>flet</B
></A
> are in the <A HREF="26_1_Glossary.html#lexical_environment"
><EM CLASS="term"
>lexical environment</EM
></A
>; they retain their local definitions only within the body of <A HREF="f_flet.html" CLASS="specref"
><B
>flet</B
></A
>. The function definition bindings are visible only in the body of <A HREF="f_flet.html" CLASS="specref"
><B
>flet</B
></A
>, not the definitions themselves. Within the function definitions, local function names that match those being defined refer to <A HREF="26_1_Glossary.html#function"
><EM CLASS="term"
>functions</EM
></A
> or <A HREF="26_1_Glossary.html#macro"
><EM CLASS="term"
>macros</EM
></A
> defined outside the <A HREF="f_flet.html" CLASS="specref"
><B
>flet</B
></A
>. <A HREF="f_flet.html" CLASS="specref"
><B
>flet</B
></A
> can locally <A HREF="26_1_Glossary.html#shadow"
><EM CLASS="term"
>shadow</EM
></A
> a global function name, and the new definition can refer to the global definition. </P
><P CLASS="j"
>Any <VAR CLASS="param"
>local-documentation</VAR
> is attached to the corresponding local <VAR CLASS="param"
>function</VAR
> (if one is actually created) as a <A HREF="26_1_Glossary.html#documentation_string"
><EM CLASS="term"
>documentation string</EM
></A
>.</P
></DD
><DT
><B
>labels</B
></DT
><DD
><P CLASS="j"
><A HREF="f_flet.html" CLASS="specref"
><B
>labels</B
></A
> is equivalent to <A HREF="f_flet.html" CLASS="specref"
><B
>flet</B
></A
> except that the scope of the defined function names for <A HREF="f_flet.html" CLASS="specref"
><B
>labels</B
></A
> encompasses the function definitions themselves as well as the body.</P
></DD
><DT
><B
>macrolet</B
></DT
><DD
><P CLASS="j"
><A HREF="f_flet.html" CLASS="specref"
><B
>macrolet</B
></A
> establishes local <A HREF="26_1_Glossary.html#macro"
><EM CLASS="term"
>macro</EM
></A
> definitions, using the same format used by <A HREF="f_defmacro.html" CLASS="macref"
><B
>defmacro</B
></A
>. </P
><P CLASS="j"
>Within the body of <A HREF="f_flet.html" CLASS="specref"
><B
>macrolet</B
></A
>, global <A HREF="26_1_Glossary.html#setf_expander"
><EM CLASS="term"
>setf expander</EM
></A
> definitions of the <VAR CLASS="param"
>names</VAR
> defined by the <A HREF="f_flet.html" CLASS="specref"
><B
>macrolet</B
></A
> do not apply; rather, <A HREF="f_setf.html" CLASS="macref"
><B
>setf</B
></A
> expands the <A HREF="26_1_Glossary.html#macro_form"
><EM CLASS="term"
>macro form</EM
></A
> and recursively process the resulting <A HREF="26_1_Glossary.html#form"
><EM CLASS="term"
>form</EM
></A
>. </P
><P CLASS="j"
>The macro-expansion functions defined by <A HREF="f_flet.html" CLASS="specref"
><B
>macrolet</B
></A
> are defined in the <A HREF="26_1_Glossary.html#lexical_environment"
><EM CLASS="term"
>lexical environment</EM
></A
> in which the <A HREF="f_flet.html" CLASS="specref"
><B
>macrolet</B
></A
> form appears. Declarations and <A HREF="f_flet.html" CLASS="specref"
><B
>macrolet</B
></A
> and <A HREF="f_symbol-macrolet.html" CLASS="specref"
><B
>symbol-macrolet</B
></A
> definitions affect the local macro definitions in a <A HREF="f_flet.html" CLASS="specref"
><B
>macrolet</B
></A
>, but the consequences are undefined if the local macro definitions reference any local <A HREF="26_1_Glossary.html#variable"
><EM CLASS="term"
>variable</EM
></A
> or <A HREF="26_1_Glossary.html#function"
><EM CLASS="term"
>function</EM
></A
> <A HREF="26_1_Glossary.html#binding"
><EM CLASS="term"
>bindings</EM
></A
> that are visible in that <A HREF="26_1_Glossary.html#lexical_environment"
><EM CLASS="term"
>lexical environment</EM
></A
>. </P
><P CLASS="j"
>Any <VAR CLASS="param"
>local-documentation</VAR
> is attached to the corresponding local <VAR CLASS="param"
>macro function</VAR
> as a <A HREF="26_1_Glossary.html#documentation_string"
><EM CLASS="term"
>documentation string</EM
></A
>.</P
></DD
></DL
></DD
><DT
><B
>Examples</B
></DT
><DD
><PRE CLASS="screen"
>(defun foo (x flag)
(macrolet ((fudge (z)
;The parameters x and flag are not accessible
; at this point; a reference to flag would be to
; the global variable of that name.
`(if flag (* ,z ,z) ,z)))
;The parameters x and flag are accessible here.
(+ x
(fudge x)
(fudge (+ x 1)))))
<SPAN CLASS="cmsy"
><SPAN STYLE="font-size:16px;vertical-align:-2px"
>&#8801;</SPAN
></SPAN
>
(defun foo (x flag)
(+ x
(if flag (* x x) x)
(if flag (* (+ x 1) (+ x 1)) (+ x 1))))</PRE
><P CLASS="j"
>after macro expansion. The occurrences of <CODE CLASS="f"
>x</CODE
> and <CODE CLASS="f"
>flag</CODE
> legitimately refer to the parameters of the function <CODE CLASS="f"
>foo</CODE
> because those parameters are visible at the site of the macro call which produced the expansion.</P
><PRE CLASS="screen"
> (flet ((flet1 (n) (+ n n)))
(flet ((flet1 (n) (+ 2 (flet1 n))))
(flet1 2))) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 6
(defun dummy-function () 'top-level) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> DUMMY-FUNCTION
(funcall #'dummy-function) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> TOP-LEVEL
(flet ((dummy-function () 'shadow))
(funcall #'dummy-function)) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> SHADOW
(eq (funcall #'dummy-function) (funcall 'dummy-function))
<SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> <A HREF="26_1_Glossary.html#true"
><EM CLASS="term"
>true</EM
></A
>
(flet ((dummy-function () 'shadow))
(eq (funcall #'dummy-function)
(funcall 'dummy-function)))
<SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> <A HREF="26_1_Glossary.html#false"
><EM CLASS="term"
>false</EM
></A
>
(defun recursive-times (k n)
(labels ((temp (n)
(if (zerop n) 0 (+ k (temp (1- n))))))
(temp n))) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> RECURSIVE-TIMES
(recursive-times 2 3) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 6
(defmacro mlets (x &amp;environment env)
(let ((form `(babbit ,x)))
(macroexpand form env))) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> MLETS
(macrolet ((babbit (z) `(+ ,z ,z))) (mlets 5)) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 10</PRE
><PRE CLASS="screen"
> (flet ((safesqrt (x) (sqrt (abs x))))
;; The safesqrt function is used in two places.
(safesqrt (apply #'+ (map 'list #'safesqrt '(1 2 3 4 5 6)))))
<SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 3.291173</PRE
><PRE CLASS="screen"
>(defun integer-power (n k)
(declare (integer n))
(declare (type (integer 0 *) k))
(labels ((expt0 (x k a)
(declare (integer x a) (type (integer 0 *) k))
(cond ((zerop k) a)
((evenp k) (expt1 (* x x) (floor k 2) a))
(t (expt0 (* x x) (floor k 2) (* x a)))))
(expt1 (x k a)
(declare (integer x a) (type (integer 0 *) k))
(cond ((evenp k) (expt1 (* x x) (floor k 2) a))
(t (expt0 (* x x) (floor k 2) (* x a))))))
(expt0 n k 1))) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> INTEGER-POWER</PRE
><PRE CLASS="screen"
> (defun example (y l)
(flet ((attach (x)
(setq l (append l (list x)))))
(declare (inline attach))
(dolist (x y)
(unless (null (cdr x))
(attach x)))
l))
(example '((a apple apricot) (b banana) (c cherry) (d) (e))
'((1) (2) (3) (4 2) (5) (6 3 2)))
<SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> ((1) (2) (3) (4 2) (5) (6 3 2) (A APPLE APRICOT) (B BANANA) (C CHERRY))</PRE
></DD
><DT
><B
>See Also</B
></DT
><DD
><P CLASS="j"
><A HREF="m_declare.html" CLASS="misc"
><B
>declare</B
></A
>, <A HREF="f_defmacro.html" CLASS="macref"
><B
>defmacro</B
></A
>, <A HREF="f_defun.html" CLASS="macref"
><B
>defun</B
></A
>, <A HREF="f_documentation.html" CLASS="funref"
><B
>documentation</B
></A
>, <A HREF="f_let.html" CLASS="specref"
><B
>let</B
></A
>, <A HREF="3_1_Evaluation.html#sec_3_1" CLASS="secref"
><SPAN CLASS="cmr"
>Section</SPAN
> <SPAN CLASS="cmr"
>3.1</SPAN
> <SPAN CLASS="cmr"
>(Evaluation)</SPAN
></A
>, <A HREF="3_4_Lambda_Lists.html#sec_3_4_11" CLASS="secref"
><SPAN CLASS="cmr"
>Section</SPAN
> <SPAN CLASS="cmr"
>3.4.11</SPAN
> <SPAN CLASS="cmr"
>(Syntactic</SPAN
> <SPAN CLASS="cmr"
>Interaction</SPAN
> <SPAN CLASS="cmr"
>of</SPAN
> <SPAN CLASS="cmr"
>Documentation</SPAN
> <SPAN CLASS="cmr"
>Strings</SPAN
> <SPAN CLASS="cmr"
>and</SPAN
> <SPAN CLASS="cmr"
>Declarations)</SPAN
></A
></P
></DD
><DT
><B
>Notes</B
></DT
><DD
><P CLASS="j"
>It is not possible to define recursive <A HREF="26_1_Glossary.html#function"
><EM CLASS="term"
>functions</EM
></A
> with <A HREF="f_flet.html" CLASS="specref"
><B
>flet</B
></A
>. <A HREF="f_flet.html" CLASS="specref"
><B
>labels</B
></A
> can be used to define mutually recursive <A HREF="26_1_Glossary.html#function"
><EM CLASS="term"
>functions</EM
></A
>. </P
><P CLASS="j"
>If a <A HREF="f_flet.html" CLASS="specref"
><B
>macrolet</B
></A
> <A HREF="26_1_Glossary.html#form"
><EM CLASS="term"
>form</EM
></A
> is a <A HREF="26_1_Glossary.html#top_level_form"
><EM CLASS="term"
>top level form</EM
></A
>, the body <VAR CLASS="param"
>forms</VAR
> are also processed as <A HREF="26_1_Glossary.html#top_level_form"
><EM CLASS="term"
>top level forms</EM
></A
>. See <A HREF="3_2_Compilation.html#sec_3_2_3" CLASS="secref"
><SPAN CLASS="cmr"
>Section</SPAN
> <SPAN CLASS="cmr"
>3.2.3</SPAN
> <SPAN CLASS="cmr"
>(File</SPAN
> <SPAN CLASS="cmr"
>Compilation)</SPAN
></A
>.</P
></DD
></DL
></DIV
></DIV
><DIV CLASS="footer"
><DIV CLASS="btmnav"
><A HREF="f_fmakunbound.html" CLASS="prev"
>&#8592;</A
><A HREF="f_funcall.html" CLASS="next"
>&#8594;</A
></DIV
><DIV CLASS="trail"
>Conversion to HTML copyright 2023 by Gilbert Baumann</DIV
></DIV
></DIV
><SCRIPT
>domReady();</SCRIPT
></BODY
></HTML
>