Welcome back! This post will explore some actual code from EC Chapter 1. Again, remember I am a new Forth programmer, so this is only one way to do this.
Let’s start with compound growth
The first program on page 4 of Executive Computing (“EC” from now on) looks like this in BASIC.
10 LET S = 100
20 '
30 FOR Y = 1 TO 5
40 LET S = 1.15 * S
50 PRINT Y, S
60 NEXT Y
70 '
80 END
It calculates inflation over five years, assuming a 15% rate each year. It prints out each year and the corresponding price. When run, you get this:

It could be written in Tali Forth like this:
\ Return a growth table given initial start value and rate.
\ Numbers should be entered in cents 115.00 = 11500
: tab 9 emit ;
: .00 0 <# # # [char] . hold #s #> type space ;
: 5years ( n -- )
cr
>r
6 1 do
r> 115 100 */
i . dup tab .00 cr
>r
loop
r> drop
;
The Program INFLATE
This is more ambitious. Three different inflation rates are tracked. See pages 4-7 in Nevison. See the comments in the code for an idea of the goal. Nevison’s code is very nicely organized and formatted.
BASIC version
100 REM INFLATE 1 JANUARY 1980 STEVE CAULDWELL
110 '
112 REM COPYRIGHT 1980 JOHN M. NEVISON ASSOCIATES
114 '
120 REM REVEALS PROFIT MARGIN IN AN INFLATIONARY
130 REM WORLD WHERE RAW MATERIAL COSTS, LABOR COSTS,
140 REM AND PRICES EACH GROW AT A DIFFERENT RATE.
145 '
150 REM VARIABLES:
154 REM L............ LABOR COST
155 REM P............ PRICE
156 REM R............ RAW MATERIAL COST
158 '
200 PRINT "YR RAW MAT.", "LABOR", "TOTAL COST",
210 PRINT "PRICE", "MARGIN (%)"
211 PRINT
220 '
270 LET P = 100
280 LET R = 56
290 LET L = 21
300 PRINT O; R, L, R+L, P, (P-(R+L))/P * 100
310 FOR Y = 1 TO 5
315 LET P = 1.12 * P
320 LET R = 1.03 * R
330 LET L = 1.15 * L
340 PRINT Y; R, L, R+L, P, (P-(R+L))/P * 100
350 NEXT Y
999 END
Of course, there are some things that we would probably change now. For example, there are “magic numbers” sprinkled throughout. The inflation rate for price is 12%, for raw materials 3%, and for laber, 15%. See lines 315-330. The margin calculation is done as part of the print statement, probably because there were no user functions in this version of BASIC. One letter variables have fallen out of favor.
A possible Forth version
OK, let’s tackle this in Forth. It’s a challenge! First off, we need to handle percentages and cents in a language without support for floating point numbers.
```forth
\ 100 * profit / price = % profit or margin
: tab 9 emit ; : .00 0 <# # # [char] . hold #s #> type space ; : .% [char] % emit ;
10000 value price 5600 value materials 2100 value labor
107 value price+ 103 value materials+ 115 value labor+
: % ( n percent – n ) 100 / ; : cost labor materials + ; : profit price cost - ; : margin 100 profit price / ; : header ( –) cr .” YR MATL LABOR TOT COST PRICE MARGIN” cr ;
: scenario header 6 0 do i . tab materials .00 tab labor .00 tab cost .00 tab price .00 tab margin 6 u.r .% cr price price+ % to price materials materials+ % to materials labor labor+ % to labor loop ;