#Define Statements

Home • Gallery • Tutorials • Download • Purchase • Site Map
 

#Define Statement Overview

The Fractal Science Kit fractal programming language supports #define and #include statements. A #define statement is used to associate a block of statements with an identifier. A #include statement is used to insert the block of statements associated with a given identifier into your program. A #define statement can be placed in My Macros or in a program's macros and/or properties sections. A #include statement can be used anywhere program statements are valid.

The #define/#include mechanism for accessing shared software is far less useful than Inline Functions or Inline Methods. It can also lead to unreadable code if not used carefully. However, there are circumstances where it is the only way available, and is still preferable to copying the same code in 10 different programs. A typical example, is to define enums or function sets in My Macros and include them in the properties section of your programs.

The syntax of the #define statement is:

#define <DefineName>
  <Statements>
#end

The <DefineName> must be a valid identifier. The <Statements> are not evaluated until they are inserted into your program via the #include statement.

The syntax of the #include statement is:

#include <DefineName>

<DefineName> must be associated with a #define statement. The defined block of statements are inserted into the code in place of the #include statement at the beginning of the program compilation.

Example:

#define HyperbolicFunctions

functionSet HyperbolicFunctions {
  Sinh Cosh Tanh Sech Csch Coth
}
#end

This statement defines a set of functions that can be used to define a function proxy option in the properties section of your program. The following example shows how this could be used:

#include HyperbolicFunctions
 
option F {
  type = HyperbolicFunctions
  caption = "f(z)"
  default = Sinh
}

The #define statement can include arguments if necessary.

The syntax of the #define statement with arguments is:

#define <DefineName>(<Arg>, <Arg>, ...)
  <Statements>
#end

The #define name (<DefineName>) and each of the argument names (<Arg>) must be a valid identifier. The <Statements> within the block can reference these arguments by naming the argument, surrounded by the number sign character (#). When the block of statements is inserted into the program, the arguments passed to #include will replace these argument references.

The syntax of the #include statement with arguments is:

#include <DefineName>(<ArgString>, <ArgString>, ...)

<DefineName> must be associated with a #define statement and the number of arguments passed in the #include statement must match the number of arguments in the associated #define statement. Each argument passed in the #include statement must be a quoted string. When the argument is substituted into the associated statements, the quotes are removed. The reason that quotes are necessary is to allow you to pass arguments with spaces, special characters, etc. (e.g., "f(x, y)").

The defined block of statements are inserted into the code in place of the #include statement at the beginning of the program compilation.

Example:

#define HyperbolicFunctionOption(Name, Label, Default)

option #Name# {
  type = HyperbolicFunctions
  caption = "#Label#"
  default = #Default#
}
#end

This statement defines a function proxy option with arguments for the option name, label, and default. The following example shows how this could be used:

#include HyperbolicFunctions
#include HyperbolicFunctionOption("F", "f(z)", "Sinh")
#include HyperbolicFunctionOption("G", "g(z)", "Cosh")

 

Copyright © 2004-2017 Hilbert, LLC
All rights reserved