home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
forth
/
compiler
/
fpc
/
source
/
p3_20dc.seq
< prev
next >
Wrap
Text File
|
1990-04-05
|
2KB
|
68 lines
\ Answer for problem 3.10 by Dickson Cheng 04/04/90 21:30:34.56
\ (IN) leaves a true flag if a < x < b , otherwise false.
: (IN) ( x a b -- flag )
OVER 1 PICK > IF SWAP THEN
-ROT OVER < -ROT > AND ;
\ [IN] leaves a true flag if a <= x <= b
: [IN] ( x a b -- flag )
1+ SWAP 1- SWAP (IN) ;
\ Leaves true flag if speed < 0
: BROKEN? ( speed -- flag ) 0< ;
\ Leaves true flag if speed is between 0 to 15 kmph
: VERY_SLOW? ( speed -- flag ) 0 15 [IN] ;
\ Leaves true flag if speed is between 16 to 30 kmph
: SLOW? ( speed -- flag ) 16 30 [IN] ;
\ Leaves true flag if speed is between 31 to 55 kmph
: NORMAL? ( speed -- flag ) 31 55 [IN] ;
\ Leaves true flag if speed is between 56 to 65 kmph
: FAST? ( speed -- flag ) 56 65 [IN] ;
\ Leaves true flag if speed is between 66 to 99 kmph
: VERY_FAST? ( speed -- flag ) 66 99 [IN] ;
\ Leaves true flag if speed is between 100 to 199
: DANGEROUS? ( speed -- flag ) 100 199 [IN] ;
\ Leaves true flag if speed is over 199
: DEADLY? ( speed -- flag ) 199 > ;
\ Check speed and print appropriate message
: SPEED_CHECK ( speed -- )
DUP BROKEN?
IF ." Impossible speed, must be something wrong!" DROP
ELSE 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 DUP DANGEROUS?
IF ." Arrest motorist, dangerous driving." DROP
ELSE DUP DEADLY?
IF ." Deadly serious, got to catch him."
THEN
THEN
THEN
THEN
THEN
THEN
THEN
THEN ;