In
computer science
Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to practical disciplines (includin ...
and
computer programming
Computer programming is the process of performing a particular computation (or more generally, accomplishing a specific computing result), usually by designing and building an executable computer program. Programming involves tasks such as anal ...
, a
function f is said to be strict if, when applied to a non-terminating expression, it also fails to terminate.
A strict function in the
denotational semantics of
programming language
A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are a kind of computer language.
The description of a programming l ...
s is a
function ''f'' where
. The entity
, called ''
bottom'', denotes an expression that does not return a normal value, either because it loops endlessly or because it aborts due to an error such as division by zero. A function that is not strict is called non-strict. A
strict programming language
A strict programming language is a programming language which employs a strict programming paradigm, allowing only strict functions (functions whose parameters must be evaluated completely before they may be called) to be defined by the user. A no ...
is one in which user-defined functions are always strict.
Intuitively, non-strict functions correspond to
control structures. Operationally, a strict function is one that always
evaluate
Evaluation is a
systematic determination and assessment of a subject's merit, worth and significance, using criteria governed by a set of standards. It can assist an organization, program, design, project or any other intervention or initiative ...
s its
argument
An argument is a statement or group of statements called premises intended to determine the degree of truth or acceptability of another statement called conclusion. Arguments can be studied from three main perspectives: the logical, the dialect ...
; a non-strict function is one that might not evaluate some of its arguments. Functions having more than one parameter can be strict or non-strict in each parameter independently, as well as ''jointly strict'' in several parameters simultaneously.
As an example, the
if-then-else
expression of many programming languages, called
?:
in languages inspired by C, may be thought of as a function of three parameters. This function is strict in its first parameter, since the function must know whether its first argument evaluates to true or to false before it can return; but it is non-strict in its second parameter, because (for example)
if(false,,1) = 1
, as well as non-strict in its third parameter, because (for example)
if(true,2,) = 2
. However, it is jointly strict in its second and third parameters, since
if(true,,) =
and
if(false,,) =
.
In a
non-strict functional programming
In computer science, functional programming is a programming paradigm where programs are constructed by applying and composing functions. It is a declarative programming paradigm in which function definitions are trees of expressions that ...
language,
strictness analysis refers to any algorithm used to prove the strictness of a function with respect to one or more of its arguments. Such functions can be
compiled to a more efficient
calling convention
In computer science, a calling convention is an implementation-level (low-level) scheme for how subroutines or functions receive parameters from their caller and how they return a result. When some code calls a function, design choices have b ...
, such as
call by value
In a programming language, an evaluation strategy is a set of rules for evaluating expressions. The term is often used to refer to the more specific notion of a ''parameter-passing strategy'' that defines the kind of value that is passed to the ...
, without changing the meaning of the enclosing program.
See also
*
Eager evaluation
*
Lazy evaluation
In programming language theory, lazy evaluation, or call-by-need, is an evaluation strategy which delays the evaluation of an expression until its value is needed ( non-strict evaluation) and which also avoids repeated evaluations ( sharing).
T ...
*
Short-circuit evaluation
References
{{DEFAULTSORT:Strict Function
Formal methods
Denotational semantics
Evaluation strategy