Forth applications are written bottom-up; no word may be referenced until it is defined. Definitions early in a source file are used to build the definitions that follow, leading up to the application's main entry pont.
Here is the recommended high-level source layout of a Forth application (see the sample application sources for more examples):
\ Required library code:
needs <libraryfile>
...
\ Opening of any external resource databases:
\ (via use-resources from the library file
resources):
(ID) p4ap (ID) <creatorID> use-resources
\ Constant definitions:
<value> constant <constantname>
...
\ Variable declarations (globals):
variable <variablename>
...
\ Variable default initializations:
<value> <variablename> !
...
\ System-dependent words (preferences, etc.):
: <name> ... ;
...
\ Application-specific words:
: <name> ... ;
...
\ Program main entry point:
: go ( -- ) ... ;
\ Stand-alone executable generation (registered
version only)
\ (Often this is placed in a separate file for convenience):
' go <creatorID> MakePRC <ProgramName>
\ Deletion of unneeded forms from the target PRC:
<id> <resourceType> delrsrc drop
...
\ Addition of needed forms from an open resource database:
<id> <resourceType> copyrsrc
...
\ Done!