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.

View in manual

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 (!NILP (Vinternal_interpreter_environment)
      && 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 tmp = cdr;
      if (CONSP (tmp)
	  && (tmp = XCDR (tmp), CONSP (tmp))
	  && (tmp = XCAR (tmp), CONSP (tmp))
	  && (EQ (QCdocumentation, XCAR (tmp))))
	{ /* Handle the special (:documentation <form>) to build the docstring
	     dynamically.  */
	  Lisp_Object docstring = eval_sub (Fcar (XCDR (tmp)));
	  if (SYMBOLP (docstring) && !NILP (docstring))
	    /* Hack for OClosures: Allow the docstring to be a symbol
             * (the OClosure's type).  */
	    docstring = Fsymbol_name (docstring);
	  CHECK_STRING (docstring);
	  cdr = Fcons (XCAR (cdr), Fcons (docstring, XCDR (XCDR (cdr))));
	}
      if (NILP (Vinternal_make_interpreted_closure_function))
        return Fcons (Qclosure, Fcons (Vinternal_interpreter_environment, cdr));
      else
        return call2 (Vinternal_make_interpreted_closure_function,
                      Fcons (Qlambda, cdr),
                      Vinternal_interpreter_environment);
    }
  else
    /* Simply quote the argument.  */
    return quoted;
}