Copyright (C) 2000-2012 |
GNU Info (elisp)What Is a FunctionWhat Is a Function? =================== In a general sense, a function is a rule for carrying on a computation given several values called "arguments". The result of the computation is called the value of the function. The computation can also have side effects: lasting changes in the values of variables or the contents of data structures. Here are important terms for functions in Emacs Lisp and for other function-like objects. "function" In Emacs Lisp, a "function" is anything that can be applied to arguments in a Lisp program. In some cases, we use it more specifically to mean a function written in Lisp. Special forms and macros are not functions. "primitive" A "primitive" is a function callable from Lisp that is written in C, such as `car' or `append'. These functions are also called "built-in" functions or "subrs". (Special forms are also considered primitives.) Usually the reason we implement a function as a primitive is either because it is fundamental, because it provides a low-level interface to operating system services, or because it needs to run fast. Primitives can be modified or added only by changing the C sources and recompiling the editor. See Note: Writing Emacs Primitives. "lambda expression" A "lambda expression" is a function written in Lisp. These are described in the following section. Note: Lambda Expressions. "special form" A "special form" is a primitive that is like a function but does not evaluate all of its arguments in the usual way. It may evaluate only some of the arguments, or may evaluate them in an unusual order, or several times. Many special forms are described in Note: Control Structures. "macro" A "macro" is a construct defined in Lisp by the programmer. It differs from a function in that it translates a Lisp expression that you write into an equivalent expression to be evaluated instead of the original expression. Macros enable Lisp programmers to do the sorts of things that special forms can do. Note: Macros, for how to define and use macros. "command" A "command" is an object that `command-execute' can invoke; it is a possible definition for a key sequence. Some functions are commands; a function written in Lisp is a command if it contains an interactive declaration (Note: Defining Commands). Such a function can be called from Lisp expressions like other functions; in this case, the fact that the function is a command makes no difference. Keyboard macros (strings and vectors) are commands also, even though they are not functions. A symbol is a command if its function definition is a command; such symbols can be invoked with `M-x'. The symbol is a function as well if the definition is a function. Note: Command Overview. "keystroke command" A "keystroke command" is a command that is bound to a key sequence (typically one to three keystrokes). The distinction is made here merely to avoid confusion with the meaning of "command" in non-Emacs editors; for Lisp programs, the distinction is normally unimportant. "byte-code function" A "byte-code function" is a function that has been compiled by the byte compiler. Note: Byte-Code Type. - Function: functionp object This function returns `t' if OBJECT is any kind of function, or a special form or macro. - Function: subrp object This function returns `t' if OBJECT is a built-in function (i.e., a Lisp primitive). (subrp 'message) ; `message' is a symbol, => nil ; not a subr object. (subrp (symbol-function 'message)) => t - Function: byte-code-function-p object This function returns `t' if OBJECT is a byte-code function. For example: (byte-code-function-p (symbol-function 'next-line)) => t - Function: subr-arity subr This function provides information about the argument list of a primitive, SUBR. The returned value is a pair `(MIN . MAX)'. MIN is the minimum number of args. MAX is the maximum number or the symbol `many', for a function with `&rest' arguments, or the symbol `unevalled' if SUBR is a special form. automatically generated by info2www version 1.2.2.9 |