home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
forth
/
compiler
/
fpc
/
source
/
l3p090.seq
< prev
next >
Wrap
Text File
|
1990-04-01
|
3KB
|
68 lines
\ Lesson 3 Part 9 ( F-PC 3.5 Tutorial by Jack Brown )
COMMENT:
Consider the following scenario:
We are writing a program for the Super-F Radar Gun (used for checking
the speed of motor vehicles). We word that will take the vehicle speed
as a stack input and print one of the following messages when the speed
limit is 50 kmph.
Message Speed range kmph
" issue ticket, impeding traffic flow." 0 - 15
" issue warning, impeding traffic flow." 16 - 30
" no action, safe speed." 31 - 55
" issue warning, exceeding speed limit." 56 - 65
" issue ticket, exceeding speed limit." 66 - 100
" arrest motorist, dangerous driving." 100 -
By the way... we are going to use kilometers per hour to measure the
speed. Do all our Forth Friends in the good old US of A realize that if
the Canada - US Free Trade Deal goes through that they will have to
switch to the metric system for all weights and measures??
Note: 30 kmph = 18 mph, 50 kmph = 30 mph, 100 kmph = 60 mph etc.
Let's see how should we proceed.... Oh.. Let's use our interval testing
words.. Remember [IN] and the rest of the family?
COMMENT;
\ Leave true flag is speed is very slow 0 - 15 kmph
: VERY_SLOW? ( speed -- flag) 0 15 [IN] ;
\ Leave true flag if speed is slow 16 - 30 kmph
: SLOW? ( speed -- flag ) 16 30 [IN] ;
\ Leave true flag if speed is normal 31 - 55 kmph
: NORMAL? ( speed -- flag ) 31 55 [IN] ;
\ Leave true flag if speed is fast 56 - 65 kmph
: FAST? ( speed -- flag ) 56 65 [IN] ;
\ Leave true flag if speed is very fast 66- 99 kmph
: VERY_FAST? ( speed -- flag ) 66 99 [IN] ;
\ Leave true flag if speed is dangerous 100 kmph and over.
: DANGEROUS? ( speed -- flag ) 99 > ;
\ Check speed and print appropriate message.
: SPEED_CHECK ( speed -- )
DUP VERY_SLOW?
IF ." Issue ticket, impeding traffic flow." DROP
ELSE DUP SLOW?
IF ." Issue warning, impeding traffic flow." DROP
ELSE DUP NORMAL?
IF ." No action, safe speed." DROP
ELSE DUP FAST?
IF ." Issue warning, exceeding speed limit." DROP
ELSE DUP VERY_FAST?
IF ." Issue ticket, exceeding speed limit." DROP
ELSE DANGEROUS?
IF ." Arrest motorist, dangerous driving."
THEN
THEN
THEN
THEN
THEN
THEN ;