swirl
Guide to OmniMark 8   OmniMark home
docs home 
IndexConceptsTasksSyntaxLibrariesLegacy LibrariesErrors
 
    Related Concepts  
control structure  

-> (conditional operator)

 
 

Return type: The same as the type of its argument
Returns:       

Syntax

boolean-expression -> if-true-expression | if-false-expression


Purpose

You can use the conditional operator ->...|... to select one of two values based on a condition:

  process
     local integer planet initial {3}
     output "Hello " 
         || (planet = 3 -> "Human" | "Alien")  

The conditional operator has low precedence and so will usually need to be included in parentheses when combined with other operators.

Two conditional expressions can be combined so that one is the argument of another:

  process
     local integer planet initial {3}
     local switch morning initial {false}
     local switch dark-out initial {true}
     
     output "Good " 
         || (morning -> "morning" | dark-out -> "evening" | "afternoon")
         || " "
         || (planet = 3 -> "Human" | "Alien")

The two alternative values must be of the same type. Implicit conversion of types through the invocation of conversion functions is not supported. However, you can explicitly cast a value to a new type:

  process
     local integer x
     local integer y initial {77}
     local stream s initial {"234"}
         
     set x to (condition ->  y | integer s)

The type of a conditional expression is the type of its arguments. If a different type is expected, implicit conversion will occur where supported by internal or user defined conversion functions.

If the alternative values are of record types, they may be different types as long as both types are extensions of the same base type.

      Related Concepts
   Conditional constructs
 
 

Top [ INDEX ] [ CONCEPTS ] [ TASKS ] [ SYNTAX ] [ LIBRARIES ] [ LEGACY LIBRARIES ] [ ERRORS ]

OmniMark 8.2.0 Documentation Generated: March 13, 2008 at 3:33:48 pm
If you have any comments about this section of the documentation, please use this form.

Copyright © Stilo International plc, 1988-2008.