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


Gforth Manual

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

5.8.4.1 Programming Style

In order to ensure readability we recommend that you do not create arbitrary control structures directly, but define new control structure words for the control structure you want and use these words in your program. For example, instead of writing:

 
BEGIN
  ...
IF [ 1 CS-ROLL ]
  ...
AGAIN THEN

we recommend defining control structure words, e.g.,

 
: WHILE ( DEST -- ORIG DEST )
 POSTPONE IF
 1 CS-ROLL ; immediate

: REPEAT ( orig dest -- )
 POSTPONE AGAIN
 POSTPONE THEN ; immediate

and then using these to create the control structure:

 
BEGIN
  ...
WHILE
  ...
REPEAT

That's much easier to read, isn't it? Of course, REPEAT and WHILE are predefined, so in this example it would not be necessary to define them.


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