Getting Started Documentation Glish Learn More Programming Contact Us
Version 1.9 Build 1556
News FAQ
Search Home


next up previous contents index
Next: Statements Up: Expressions Previous: Precedence


include Expression

You can include the contents of a Glish source file using the include expression:

include "file"
where file is the name of the file to include. Typically include expressions appear near the beginning of a source file, and include other source files as a simple ``library'' mechanism. You can check the success of the inclusion using the include expression as follows:
    if ( ! include "my-first-file.g" )
        include "my-fall-back-file.g"
Here the file my-fallback-file.g is only included if the inclusion of my-first-file.g fails. If parsing any portion of the file being included fails, no part of the file is executed.

The include expressions may be nested arbitrarily deep, and the path Glish searches when trying to include a file can be set as follows:

	system.path.include := ". /home/me/scripts /usr/local/share/glish"
Multiple directories can be specified with this variable and then searched in the order specified. If this variable is not set, only the current directory is searched for files which do not begin a ``/''. Note the leading dot (``.'') in the string above; if this isn't included the current directory will not be searched. A good place to set this variable is in the .glishrc file(s) (See § 13.1, page [*]).

While a Glish variable along with the is_defined() function (see § 10.6, page [*]) can be used to prevent multiple inclusions of a file, a better way to handle this with the include once pragma. When this pragma is inserted into a file, it indicates that the interpreter should only include it once. The pragma is used as follows:

    pragma include once
    print "file test_pragma.g included"
It forces the file to be included only once. Currently, to re-include the file you must exit and then re-enter Glish. The advantage is that on successive includes of the file Glish can return without parsing or opening the file. This saves time and the makes include file simpler.


next up previous contents index
Next: Statements Up: Expressions Previous: Precedence   Contents   Index
Please send questions or comments about AIPS++ to aips2-request@nrao.edu.
Copyright © 1995-2000 Associated Universities Inc., Washington, D.C.

Return to AIPS++ Home Page
2006-10-15