Including code from other files

OmniMark allows you to include code that is contained in another file in an OmniMark program by way of an include declaration. This feature allows you to easily recycle useful bits of code without having to resort to "copy and paste". Additionally, this means that if you decide you want to change something in that particular piece of code, rather than having to track down every individual usage of it, you need only make the changes in the single file that you have "included" in the other programs.

For example, you have defined an OmniMark function that you are particularly proud of, and that is useful in several different programs you're working on. For example, the function "Report", as follows:

  define function Report
     value string msg
  as
     reopen log-file as file "MyProgram.log"
     put log-file date "xY/M/D h:m:s" || " MyProgram: " || msg || "%n"
     close log-file

The function Report simply outputs the value of the stream "msg" into the file MyProgram.log with a time stamp. If this function were the only thing to be in a file called report.xin, that function could then be included in any OmniMark program by naming that file in an include declaration:

  include "report.xin"

Related Topics