1
0
Fork 0
cl-sites/novaspec.org/cl/f_eval.html
2025-02-05 18:52:26 +01:00

385 lines
No EOL
7.9 KiB
HTML

<!DOCTYPE HTML>
<HTML LANG="en-us"
><HEAD
><TITLE
>eval | Common Lisp Nova Spec</TITLE
><META CHARSET="US-ASCII"
><LINK REL="canonical" HREF="f_eval.html"
><LINK REL="next" HREF="f_eval-when.html" TYPE="text/html" TITLE="eval-when"
><LINK REL="prev" HREF="f_compile.html" TYPE="text/html" TITLE="compile"
><LINK REL="up" HREF="3_8_Evaluation_and_Compilation_Dictionary.html" TYPE="text/html" TITLE="3.8 Evaluation and Compilation 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="3_Evaluation_and_Compilation.html"
>3. Evaluation and Compilation</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="3_8_Evaluation_and_Compilation_Dictionary.html"
>3.8 Evaluation and Compilation Dictionary</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="f_eval.html"
>eval</A
></SPAN
></DIV
><DIV CLASS="apropos"
><DIV CLASS="apropos-io"
><A HREF="f_compile.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_eval-when.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="eval"
></SPAN
><B
>eval</B
></TD
><TD ALIGN="RIGHT" VALIGN="BASELINE" WIDTH="0" NOWRAP="NOWRAP" CLASS="ftype"
><I
>Function</I
></TD
></TR
></TABLE
><HR
></DIV
><UL CLASS="subtoc"
></UL
><DL
><DT
><B
>Syntax</B
></DT
><DD
><P CLASS="j"
><B
>eval</B
> <SPAN CLASS="cmssi"
>form</SPAN
> <SPAN CLASS="arrow"
>&#8594;</SPAN
> {<VAR CLASS="param"
>result</VAR
>}*</P
></DD
><DT
><B
>Arguments and Values</B
></DT
><DD
><P CLASS="j"
><VAR CLASS="param"
>form</VAR
> &#8212; a <A HREF="26_1_Glossary.html#form"
><EM CLASS="term"
>form</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
> <A HREF="26_1_Glossary.html#yield"
><EM CLASS="term"
>yielded</EM
></A
> by the <A HREF="26_1_Glossary.html#evaluation"
><EM CLASS="term"
>evaluation</EM
></A
> of <VAR CLASS="param"
>form</VAR
>.</P
></DD
><DT
><B
>Description</B
></DT
><DD
><P CLASS="j"
>Evaluates <VAR CLASS="param"
>form</VAR
> in the current <A HREF="26_1_Glossary.html#dynamic_environment"
><EM CLASS="term"
>dynamic environment</EM
></A
> and the <A HREF="26_1_Glossary.html#null_lexical_environment"
><EM CLASS="term"
>null lexical environment</EM
></A
>. </P
><P CLASS="j"
><A HREF="f_eval.html" CLASS="funref"
><B
>eval</B
></A
> is a user interface to the evaluator. </P
><P CLASS="j"
>The evaluator expands macro calls as if through the use of <A HREF="f_macroexpand.html" CLASS="funref"
><B
>macroexpand-1</B
></A
>. </P
><P CLASS="j"
>Constants appearing in code processed by <A HREF="f_eval.html" CLASS="funref"
><B
>eval</B
></A
> are not copied nor coalesced. The code resulting from the execution of <A HREF="f_eval.html" CLASS="funref"
><B
>eval</B
></A
> references <A HREF="26_1_Glossary.html#object"
><EM CLASS="term"
>objects</EM
></A
> that are <A HREF="f_eql.html" CLASS="funref"
><B
>eql</B
></A
> to the corresponding <A HREF="26_1_Glossary.html#object"
><EM CLASS="term"
>objects</EM
></A
> in the source code.</P
></DD
><DT
><B
>Examples</B
></DT
><DD
><PRE CLASS="screen"
> (setq form '(1+ a) a 999) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 999
(eval form) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 1000
(eval 'form) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> (1+ A)
(let ((a '(this would break if eval used local value))) (eval form))
<SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 1000</PRE
></DD
><DT
><B
>See Also</B
></DT
><DD
><P CLASS="j"
><A HREF="f_macroexpand.html" CLASS="funref"
><B
>macroexpand-1</B
></A
>, <A HREF="3_1_Evaluation.html#sec_3_1_2" CLASS="secref"
><SPAN CLASS="cmr"
>Section</SPAN
> <SPAN CLASS="cmr"
>3.1.2</SPAN
> <SPAN CLASS="cmr"
>(The</SPAN
> <SPAN CLASS="cmr"
>Evaluation</SPAN
> <SPAN CLASS="cmr"
>Model)</SPAN
></A
></P
></DD
><DT
><B
>Notes</B
></DT
><DD
><P CLASS="j"
>To obtain the current dynamic value of a <A HREF="26_1_Glossary.html#symbol"
><EM CLASS="term"
>symbol</EM
></A
>, use of <A HREF="f_symbol-value.html" CLASS="funref"
><B
>symbol-value</B
></A
> is equivalent (and usually preferable) to use of <A HREF="f_eval.html" CLASS="funref"
><B
>eval</B
></A
>. </P
><P CLASS="j"
>Note that an <A HREF="f_eval.html" CLASS="funref"
><B
>eval</B
></A
> <A HREF="26_1_Glossary.html#form"
><EM CLASS="term"
>form</EM
></A
> involves two levels of <A HREF="26_1_Glossary.html#evaluation"
><EM CLASS="term"
>evaluation</EM
></A
> for its <A HREF="26_1_Glossary.html#argument"
><EM CLASS="term"
>argument</EM
></A
>. First, <VAR CLASS="param"
>form</VAR
> is <A HREF="26_1_Glossary.html#evaluate"
><EM CLASS="term"
>evaluated</EM
></A
> by the normal argument evaluation mechanism as would occur with any <A HREF="26_1_Glossary.html#call"
><EM CLASS="term"
>call</EM
></A
>. The <A HREF="26_1_Glossary.html#object"
><EM CLASS="term"
>object</EM
></A
> that results from this normal <A HREF="26_1_Glossary.html#argument"
><EM CLASS="term"
>argument</EM
></A
> <A HREF="26_1_Glossary.html#evaluation"
><EM CLASS="term"
>evaluation</EM
></A
> becomes the <A HREF="26_1_Glossary.html#value"
><EM CLASS="term"
>value</EM
></A
> of the <VAR CLASS="param"
>form</VAR
> <A HREF="26_1_Glossary.html#parameter"
><EM CLASS="term"
>parameter</EM
></A
>, and is then <A HREF="26_1_Glossary.html#evaluate"
><EM CLASS="term"
>evaluated</EM
></A
> as part of the <A HREF="f_eval.html" CLASS="funref"
><B
>eval</B
></A
> <A HREF="26_1_Glossary.html#form"
><EM CLASS="term"
>form</EM
></A
>. For example:</P
><PRE CLASS="screen"
>(eval (list 'cdr (car '((quote (a . b)) c)))) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> b</PRE
><P CLASS="j"
>The <A HREF="26_1_Glossary.html#argument"
><EM CLASS="term"
>argument</EM
></A
> <A HREF="26_1_Glossary.html#form"
><EM CLASS="term"
>form</EM
></A
> <CODE CLASS="f"
>(list 'cdr (car '((quote (a . b)) c)))</CODE
> is evaluated in the usual way to produce the <A HREF="26_1_Glossary.html#argument"
><EM CLASS="term"
>argument</EM
></A
> <CODE CLASS="f"
>(cdr (quote (a . b)))</CODE
>; <A HREF="f_eval.html" CLASS="funref"
><B
>eval</B
></A
> then evaluates its <A HREF="26_1_Glossary.html#argument"
><EM CLASS="term"
>argument</EM
></A
>, <CODE CLASS="f"
>(cdr (quote (a . b)))</CODE
>, to produce <CODE CLASS="f"
>b</CODE
>. Since a single <A HREF="26_1_Glossary.html#evaluation"
><EM CLASS="term"
>evaluation</EM
></A
> already occurs for any <A HREF="26_1_Glossary.html#argument"
><EM CLASS="term"
>argument</EM
></A
> <A HREF="26_1_Glossary.html#form"
><EM CLASS="term"
>form</EM
></A
> in any <A HREF="26_1_Glossary.html#function_form"
><EM CLASS="term"
>function form</EM
></A
>, <A HREF="f_eval.html" CLASS="funref"
><B
>eval</B
></A
> is sometimes said to perform &#8220;an extra level of evaluation.&#8221;</P
></DD
></DL
></DIV
></DIV
><DIV CLASS="footer"
><DIV CLASS="btmnav"
><A HREF="f_compile.html" CLASS="prev"
>&#8592;</A
><A HREF="f_eval-when.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
>