Function: function
function is a special form defined in eval.c.
Signature
(function ARG)
Documentation
Like quote, but preferred for objects which are functions.
In byte compilation, function causes its argument to be handled by
the byte compiler. Similarly, when expanding macros and expressions,
ARG can be examined and possibly expanded. If quote is used
instead, this doesn't happen.
Probably introduced at or before Emacs version 1.4.
Source Code
// Defined in /usr/src/emacs/src/eval.c
{
Lisp_Object quoted = XCAR (args);
if (!NILP (XCDR (args)))
xsignal2 (Qwrong_number_of_arguments, Qfunction, Flength (args));
if (CONSP (quoted)
&& EQ (XCAR (quoted), Qlambda))
{ /* This is a lambda expression within a lexical environment;
return an interpreted closure instead of a simple lambda. */
Lisp_Object cdr = XCDR (quoted);
Lisp_Object args = Fcar (cdr);
cdr = Fcdr (cdr);
Lisp_Object docstring = Qnil, iform = Qnil;
if (CONSP (cdr))
{
docstring = XCAR (cdr);
if (STRINGP (docstring))
{
Lisp_Object tmp = XCDR (cdr);
if (!NILP (tmp))
cdr = tmp;
else /* It's not a docstring, it's a return value. */
docstring = Qnil;
}
/* Handle the special (:documentation <form>) to build the docstring
dynamically. */
else if (CONSP (docstring)
&& EQ (QCdocumentation, XCAR (docstring))
&& (docstring = eval_sub (Fcar (XCDR (docstring))),
true))
cdr = XCDR (cdr);
else
docstring = Qnil; /* Not a docstring after all. */
}
if (CONSP (cdr))
{
iform = XCAR (cdr);
if (CONSP (iform)
&& EQ (Qinteractive, XCAR (iform)))
cdr = XCDR (cdr);
else
iform = Qnil; /* Not an interactive-form after all. */
}
if (NILP (cdr))
cdr = Fcons (Qnil, Qnil); /* Make sure the body is never empty! */
if (NILP (Vinternal_interpreter_environment)
|| NILP (Vinternal_make_interpreted_closure_function))
return Fmake_interpreted_closure
(args, cdr, Vinternal_interpreter_environment, docstring, iform);
else
return call5 (Vinternal_make_interpreted_closure_function,
args, cdr, Vinternal_interpreter_environment,
docstring, iform);
}
else
/* Simply quote the argument. */
return quoted;
}