Keep (data-processing)
In data processing, a guard is an expression of the type Booléen which has as a value truth if the execution of the program must continue in the branch
in question.
Le term is used in particular in the data-processing languages Haskell and Clean.
Dans Mathematica, the guards are called forced.
The guards are a fundamental concept of the kept Commandes, a language of method formal.
Les guards can be used to increase the Filtrage by reason with the possibility of jumping a reason even if the structure passes the filter.
The Boolean expressions in a conditional Instruction also answer the definition of guard but they are
called conditions.
In the example following in Haskell language, the guards appear between each pair of " |" and " =" :
F X | X > 0 = 1 | otherwise = 0
It is similar to the following mathematical notation:
In the Haskell notation the guards are in the clauses “if” and “if not”.
If there are parallel guards, as in the example below, they are tried in the order of the first to the last. The first connect which passes the guard is selected. The guards of a list of case are typically parallel. But, in a Comprehension of list in Haskell, the guards are in series. If one of it fails, the list of elements is not produced. That is equivalent combining the various guards with a and logical, except that it can have other clauses there of comprehension of list among the guards.
Evolution
A conditional simple expression, already present since 1963 in CPL, comprises a guard in the first under-expression, and another under-expression to use if the first is not it. Some common ways to write this: (x>0) - > 1/x; 0 x>0? 1/x: 0
If the second under-expression can be a conditional expression even simpler, we can give several additional alternatives to test before the fall ( fall-through ): (x>0) - > 1/x; (x<0) - > -1/x; 0
Already in 1966, ISWIM supports a form of expression without an obligatory case of fall, thus separating the guard from the concept of choice of form either that/or this. In the case of ISWIM, if aucne of the alternatives cannot be used, the value then become undefined , which means never not to calculate a value.
SASL (1976) is one of the first data-processing languages to use the term of guard. In this language, the functions can to have several definitions and that which is applied is selected according to the guards which follow each definition: FAC N = 1, N = 0 = N * FAC (n-1), N > 0
Reason for guard
In addition to one guard attached to a reason, a guard by reason can indicate the use of filtering per reason in the context of a guard. Indeed, the recognition by a reason means the success of the guard. This significance was introduced by a titrated proposal for Haskell of Simon Peyton Jones has new view off guards] in April 1997 and summer established. This functionality makes it possible to use reasons in the guards of a reason.
An example of Haskell thus extended: clunky env var1 var2 | Just val1 < - lookup env var1 , Just val2 < - lookup env var2 = val1 + val2 … other equations for clunky…
It as follows is read: " Clunky for an environment and two variables, if the lookups (?) variables of the environment produces values , is the sum of the values. … " As in one] of list, the guards are in series, and if one of it fails the branch is not followed.
See too
-
Assertion (data-processing)
- logical Condition
- Instruction switch
References
-
Guard in The Free On-line Dictionary off Computing , Denis Howe (editor).
- The Haskell 98 Carryforward , chapter 3 Expressions.
- The Mathematica Book, section 2.3.5 Putting Constraints one Patterns
- The Glorious Glasgow Haskell Compilation System User' S Guides , Version 6.4, section 7.3.2. Pattern guards
| Random links: | James Fergusson | Lara (goddess) | County of Marion (Arkansas) | Bibio marci | Cessalto | Simba |