contentsconceptssyntaxlibrariessampleserrorsindex
Full text search
Referents
    Related Syntax  

Referents are variables that can be output before their final values have been assigned. With referents you are able to stick "placeholder" variables in your output and then later assign or change their values. These "placeholder" variables are particularly useful in creating hypertext links and cross-references, but they can be used for numerous other tasks. The following program illustrates the "placeholder" quality of referents:

  process
     local stream foo
     set foo to "Mary%n"
     set referent "bar" to "Mary%n"
     output foo
     output referent "bar"
     set foo to "lamb%n"
     set referent "bar" to "lamb%n"

The output of this program is:

  Mary
  lamb

Where the output value of stream "foo" didn't change values after being output, the output value of referent "bar" did. The final value of both of the variables did change to "lamb", but only the output of the referent reflected this change.

Notice that while the stream "foo" had to be declared before it was used, the referent "bar" did not. All you need to do to create and use a referent is give it a name and set it to a value. For example, the following code creates a referent named "ref1" and sets it to an initial value of "mary joe":

  set referent ref1 to "mary joe"

Another simple example of the use of referents is in outputting page numbers that include "of n" values, for example, "page 1 of 8". Until a document has been completely processed, there is no way to know for certain how many pages there are going to be. With referents, however, you can simply stick a placeholder where the page numbers will be in the output and, after the document has been completely processed and the number of pages determined, the final values can be plugged into the referents.

The following is a short program that will output a referent when it finds one or more numbers in the input file:

  global counter num initial {0}

  find digit+
     increment num
     output referent "%d(num)ref"

  process
     local counter num2
     submit file "test1.txt"
     repeat
        exit when num2 > num
        set referent "%d(num2)ref" to "Play %d(num2) of %d(num)%t"
        increment num2
     again

An appropriate plain-text input file for this program would be:

  1 Hamlet
  2 Richard III
  3 Macbeth
  4 Romeo and Juliet
  5 King Lear

If this input file were processed by the program shown above, the output would be:

  Play 1 of 5	Hamlet
  Play 2 of 5	Richard III
  Play 3 of 5	Macbeth
  Play 4 of 5	Romeo and Juliet
  Play 5 of 5	King Lear

So, what has happened to this output is that OmniMark matched a digit, output a referent as a placeholder, and let any following text (the title of the play) fall through to the output. With each digit encountered, the process is repeated. When the process-end rule fired, the final values of the referents were determined and resolved.

      Related Syntax
   referents
   set referent
 
----

Top [CONTENTS] [CONCEPTS] [SYNTAX] [LIBRARIES] [SAMPLES] [ERRORS] [INDEX]

Generated: April 21, 1999 at 2:00:51 pm
If you have any comments about this section of the documentation, send email to [email protected]

Copyright © OmniMark Technologies Corporation, 1988-1999.