Apply

Apply

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. [ [http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-26.html The Metacircular Evaluator] (SICP Section 4.1)]

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:X imes Y o Z, that is, gisin [X imes Y o Z] where the bracket notation [A o B] denotes the space of functions from "A" to "B". By means of currying, there is a unique function mbox{curry}(g) :X o [Y o Z] . Then Apply provides the universal morphism

:mbox{Apply}: [Y o Z] imes Y o Z,

so that

:mbox {Apply}(f,y)=f(y)

or, equivalently one has the commuting diagram

:mbox{Apply} circ left( mbox{curry}(g) imes mbox{id}_Y ight) = g

The notation [A o B] for the space of functions from "A" to "B" occurs more commonly in computer science. In category theory, however, [A o B] 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" [Saunders Mac Lane, "Category Theory"] , 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). [H.P. Barendregt, "The Lambda Calculus", (1984) North-Holland ISBN 0-444-87508-5] This property helps establish the foundational validity of the study of the denotational semantics of computer programs.

References


Wikimedia Foundation. 2010.

Игры ⚽ Поможем сделать НИР
Synonyms:

Look at other dictionaries:

  • apply — ap‧ply [əˈplaɪ] verb applied PTandPP 1. [intransitive] to make a formal, usually written, request for something, especially a job, a place at university, or permission to do something: apply for • She had applied for a full time job as an English …   Financial and business terms

  • Apply — Ap*ply , v. t. [imp. & p. p. {Applied}; p. pr. & vb. n. {Applying}.] [OF. aplier, F. appliquer, fr. L. applicare to join, fix, or attach to; ad + plicare to fold, to twist together. See {Applicant}, {Ply}.] 1. To lay or place; to put or adjust… …   The Collaborative International Dictionary of English

  • apply — [v1] put into use administer, assign, bring into play, bring to bear, employ, engage, execute, exercise, exploit, handle, implement, practice, utilize; concept 225 apply [v2] be appropriate, relevant affect, allude, appertain, be applicable, bear …   New thesaurus

  • apply — [ə plī′] vt. applied, applying [ME applien < OFr aplier < L applicare, to attach to < ad , to + plicare, to fold: see PLY1] 1. to put on or spread on; place so as to be touching [to apply a salve to the skin] 2. to put to some practical… …   English World dictionary

  • Apply — Ap*ply , v. i. 1. To suit; to agree; to have some connection, agreement, or analogy; as, this argument applies well to the case. [1913 Webster] 2. To make request; to have recourse with a view to gain something; to make application. (to); to… …   The Collaborative International Dictionary of English

  • apply — I (pertain) verb affect, be applicable, be concerned with, be connected with, be pertinent, be proper to, be relevant, bear upon, belong to, concern, deal with, have a connection to, have bearing on, have reference, have relation, involve,… …   Law dictionary

  • apply — (v.) late 14c., to put (one s faculties, etc.) to some task or career, late 14c., from O.Fr. aploiier (12c., Mod.Fr. appliquer) apply, use, attach, from L. applicare attach to, join, connect; figuratively, devote (oneself) to, give attention,… …   Etymology dictionary

  • apply — ► VERB (applies, applied) 1) make a formal request for something to be done, such as asking to be considered for a job. 2) bring into operation or use. 3) be relevant. 4) put (a substance) on a surface. 5) (apply oneself) put all one s …   English terms dictionary

  • apply to — index appertain, call (appeal to), importune, petition, pray Burton s Legal Thesaurus. William C. Burton. 2006 …   Law dictionary

  • apply — 1 *use, employ, utilize, avail 2 devote, *direct, address Analogous words: attend, mind, *tend: addict, accustom, *habituate: toil, labor, work, grind (see corresponding nouns at WORK) Contrasted …   New Dictionary of Synonyms

  • apply — v. 1) (D; intr.) ( to request ) to apply for; to (we applied to the authorities for assistance; the captain applied to headquarters for a transfer; she applied for a fellowship) 2) (D; intr.) ( to seek admission to ) to apply to (she applied to… …   Combinatory dictionary

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”