Applying functionals

  One of the basic types of functionals are functions which allow to cause other functions, otherwise, to apply functional argument to its parameters. Such functionals name applying or applicative functionals.
  Applying functionals are related universal Lisp function eval. While eval calculates value of the any expression (form), applying functional calculates value of a call of some function. Lisp interpreter eval and actually causes applying functional apply at calculation of a call, and apply in turn causes eval at calculation of value of other forms.
  Applying functionals enable to interpret and transform data to the program and to apply it in calculations.

APPLY applies function to the list of arguments

  apply is (in the initial form) function of two arguments from which the first argument represents function which is applied to the elements of the list making the second argument of function apply:

  (nil apply obj fn list)
  ≡
  (obj fn 'x1 'x2 … 'xn),

  where list=(x1 x2 … xn)

>(nil apply 2 '+ '(3))
5
>(nil apply nil 'cons '(that (will wish)))
(that will wish)
>('f set '+)
+
>(nil apply 2 f '(3))
5
>(nil apply nil 'eval '((2 + 3)))
5
>(nil apply nil 'apply '(2 + (3)))
; apply applies itself
5
>(nil apply nil '(lambda (x y) (x + y)) '(2 3))
5

  Use apply gives greater flexibility in comparison with a direct call of function: by means of the same functions apply it is possible to carry out various calculations depending on functional argument.

FUNCALL causes function with arguments

  Functional funcall on the action it is similar apply, but for caused function it accepts arguments not the list, and separately:

  (nil funcall obj fn x1 x2 … xn)
  ≡
  (obj fn x1 x2 … xn)

  Let's give an example:

>(nil funcall 2 '+ 3)
5

   funcall and apply allow to set calculations (function) by the any form, for example, as in a call of function, or a symbol which value is the functional object. In an ordinary call of function it is possible to use only a symbol connected defmethod with lambda-expression. Interpretation of a name depends on a syntactic position.

>('addition set '+)
+
>(nil funcall 2 addition 3)
5
>(nil funcall 2 ('(+ - * /) first) 3)
5

  Thus there is an opportunity to use synonyms of a name of function. On the other hand, the name of function can be used as an ordinary variable, for example for storage of other function (a name or lambda-expression), and these two senses (value and definition) will not stir each other:

>('cons set '+)
+
>(nil funcall 2 cons 3)
5
>(nil cons 2 3)
(2 . 3)

  As the second functionals argument funcall is calculated by ordinary rules on its place there should be an expression which value will be a symbol or lambda-expression.