format, %
Full Description
swirl
Syntax
  string-expression (format | % ) (numeric-expression | string-expression)


Purpose

An operator that converts the contents of a string-expression or numeric-expression to a format specified by the preceding string-expression. This operator allows you to dynamically format values in an OmniMark program.

For example, the output action in the following code:

  match "%%" ul [digit | "abcdef"] {2} => twoHex
              output "b" % (twoHex base 16)

Outputs the value of the numeric expression, defined as "twoHex base 16", as a binary string.

The format operator works in a manner similar to OmniMark format items (keywords preceded by "%"), but there are two main differences. The first difference is that format items require the program to declare a variable for storing the value of the string or numeric expression before the expression can be converted, while the format operator allows you to dynamically format the value. For example, the following code creates the variable "sum" to store the numeric expression ApennySaved + ApennyEarned, then uses the %d format item to output the sum of ApennySaved + ApennyEarned in decimal format:

  set sum to ApennySaved + ApennyEarned
    output "%d(sum)"

The following code uses the format operator to produce the same result:

  output "d" % (ApennySaved + ApennyEarned)

The second difference is that the format string can be used to allow dynamic sizing of output values. For example:

  output ("d" % column-width || "d") % NumPennies

In this case, the bracketed expression is the format string used to format NumPennies.

The "format" string-expression (the expression used with the format operator to convert another string or numeric expression) must end with one of the following:

  • "a" alphabetic representation of a counter value
  • "b" binary representation of a counter value
  • "d" decimal represenation of a counter value
  • "g" string expression
  • "i" Roman numeral representation of a counter value
  • "y" symbolic representation of a counter value

Each of these has an associated format item of the same letter. Note that "a", "b", "d", "i" and "y" require a numeric expression, just like their format item forms; and "g" requires a string expression.

Copyright © OmniMark Technologies Corporation, 1988-1998.