Previous: Output record, Up: Outputs


9.38 Writing new outputs

In this section, we explain how you can write new outputs in Mozart/Oz. You may also choose to do post-processing using another programming language, building on one of the XML output functors.

In order to write an output in Mozart/Oz, you need to provide two things:

  1. the output definition
  2. the output functor

9.38.1 Output definition

You write the output definition in the IL, and add it to the list of output definitions bound to the Oz variable Outputs at the top of the functor Outputs/Outputs.oz.

9.38.1.1 Example (dag output)

Here is an example output definition of the output output.dag:

     elem(tag: outputdef
          id: elem(tag: constant
                   data: 'output.dag')
          'functor': elem(tag: constant
                          data: 'Dag'))

The value of the id feature is an IL constant denoting the unique output identifier. The value of the 'functor' feature is an IL constant denoting the filename of the Oz functor implementing the output (modulo the suffix .ozf).

9.38.1.2 Integrate the output definition

In order to integrate the output definition into the XDK, you need to add the identifier of the new output to the XML file Outputs/outputs.xml. Here, for each new output, you add a line like the following for the Dag output:

     <outputDef id="output.Dag"/>

This step is necessary because XML language grammar files contain only output chooses and uses, but not output definitions. Therefore, the output identifiers of the chosen/used outputs are only referred to but not defined in XML language grammar files, which leads to errors running an XML validator on them.

9.38.2 Output functor

You write the output functor as an Oz functor exporting two procedures:

Open has three arguments:

  1. DIDA is a dimension identifier denoting the output dimension
  2. I is an Oz integer denoting the number of the solution
  3. OutputRec is the output record providing the decoded information contained in the solution

Close has one argument:

  1. DIDA is a dimension identifier denoting the output dimension

The output functor has to reside in Outputs/Lib. Its file name must match the value of the 'functor' feature in the output definition, i.e. for Dag, it must be Dag.oz.

9.38.2.1 Integrate the output functor

In order to integrate the output definition into the XDK, you need to add the output functor to the ozmake makefile in Outputs/Lib (Outputs/Lib/makefile.oz).

9.38.2.2 Check cycles helper procedure

The functor Outputs/Lib/Helpers.oz exports the procedure CheckCycles: DIDA NodeOLs -> U. CheckCycles checks whether a graph has a cycle. It has two arguments:

The procedure assumes that the graph principle (or the graph1 principle) is used on dimension DIDA.