Next: Macros, Previous: Variables, Up: The language [Contents][Index]
A function is a Lisp object which, when applied to a sequence of argument values, produces another value—the function’s result. It may also induce side-effects (e.g. changing the environment of the calling function). All Lisp functions return results — there is nothing like a procedure in Pascal.
Note that special forms (see Special Forms) and macros (see Macros) are not functions since they do not guarantee to evaluate all of their arguments.
Functions are the main building-block in Lisp programs, each program is usually a system of interrelated functions.
There are two types of function: primitive functions are functions written in the C language, these are sometimes called built-in functions, the object containing the C code itself is called a subr. All other functions are defined in Lisp.
Returns true if object is a function (i.e. it can be used
as the function argument of funcall.
(functionp set) ;; set is a subr
⇒ t
(functionp setq) ;; setq is a special-form, so not a function
⇒ ()
(functionp (lambda (x) (+ x 2))) ;; a closure is a function
⇒ t
Return’s the name of the function arg (a symbol). For an anonymous closure, it’ll be nil.
Returns true is arg is a primitive subroutine object. This includes special forms.
Returns a string naming the primitive subroutine subr.
| • Lambda Expressions: | Structure of a function object | |
| • Closures: | Function core | |
| • Defining Named Functions: | Usual way of function definition | |
| • Predicate Functions: | Functions which return boolean values | |
| • Local Functions: | Binding functions temporarily | |
| • Calling Functions: | Functions can be called by hand | |
| • Mapping Functions: | Map a function to the elements of a list |
Next: Macros, Previous: Variables, Up: The language [Contents][Index]