Implies (keyword)

From The Oxygene Language Wiki
Jump to: navigation, search

This is a Language topic about Oxygene
 

Language Topics Introduction | Structured Overview | Grammar | Keywords | Functions



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

Personal tools
Namespaces

Variants
Actions
Navigation
Getting Started
Sections
If you know
More
Toolbox