Next: , Previous: , Up: The language   [Contents][Index]

5.9 Functions

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.

Function: functionp object

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
Function: function-name arg

Return’s the name of the function arg (a symbol). For an anonymous closure, it’ll be nil.

Function: subrp arg

Returns true is arg is a primitive subroutine object. This includes special forms.

Function: subr-name subr

Returns a string naming the primitive subroutine subr.

Next: , Previous: , Up: The language   [Contents][Index]