swirl
Guide to OmniMark 8   OmniMark home
docs home 
IndexConceptsTasksSyntaxLibrariesLegacy LibrariesErrors
 
    Related Concepts  
declaration/definition  

define conversion-function

 
 

Syntax

define type conversion-function
 value type input-value
 (as function-body | elsewhere)



Purpose

You can define a conversion function that will be called automatically when data of one type is expected and data of another type is supplied. The following example define a conversion function that converts an integer to a stream:

  define string conversion-function
   value integer x
   as
      return "d" % x
  
  process
     local integer foo initial {5}
     output foo

A conversion function is not called explicitly. It is called automatically when needed. Therefore, a conversion function has no name. It can be referred to by the type of conversion it supports, so the above function can be called an "integer to stream" conversion function.

You can define a conversion function for:

OmniMark supplies conversion function for most of its internal types, and the external function libraries supplied with OmniMark define conversion functions between the OmniMark types and the types they create. There can only be one conversion function for any one type-to-type conversion so you cannot define conversion-functions for conversions that are already supported.

When defining conversion functions, it is sometimes useful to take advantage of the type conversions that already exist. The following conversion functions define conversions between the bcd and floatdata types using the string representation of the number as an intermediate type. This takes advantage of the fact that the BCD and float libraries both define string formatting and conversions from strings for their respective data types:

  define bcd conversion-function value float f
   as
     return "d" % f
  
  define float conversion-function value bcd b
   as
     return "d" % b

Conversion functions and extended records

There are two limitations when defining conversion functions that deal with extended records:

      Related Concepts
   Functions: conversion
   Modules, defining
 
 

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.