home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / forth / compiler / fpc / source / l3p090.seq < prev    next >
Text File  |  1990-04-01  |  3KB  |  68 lines

  1. \ Lesson 3 Part 9  ( F-PC 3.5 Tutorial by Jack Brown )
  2.  
  3. COMMENT:
  4. Consider the following scenario:
  5. We are writing a program for the Super-F Radar Gun  (used for checking
  6. the speed of motor vehicles).  We word that will take the vehicle speed
  7. as a stack input and print one of the following messages when the speed
  8. limit is 50 kmph.
  9.  
  10.             Message                              Speed range kmph
  11.  
  12. " issue ticket,    impeding traffic flow."           0   -  15
  13. " issue warning,   impeding traffic flow."          16   -  30
  14. " no action,       safe speed."                      31   -  55
  15. " issue warning,   exceeding speed limit."           56   -  65
  16. " issue ticket,    exceeding speed limit."           66   - 100
  17. " arrest motorist, dangerous driving."              100   -
  18.  
  19. By the way... we are going to use kilometers per hour to measure the
  20. speed.  Do all our Forth Friends in the good old US of A realize that if
  21. the Canada - US Free Trade Deal goes through that they will have to
  22. switch to the metric system for all weights and measures??
  23. Note:  30 kmph = 18 mph, 50 kmph = 30 mph,  100 kmph = 60 mph  etc.
  24.  
  25. Let's see how should we proceed....  Oh..  Let's use our interval testing
  26. words..  Remember  [IN] and the rest of the family?
  27. COMMENT;
  28.  
  29. \ Leave true flag is speed is very slow  0 - 15 kmph
  30. : VERY_SLOW? ( speed -- flag)  0 15 [IN] ;
  31.  
  32. \ Leave true flag if speed is slow  16 - 30 kmph
  33. : SLOW? ( speed -- flag )      16 30 [IN] ;
  34.  
  35. \ Leave true flag if speed is normal  31 - 55 kmph
  36. : NORMAL? ( speed -- flag )    31 55 [IN] ;
  37.  
  38. \ Leave true flag if speed is fast    56 - 65 kmph
  39. : FAST? ( speed -- flag )      56 65 [IN] ;
  40.  
  41. \ Leave true flag if speed is very fast  66- 99 kmph
  42. : VERY_FAST? ( speed -- flag ) 66 99 [IN] ;
  43.  
  44. \ Leave true flag if speed is dangerous   100 kmph and over.
  45. : DANGEROUS? ( speed -- flag ) 99 > ;
  46.  
  47. \ Check speed and print appropriate message.
  48. : SPEED_CHECK ( speed -- )
  49.     DUP VERY_SLOW?
  50.     IF   ." Issue ticket,    impeding traffic flow." DROP
  51.     ELSE DUP SLOW?
  52.         IF   ." Issue warning,   impeding traffic flow." DROP
  53.         ELSE  DUP NORMAL?
  54.             IF   ." No action,       safe speed." DROP
  55.             ELSE DUP FAST?
  56.                 IF   ." Issue warning,   exceeding speed limit." DROP
  57.                 ELSE DUP VERY_FAST?
  58.                     IF   ." Issue ticket,    exceeding speed limit." DROP
  59.                     ELSE DANGEROUS?
  60.                         IF   ." Arrest motorist, dangerous driving."
  61.                          THEN
  62.                     THEN
  63.                 THEN
  64.             THEN
  65.         THEN
  66.     THEN ;
  67.  
  68.