file inclusion - Maple Help

Home : Support : Online Help : Programming : Compiling : Preprocessor

$include - file inclusion$define - macro definition

$undef - macro definition removal$ifdef - conditional processing

 Calling Sequence $include "filename"$include $define macroName macroDefinition$define macroName( macroParameters ) macroDefinition $undef macroName$ifdef macroName $ifndef macroName$else macroName $elif macroName$endif

Parameters

 filename - name of file to include macroName - macro name macroDefinition - text to be substituted for a macro macroParameters - comma-separated macro formal parameter sequence

Description

 • The Maple preprocessor is modeled after the C preprocessor, but it implements only a small subset of the C preprocessor's capabilities. However, many of the design decisions were driven by those of the C preprocessor.
 • The preprocessor directives are not part of the Maple language and therefore cannot be entered at the Maple command prompt.  However, they can be embedded within Maple files and are preprocessed during the loading or reading of the file.
 • To avoid potential collisions with Maple comments, the Maple preprocessor uses the dollar sign ("$") instead of the number sign ("#") as the preprocessor directive introducer. Furthermore, no white space may appear between the "$" and the directive's keyword.
 • The introducer ("$") must appear as the first character of a line to be recognized as a preprocessor directive.  • Preprocessor directives appearing within multi-line comments (those delimited by (* and *) characters) are ignored. $include:
 • The $include directive causes a specified file to be processed as part of the input, just as though the contents of the file had appeared in place of the directive.  • An$include directive of the form $include "filename" searches for exactly the file specified, and then will search for the file relative to the include path. The filename can be an absolute or a relative path name. Any valid pathname is allowed. To enhance portability on non-UNIX platforms, any slash (/) characters appearing in the filename are automatically translated to the directory separator used by the underlying operating system ("\" under Windows).  • An$include directive of the form $include searches for the specified file in the directories specified by the include path first. If it fails to find it, it searches for exactly the file specified.  • The maximum number of nested$include files is limited by the maximum number of files that can be opened by the given version of Maple. This varies from system to system.
 • The include path can be specified on the command line that invokes Maple by using the -I option or it can be modified by calling kernelopts(includepath). Multiple paths can be specified within a single string separated by commas or semicolons or alternatively a list of paths may be entered.  When using kernelopts(includepath) you do not have to prefix the include path with -I.  The maximum number of include path entries is 25.
 $define:  • The$define directive creates a macro definition.
 • The macroName can be any valid C language identifier, namely a letter or underscore followed by zero or more letters, digits, or underscores.
 • The maximum length for a macro definition, including the $define keyword, macro name, and macro parameters but excluding backslashes, is 1024 characters.  • The macroDefinition can be any sequence of characters. If a "#" character is encountered outside of a quoted Maple name () or string (""), it is assumed to start a comment, and it terminates the macro definition. (The comment and any preceding whitespace do not become part of the definition.) If no macroDefinition is provided, the macro is defined to have the value NULL.  • The macroParameters are a comma-separated sequence of single-letter formal parameter names. When the macro is invoked and replaced by the macroDefinition, occurrences of these parameter names in the definition are replaced by the actual parameters in the macro invocation. There can be at most 52 formal parameters to a macro, and the same parameter cannot appear more than once in the macroParameters.  • Simple macro definitions can also be made on the command line that invokes Maple, by using -D macroName or -D macroName=macroDefinition.  • There are two predefined macros. __FILE__ expands to a string giving the name of the file being processed (as the result of an$include statement), or to the empty string if redirected input is being read directly. __LINE__ expands to an integer that gives the current line number of the file being processed.
 • The macro invocation mechanism is aware of Maple syntax, and will correctly treat strings, quoted names, and expressions delimited by "()", "[]", or "{}" as single arguments, even if they contain commas. It will not correctly deal with a single quoted (that is, unevaluation quote) expression, because that would require too much knowledge. This is only a problem if an unevaluated expression contains a comma that is not protected by one of the delimiters listed earlier.
 • The maximum number of active macro definitions, including the two predefined macros, is 511.
 • Macros are expanded from the outside in. For example, if macros A and B are defined, each having a parameter, A(B(x)) is expanded by first expanding A, with B(x) as a parameter. Then, the input is rescanned and each occurrence of B(x) is expanded.
 $undef:  • The$undef directive removes the definition of a macro, if it exists.
 • Macro undefinitions can also be made on the command line that invokes Maple, by using the -U macroName option. Command line undefinitions only undefine macros that were defined by earlier -D options.
 $ifdef:  • The$ifdef directive tests whether a macro is defined. The $ifndef directive tests if a macro is not defined.  • If the test is positive, the text lines after the directive are processed, up to a corresponding$else, $elif, or$endif. If the test is negative, those lines are skipped. If a corresponding $else or$elif directive exists, the lines between it and the corresponding $endif are skipped if the test was positive, but are processed if the test was negative.  • These directives can be nested, but a given level of nesting cannot extend outside of the file in which it was started. In other words, the corresponding$ifdef/$ifndef,$else or $elif, and$endif must all be within the same file. The maximum nesting depth is 100 levels.