Implies (keyword)
From The Oxygene Language Wiki
This is a Language topic
Feel free to add your notes to this topic below.
The implies operator was designed specifically for require/ensure clauses and class invariants, but can also be used elsewhere in code. Similar to and and or, it combines two Boolean expressions; the difference is that with implies, the second expression is only evaluated if the first/left expression is true. If the first expression is false, the entire expression will be considered true.
ensure HasDriversLicense implies Age >= 16;
In the example above, (Age >= 16) is only ever evaluated, if HasDriversLicense is true; else, the entire expression will short-circuit to true, essentially skipping the clause for the purpose of pre/post-conditions or invariants.
The above could be rewritten as
ensure (not HasDriversLicense) or (Age >= 16)
which performs the same logic, but reads a lot less intuitively.
Of course, implies can also be used as part of any Boolean logic expression, outside of class contracts.
See Also
- or – and
- Class Contracts – require – ensure
- Expressions
Area: Oxygene Language
Compiler version: Oxygene 5
Language Glossary — Keywords — Types — FAQ — How To