Node:Forth source files, Next:General files, Previous:Files, Up:Files
The simplest way to interpret the contents of a file is to use one of
these two formats:
include mysource.fs s" mysource.fs" included
You usually want to include a file only if it is not included already
(by, say, another source file). In that case, you can use one of these
require mysource.fs needs mysource.fs s" mysource.fs" required
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:
1024 require foo.fs drop
Here you want to pass the argument 1024 (e.g., a buffer size) to
foo.fs has the stack effect ( n - n
), which allows its use with
require. Of course with such
parameters to required files, you have to ensure that the first
require fits for all uses (i.e.,
require it early in the
master load file).
Interpret (process using the text interpreter) the contents of the file wfileid.
include-filei*x wfileid -- j*x unknown ``include-file''
includedi*x c-addr u -- j*x file ``included''
include-filethe 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,
included?c-addr u -- f gforth ``included?''
foo.fsand found somewhere on the Forth search path. To return
included?, you must specify the exact path to the file, even if that is
include... "file" -- ... gforth ``include''
include-filethe file file.
requiredi*x addr u -- j*x gforth ``required''
include-filethe file with the name given by addr u, if it is not
required) already. Currently this works by comparing the name of the file (with path) against the names of earlier included files.
require... "file" -- ... gforth ``require''
include-filefile only if it is not included already.
An alias for
needs... "name" -- ... gforth ``needs''
require; exists on other systems (e.g., Win32Forth).
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 undefined. In Gforth, the result is valid during the whole seesion (but not across
sourcefilename-- c-addr u gforth ``sourcefilename''
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 undefined.
sourceline#-- u gforth ``sourceline-number''
A definition in ANS Forth for
required is provided in