swirl
Guide to OmniMark 8   OmniMark home
docs home 
IndexConceptsTasksSyntaxLibrariesLegacy LibrariesErrors
 
    Related Concepts  
operator  

~ (identity)

 
 

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

Syntax

~ expression


Purpose

The identity operator is used to disambiguate an expression in certain contexts where the same expression could be interpreted in multiple ways. This is necessary when using an expression inside a pattern or inside of an element context test.

Identity operator in patterns

You can use the identity operator (~) to force an expression contained in a pattern to be evaluated so that the result of the expression becomes part of the pattern. This is only necessary for expressions which are ambiguous in their syntax, so that OmniMark cannot tell, without the identity operator, whether the expression is a value expression to be evaluated or a sequence of pattern expressions.

The identity operator is required in the following cases:

You must use the identity operator when using an item on a shelf in a pattern:

     ~foo[2]
     ~foo{"bar"}

You must use the identity operator when calling an infix function (one in which the function name is placed between its arguments):

     ~("d" % foo)
     ~(foo take (any ** ","))

You can also use the identity operator in place of the keyword when to add a conditional expression to a pattern. Thus you can replace:

     (when title = "")

with

     ~(title = "")

Identity operator in element context tests

The identity operator can be used to specify an expression that generates the name of an element in an element context test or an element qualifier. The element context tests are

The relevant element qualifiers are

When used in this fashion, the argument of the identity operator should be a string, or an expression convertible to a string.

As an example, the following program outputs a message only when the name of the parent of the current element is the content of the string shelf s (i.e., a):

       global string s initial { "a" }
  
  
       process
          do xml-parse scan "<a><b><c/></b></a>"
             output "%c"
          done
  
  
       element #implied
          output "%c"
  
          output "Hello, World!%n"
             when parent is ~s

The identity operator is required in the parent is element context text because, without it, the identifier s would be interpreted as the name of the element, rather than as the name of the string shelf s.

      Related Concepts
   Pattern matching
 
 

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.