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


Gforth Manual

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

3.7 Using files for Forth code

While working at the Forth command line is convenient for one-line examples and short one-off code, you probably want to store your source code in files for convenient editing and persistence. You can use your favourite editor (Gforth includes Emacs support, see section 12. Emacs and Gforth) to create file and use

 
s" file" included

to load it into your Forth system. The file name extension I use for Forth files is `.fs'.

You can easily start Gforth with some files loaded like this:

 
gforth file1 file2

If an error occurs during loading these files, Gforth terminates, whereas an error during INCLUDED within Gforth usually gives you a Gforth command line. Starting the Forth system every time gives you a clean start every time, without interference from the results of earlier tries.

I often put all the tests in a file, then load the code and run the tests with

 
gforth code tests -e bye

(often by performing this command with C-x C-e in Emacs). The -e bye ensures that Gforth terminates afterwards so that I can restart this command without ado.

The advantage of this approach is that the tests can be repeated easily every time the program ist changed, making it easy to catch bugs introduced by the change.

Reference: 5.16.1 Forth source files.


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