GNU Info

Info Node: (librep.info)Anonymous Functions

(librep.info)Anonymous Functions


Next: Predicate Functions Prev: Defining Functions Up: Functions
Enter node , (file) or (file)node

Anonymous Functions
-------------------

   When supplying functions as arguments to other functions it is often
useful to give an actual function _definition_ (i.e. an enclosed lambda
expression) instead of the name of a function.

   In Lisp, unlike most other programming languages, functions have no
inherent name. As seen in the last section named-functions are created
by storing a function object in a variable, if you want, a function can
have many different names: simply store the function in many different
variables!

   So, when you want to pass a function as an argument there is the
option of just writing down its definition. This is especially useful
with functions like `mapc' and `delete-if'. For example, the following
form removes all elements from the LIST which are even and greater than
20.

     (setq LIST (delete-if (lambda (x)
                             (and (zerop (% x 2)) (> x 20)))
                           LIST))

   The above lambda expression combines two predicates applied to its
argument.

   In certain cases it may be necessary to create a non-constant
function, for example by using backquoting (Note: Backquoting). In
these cases the `make-closure' function may be used to create a function
object from a lambda expression.

 - Function: make-closure arg
     Return the closure of ARG and the current lexical environment.

 - Function: closurep arg
     Returns true if ARG is a closure.

 - Function: closure-function closure
     Returns the function object associated with the lexical closure
     CLOSURE.


automatically generated by info2www version 1.2.2.9