www.delorie.com/gnu/docs/gforth/gforth_130.html   search  
Buy GNU books!

Gforth Manual

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.16.1 Forth source 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 three formats:

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'. Interpreting `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).

doc-include-file doc-included doc-included? doc-include doc-required doc-require doc-needs doc-sourcefilename doc-sourceline#

A definition in ANS Forth for required is provided in `compat/required.fs'.

  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003