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

330 lines
6.7 KiB
HTML
Raw Normal View History

2025-02-05 18:52:26 +01:00
<!DOCTYPE HTML>
<HTML LANG="en-us"
><HEAD
><TITLE
>funcall | Common Lisp Nova Spec</TITLE
><META CHARSET="US-ASCII"
><LINK REL="canonical" HREF="f_funcall.html"
><LINK REL="next" HREF="f_function.html" TYPE="text/html" TITLE="function"
><LINK REL="prev" HREF="f_flet.html" TYPE="text/html" TITLE="flet, labels, macrolet"
><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_funcall.html"
>funcall</A
></SPAN
></DIV
><DIV CLASS="apropos"
><DIV CLASS="apropos-io"
><A HREF="f_flet.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_function.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="funcall"
></SPAN
><B
>funcall</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
>funcall</B
> <SPAN CLASS="cmssi"
>function</SPAN
> <SPAN CLASS="cmtt"
>&amp;rest</SPAN
> <SPAN CLASS="cmssi"
>args</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"
>function</VAR
> &#8212; a <A HREF="26_1_Glossary.html#function_designator"
><EM CLASS="term"
>function designator</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>args</VAR
> &#8212; <A HREF="26_1_Glossary.html#argument"
><EM CLASS="term"
>arguments</EM
></A
> to the <VAR CLASS="param"
>function</VAR
>. </P
><P CLASS="j"
><VAR CLASS="param"
>results</VAR
> &#8212; the <A HREF="26_1_Glossary.html#value"
><EM CLASS="term"
>values</EM
></A
> returned by the <VAR CLASS="param"
>function</VAR
>.</P
></DD
><DT
><B
>Description</B
></DT
><DD
><P CLASS="j"
><A HREF="f_funcall.html" CLASS="funref"
><B
>funcall</B
></A
> applies <VAR CLASS="param"
>function</VAR
> to <VAR CLASS="param"
>args</VAR
>. If <VAR CLASS="param"
>function</VAR
> is a <A HREF="26_1_Glossary.html#symbol"
><EM CLASS="term"
>symbol</EM
></A
>, it is coerced to a <A HREF="26_1_Glossary.html#function"
><EM CLASS="term"
>function</EM
></A
> as if by finding its <A HREF="26_1_Glossary.html#functional_value"
><EM CLASS="term"
>functional value</EM
></A
> in the <A HREF="26_1_Glossary.html#global_environment"
><EM CLASS="term"
>global environment</EM
></A
>.</P
></DD
><DT
><B
>Examples</B
></DT
><DD
><PRE CLASS="screen"
> (funcall #'+ 1 2 3) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 6
(funcall 'car '(1 2 3)) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 1
(funcall 'position 1 '(1 2 3 2 1) :start 1) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 4
(cons 1 2) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> (1 . 2)
(flet ((cons (x y) `(kons ,x ,y)))
(let ((cons (symbol-function '+)))
(funcall #'cons
(funcall 'cons 1 2)
(funcall cons 1 2))))
<SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> (KONS (1 . 2) 3)</PRE
></DD
><DT
><B
>Exceptional Situations</B
></DT
><DD
><P CLASS="j"
>An error of <A HREF="26_1_Glossary.html#type"
><EM CLASS="term"
>type</EM
></A
> <A HREF="t_undefined-function.html" CLASS="typeref"
><B
>undefined-function</B
></A
> should be signaled if <VAR CLASS="param"
>function</VAR
> is a <A HREF="26_1_Glossary.html#symbol"
><EM CLASS="term"
>symbol</EM
></A
> that does not have a global definition as a <A HREF="26_1_Glossary.html#function"
><EM CLASS="term"
>function</EM
></A
> or that has a global definition as a <A HREF="26_1_Glossary.html#macro"
><EM CLASS="term"
>macro</EM
></A
> or a <A HREF="26_1_Glossary.html#special_operator"
><EM CLASS="term"
>special operator</EM
></A
>.</P
></DD
><DT
><B
>See Also</B
></DT
><DD
><P CLASS="j"
><A HREF="f_apply.html" CLASS="funref"
><B
>apply</B
></A
>, <A HREF="f_function.html" CLASS="specref"
><B
>function</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
></P
></DD
><DT
><B
>Notes</B
></DT
><DD
><PRE CLASS="screen"
>(funcall <VAR CLASS="param"
>function</VAR
> <VAR CLASS="param"
>arg1</VAR
> <VAR CLASS="param"
>arg2</VAR
> ...)
<SPAN CLASS="cmsy"
><SPAN STYLE="font-size:16px;vertical-align:-2px"
>&#8801;</SPAN
></SPAN
> (apply <VAR CLASS="param"
>function</VAR
> <VAR CLASS="param"
>arg1</VAR
> <VAR CLASS="param"
>arg2</VAR
> ... nil)
<SPAN CLASS="cmsy"
><SPAN STYLE="font-size:16px;vertical-align:-2px"
>&#8801;</SPAN
></SPAN
> (apply <VAR CLASS="param"
>function</VAR
> (list <VAR CLASS="param"
>arg1</VAR
> <VAR CLASS="param"
>arg2</VAR
> ...))</PRE
><P CLASS="j"
>The difference between <A HREF="f_funcall.html" CLASS="funref"
><B
>funcall</B
></A
> and an ordinary function call is that in the former case the <VAR CLASS="param"
>function</VAR
> is obtained by ordinary <A HREF="26_1_Glossary.html#evaluation"
><EM CLASS="term"
>evaluation</EM
></A
> of a <A HREF="26_1_Glossary.html#form"
><EM CLASS="term"
>form</EM
></A
>, and in the latter case it is obtained by the special interpretation of the function position that normally occurs.</P
></DD
></DL
></DIV
></DIV
><DIV CLASS="footer"
><DIV CLASS="btmnav"
><A HREF="f_flet.html" CLASS="prev"
>&#8592;</A
><A HREF="f_function.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
>