The simplest way to interpret the contents of a file is to use one of these two equivalent syntaxes:
You usually want to include a file only if it is not included already
(by, say, another source file). In that case, you can replace include with require:
It is good practice to write your source files such that interpreting
them does not change the stack. Source files designed in this way can
be used with required and friends without complications. For
example, assume that including foo.fs has the stack effect
( u -- u ) (u might be a configuration parameter, such as a
buffer size). Then you can use it with require:
If require actually includes foo.fs, the 1024 will be on
the stack at the end, just like if require does nothing. With
such parameters to required files, you have to ensure that the first
require fits for all uses (i.e., require the file early
in the master load file).
Another alternative is to pass configuration parameters by defining words (often constants) for them.
Interpret (process using the text interpreter) the contents of the file wfileid.
include-file the file whose name is given by the string
c-addr u.
True only if the file c-addr u is in the list of earlier
included files. If the file has been loaded, it may have been
specified as, say, foo.fs and found somewhere on the
Forth search path. To return true from included?,
you must specify the exact path to the file, even if that is
./foo.fs
include-file the file file.
include-file the file with the name given by addr
u, if it is not included (or required)
already. Currently this works by comparing the name of the file
(with path) against the names of earlier included files.
include-file file only if it is not included already.
An alias for require; exists on other systems (e.g., Win32Forth).
skip remaining source file
List the names of the files that have been included.
The name of the source file which is currently the input
source. The result is valid only while the file is being
loaded. If the current input source is no (stream) file, the
result is an arbitrary string. In Gforth, the result is valid
during the whole session (but not across savesystem
etc.).
The line number of the line that is currently being interpreted from a (stream) file. The first line has the number 1. If the current input source is not a (stream) file, the result is an unspecified number.
A definition in Standard Forth for required is provided in
compat/required.fs.