Programming
evaluation

In computer science, an evaluation strategy is a set of (usually deterministic) rules for determining the evaluation of expressions in a programming language. Eager evaluation or strict evaluation is the Evaluation strategy in most traditional Programming languages In eager evaluation an expression In Computer programming, lazy evaluation (or delayed evaluation) is the technique of delaying a computation until such time as the result of the computation is In Computing, partial evaluation is a technique for program optimization by Specialization. In Computer science, remote evaluation is a general term for any technology that involves the transmission of executable software programs from a client computer to a server Short-circuit evaluation or minimal evaluation denotes the semantics of some Boolean operators in some Programming languages in which the second argument Computer science (or computing science) is the study and the Science of the theoretical foundations of Information and Computation and their An expression in a Programming language is a combination of values Variables operators and functions that are interpreted ( A programming language is an Artificial language that can be used to write programs which control the behavior of a machine particularly a Computer. Emphasis is typically placed on functions or operators — an evaluation strategy defines when and in what order the arguments to a function are evaluated, when they are substituted into the function, and what form that substitution takes. In Computer science, a subroutine ( function, method, procedure, or subprogram) is a portion of code within a larger The lambda calculus, a formal system for the study of functions, has often been used to model evaluation strategies, where they are usually called reduction strategies. In Mathematical logic and Computer science, lambda calculus, also written as λ-calculus, is a Formal system designed to investigate function In formal logic, a formal system (also called a logical system, a logistic system, or simply a logic Formal systems in mathematics consist Evaluation strategies divide into two basic groups, strict and non-strict, based on how arguments to a function are handled. A language may combine several evaluation strategies; for example, C++ combines call-by-value with call-by-reference. C++ (" C Plus Plus " ˌsiːˌplʌsˈplʌs is a general-purpose Programming language. Most languages that are predominantly strict use some form of non-strict evaluation for boolean expressions and if-statements.

Strict evaluation

In strict evaluation, the arguments to a function are always evaluated completely before the function is applied. In Computer science, a subroutine ( function, method, procedure, or subprogram) is a portion of code within a larger

Under Church encoding, eager evaluation of operators maps to strict evaluation of functions; for this reason, strict evaluation is sometimes called "eager". In Mathematics, Church encoding is a means of embedding data and operators into the Lambda calculus, the most familiar form being the Church numerals, a Eager evaluation or strict evaluation is the Evaluation strategy in most traditional Programming languages In eager evaluation an expression Programming languages generally support a set of operators that are similar to operators in mathematics. Most existing programming languages use strict evaluation for functions.

Applicative order

Applicative order (or leftmost innermost) evaluation refers to an evaluation strategy in which the arguments of a function are evaluated from left to right in a post-order traversal of reducible expressions (redexes). In Computer science, tree-traversal refers to the process of visiting each node in a Tree data structure, exactly once in a systematic way Unlike call-by-value, applicative order evaluation reduces terms within a function body as much as possible before the function is applied.

Call by value

Call-by-value evaluation is the most common evaluation strategy, used in languages as far-ranging as C and Scheme. tags please moot on the talk page first! --> In Computing, C is a general-purpose cross-platform block structured Scheme is a Multi-paradigm programming language. It is one of the two main dialects of Lisp and supports a number of programming paradigms but is In call-by-value, the argument expression is evaluated, and the resulting value is bound to the corresponding variable in the function (usually by capture-avoiding substitution or by copying the value into a new memory region). If the function or procedure is able to assign values to its parameters, only the local copy is assigned -- that is, anything passed into a function call is unchanged in the caller's scope when the function returns.

Call-by-value is not a single evaluation strategy, but rather the family of evaluation strategies in which a function's argument is evaluated before being passed to the function. While many programming languages (such as Eiffel and Java) that use call-by-value evaluate function arguments left-to-right, some evaluate functions and their arguments right-to-left, and others (such as Scheme, OCaml and C) leave the order unspecified (though they generally guarantee sequential consistency). Sequential consistency is one of the Consistency models used in the domain of the Concurrent programming (e

Call by reference

In call-by-reference evaluation, a function receives an implicit reference to the argument, rather than a copy of its value. In Computer science, a reference is an object containing information which refers to data stored elsewhere as opposed to containing the data itself This means that the function can modify the argument, what will be seen by its caller. Call-by-reference therefore has the advantage of greater time- and space-efficiency (since arguments do not need to be copied), as well as the potential for greater communication between a function and its caller (since the function can return information using its reference arguments), but the disadvantage that a function must often take special steps to "protect" values it wishes to pass to other functions.

Many languages support call-by-reference in some form or another, but comparatively few use it as a default; Perl and Visual Basic are two that do, though Visual Basic also offers a special syntax for call-by-value parameters. NOTES FOR EDITORS "Perl" is not an acronym (read the "Name" section below Visual Basic ( VB) is the third-generation event-driven programming language and associated development environment (IDE from A few languages, such as C++, default to call-by-value, but offer special syntax for call-by-reference parameters. C++ (" C Plus Plus " ˌsiːˌplʌsˈplʌs is a general-purpose Programming language. In purely functional languages there is typically no semantic difference between the two strategies (since their data structures are immutable, so there is no possibility for a function to modify any of its arguments), so they are typically described as call-by-value even though implementations frequently use call-by-reference internally for the efficiency benefits. Purely functional is a term in Computing used to describe Algorithms Data structures or Programming languages that exclude destructive modifications

Even among languages that don't exactly support for call-by-reference, many, including C and ML, support explicit references (objects that refer to other objects), such as pointers (objects representing the memory addresses of other objects), and these can be used to effect or simulate call-by-reference (but with the complication that a function's caller must explicitly generate the reference to supply as an argument). tags please moot on the talk page first! --> In Computing, C is a general-purpose cross-platform block structured ML is a general-purpose Functional programming language developed by Robin Milner and others in the late 1970s at the University of Edinburgh, whose syntax In Computer science, a reference is an object containing information which refers to data stored elsewhere as opposed to containing the data itself Some languages straddle both worlds; for example, Java is a call-by-value language, but since most Java expressions are references to anonymous objects, it frequently displays call-by-reference semantics without the need for any explicit reference syntax.

Call by copy-restore

Call-by-copy-restore, call-by-value-result or call-by-value-return (as termed in the Fortran community) is a special case of call-by-reference where the provided reference is unique to the caller. Fortran (previously FORTRAN) is a general-purpose, procedural, imperative Programming language that is especially suited to If a parameter to a function call is a reference that might be accessible by another thread of execution, its contents are copied to a new reference that is not; when the function call returns, the updated contents of this new reference are copied back to the original reference ("restored").

The semantics of call-by-copy-restore also differ from those of call-by-reference where two or more function arguments alias one another; that is, point to the same variable in the caller's environment. In Computing, aliasing describes a situation in which a data location in memory can be accessed through different symbolic names in the program Under call-by-reference, writing to one will affect the other; call-by-copy-restore avoids this by giving the function distinct copies, but leaves the result in the caller's environment undefined (depending on which of the aliased arguments is copied back first). In Computer science, undefined behavior is a feature of some programming languages &mdash most famously C.

When the reference is passed to the callee uninitialized, this evaluation strategy may be called call-by-result.

Partial evaluation

Main article: partial evaluation

In partial evaluation, evaluation may continue into the body of a function that has not been applied. In Computing, partial evaluation is a technique for program optimization by Specialization. Any sub-expressions that do not contain unbound variables are evaluated, and function applications whose argument values are known may be reduced. In the presence of side-effects, complete partial evaluation may produce unintended results; for this reason, systems that support partial evaluation tend to do so only for "pure" expressions (expressions without side-effects) within functions.

Non-strict evaluation

In non-strict evaluation, arguments to a function are not evaluated unless they are actually used in the evaluation of the function body.

Under Church encoding, lazy evaluation of operators maps to non-strict evaluation of functions; for this reason, non-strict evaluation is sometimes referred to as "lazy". In Computer programming, lazy evaluation (or delayed evaluation) is the technique of delaying a computation until such time as the result of the computation is Boolean expressions in many languages use lazy evaluation; in this context it is often called short circuiting. In Computer programming, lazy evaluation (or delayed evaluation) is the technique of delaying a computation until such time as the result of the computation is Conditional expressions also usually use lazy evaluation, albeit for different reasons.

Normal order

Normal-order (or leftmost outermost) evaluation is the evaluation strategy where the outermost redex is always reduced, applying functions before evaluating function arguments. It differs from call-by-name in that call-by-name does not evaluate inside the body of an unapplied function.

Call by name

In call-by-name evaluation, the arguments to functions are not evaluated at all — rather, function arguments are substituted directly into the function body using capture-avoiding substitution. If the argument is not used in the evaluation of the function, it is never evaluated; if the argument is used several times, it is re-evaluated each time. (See Jensen's Device. Jensen's Device is a computer programming technique devised by Danish computer scientist Jørn Jensen after studying the ALGOL 60 Report )

Call-by-name evaluation can be preferable over call-by-value evaluation because call-by-name evaluation always yields a value when a value exists, whereas call-by-value may not terminate if the function's argument is a non-terminating computation that is not needed to evaluate the function. Opponents of call-by-name claim that it is significantly slower when the function argument is used, and that in practice this is almost always the case as a mechanism such as a thunk is needed. The word thunk has at least three related meanings in computer science

Call-by-name evaluation is rarely implemented directly, but frequently used in considering theoretical properties of programs and programming languages. Real-world languages with call-by-name semantics tend to be implemented using call-by-need evaluation. Call-by-name is the default evaluation in ALGOL 60. Algol (β Per / Beta Persei known colloquially as the Demon Star, is a bright Star in the Constellation Perseus.

Call by need

Call-by-need is a memoized version of call-by-name where, if the function argument is evaluated, that value is stored for subsequent uses. In Computing, memoization is an optimization technique used primarily to speed up Computer programs by having function calls avoid repeating In a "pure" (effect-free) setting, this produces the same results as call-by-name; when the function argument is used two or more times, call-by-need is almost always faster.

Because evaluation of expressions may happen arbitrarily far into a computation, languages using call-by-need generally do not support computational effects (such as mutation) except through the use of monads and uniqueness types. In object-oriented and functional programming an immutable object is an object whose state cannot be modified after it is created In Functional programming, a monad is a kind of Abstract data type used to represent Computations (instead of data in the Domain model) In Computing, a unique type guarantees that an object is used in a single-threaded way with at most a single reference to it This eliminates any unexpected behavior from variables whose values change prior to their delayed evaluation.

This is a kind of Lazy evaluation. In Computer programming, lazy evaluation (or delayed evaluation) is the technique of delaying a computation until such time as the result of the computation is

Haskell is the most well-known language that uses call-by-need evaluation. Haskell is a standardized Purely functional Programming language with non-strict semantics, named after the Logician Haskell Curry

Call by macro expansion

Call-by-macro-expansion is similar to call-by-name, but uses textual substitution rather than capture-avoiding substitution. With uncautious use, macro substitution may result in variable capture and lead to undesired behavior. Hygienic macros avoid this problem by checking for and replacing shadowed variables that are not parameters. Hygienic macros are macros whose expansion is guaranteed not to cause collisions with existing symbol definitions

Nondeterministic strategies

Full β-reduction

Under full β-reduction, any function application may be reduced (substituting the function's argument into the function using capture-avoiding substitution) at any time. This may be done even within the body of an unapplied function.

Call by future

Call-by-future (or parallel call-by-name) is like call-by-need, except that the function's argument may be evaluated in parallel with the function body (rather than only if used). The two threads of execution synchronize when the argument is needed in the evaluation of the function body; if the argument is never used, the argument thread may be killed.

Optimistic evaluation

Optimistic evaluation is another variant of call-by-need in which the function's argument is partially evaluated for some amount of time (which may be adjusted at runtime), after which evaluation is aborted and the function is applied using call-by-need. This approach avoids some of the runtime expense of call-by-need, while still retaining the desired termination characteristics.