Definitions
Nearby Words

# Apply

[uh-plahy]

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 category theory, Apply is important in Cartesian closed categories, (and thus, also in Topos theory), where it is a universal morphism, right adjoint to currying.

## Programming

In computer programing, apply applies a function to a list of arguments. Eval and apply are the two interdependent components of the eval-apply cycle, which is the essence of evaluating Lisp, described in SICP.

### Apply function

Apply is also the name of a special function in many languages, which takes a function and a list, and uses the list as the function's own argument list, as if the function was called with the elements of the list as the arguments. This is important in languages with variadic functions, because this is the only way to call a function with an indeterminate (at compile time) number of arguments.

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):(apply #'+ (list 1 2)) Similarly in Scheme:(apply + (list 1 2)) 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:variadicFunc(arrayOfArgs); In JavaScript, function objects have an `apply` method, the first argument is the value of the `this` keyword inside the function; the second is the list of arguments:func.apply(null, args); In Perl, lists and hashes are automatically "flattened" when inserted into a list environment, such as an argument list of a function:func(@args); In PHP, `apply` is called `call_user_func_array`:call_user_func_array('func_name', \$args); In Python and Ruby, you use the same asterisk notation used in defining variadic functions to call a function on a sequence:func(*args)

## Universal property

Consider a function $g:Xtimes Yto Z$, that is, $gisin \left[Xtimes Yto Z\right]$ where the bracket notation $\left[Ato B\right]$ denotes the space of functions from A to B. By means of currying, there is a unique function $mbox\left\{curry\right\}\left(g\right) :Xto \left[Yto Z\right]$. Then Apply provides the universal morphism

$mbox\left\{Apply\right\}:\left[Yto Z\right]times Y to Z$,

so that

$mbox \left\{Apply\right\}\left(f,y\right)=f\left(y\right)$

or, equivalently one has the commuting diagram

$mbox\left\{Apply\right\} circ left\left(mbox\left\{curry\right\}\left(g\right) times mbox\left\{id\right\}_Y right\right) = g$

The notation $\left[Ato B\right]$ for the space of functions from A to B occurs more commonly in computer science. In category theory, however, $\left[Ato B\right]$ is known as the exponential object, and is written as $B^A$. 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 $lambda$, so that $lambda g$ is written for curry(g). This notation is in conflict with the use of $lambda$ 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.

## Topological properties

In order theory, in the category of complete partial orders endowed with the Scott topology, both curry and apply are continuous functions (that is, they are Scott continuous). This property helps establish the foundational validity of the study of the denotational semantics of computer programs.

## References

Search another word or see Applyon Dictionary | Thesaurus |Spanish