In mathematics and computer science, Apply is a function that applies functions to arguments. It is a central concept in programming languages derived from lambda calculus, such as LISP and Scheme, and also in functional languages. In particular, it has a role in the study of the denotational semantics of computer programs, by virtue of the fact that it is a continuous function on complete partial orders.
In Common Lisp apply is a function that applies a function to a list of arguments (note here that "+" is a variadic function that takes any number of arguments):
Similarly in Scheme:
In C# and Java, variadic arguments are simply collected in an array; you can explicitly pass in an array in place of the variadic arguments:
apply method, the first argument is the value of the
this keyword inside the function; the second is the list of arguments:
In Perl, lists and hashes are automatically "flattened" when inserted into a list environment, such as an argument list of a function:
apply is called
In Python and Ruby, you use the same asterisk notation used in defining variadic functions to call a function on a sequence:
or, equivalently one has the commuting diagram
The notation for the space of functions from A to B occurs more commonly in computer science. In category theory, however, is known as the exponential object, and is written as . There are other common notational differences as well; for example Apply is often called Eval, even though in computer science, these are not the same thing, with eval distinguished from Apply, as being the evaluation of the quoted string form of a function with its arguments, rather than the application of a function to some arguments.
Also, in category theory, curry is commonly denoted by , so that is written for curry(g). This notation is in conflict with the use of in lambda calculus, where lambda is used to denote free variables. With all of these notational changes accounted for, the adjointness of Apply and curry is then expressed in the commuting diagram
The articles on exponential object and Cartesian closed category provide a more precise discussion of the category-theoretic formulation of this idea. Thus use of lambda here is not accidental; Cartesian close categories provide the general, natural setting for lambda calculus.