home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / forth / compiler / fpc / tutor / l3p150 < prev    next >
Text File  |  1990-07-15  |  3KB  |  77 lines

  1.        ╔════════════════════════════════════════════════════╗
  2.        ║ Lesson 3 Part 150  F-PC 3.5 Tutorial by Jack Brown ║
  3.        ╚════════════════════════════════════════════════════╝
  4.  
  5. \ Here is another way to write SPEED_CHECK .  This time the messages
  6. \ are built into the speed interval words.  This factoring has the
  7. \ disadvantage that all intervals are checked even when one of the
  8. \ one the very_slow message has been printed.  There would be no
  9. \ advantage to changing the order of the lines in the word
  10. \ SPEED_CHECK as every interval would be checked anyway!
  11.  
  12. \            Message                              Speed range kmph
  13. \           -----------                          ------------------
  14. \ " issue ticket,    impeding traffic flow."            0   -  15
  15. \ " issue warning,   impeding traffic flow."           16   -  30
  16. \ " no action,       safe speed."                      31   -  55
  17. \ " issue warning,   exceeding speed limit."           56   -  65
  18. \ " issue ticket,    exceeding speed limit."           66   -  99
  19. \ " arrest motorist, dangerous driving."              100   -
  20.  
  21. \ Display ticket msg ifis speed is very slow  0 - 15 kmph
  22. : VERY_SLOW? ( speed --)
  23.         0 15 [IN]
  24.         IF   ." Issue ticket,    impeding traffic flow."
  25.         THEN ;
  26.  
  27.  
  28. \ Display warning msg if speed is slow  16 - 30 kmph
  29. : SLOW? ( speed --)
  30.        16 30 [IN]
  31.         IF   ." Issue warning,   impeding traffic flow."
  32.         THEN ;
  33.  
  34. \ Display no action msg if speed is normal  31 - 55 kmph
  35. : NORMAL? ( speed --)
  36.        31 55 [IN]
  37.        IF   ." No action,       safe speed."
  38.        THEN ;
  39.  
  40.  
  41. \ Display warning msg if speed is fast    56 - 65 kmph
  42. : FAST? ( speed --)
  43.        56 65 [IN]
  44.        IF   ." Issue warning,   exceeding speed limit."
  45.        THEN ;
  46.  
  47.  
  48. \ Display ticket msg if spped is very fast  66- 99 kmph
  49. : VERY_FAST? ( speed --)
  50.        66 99 [IN]
  51.        IF   ." Issue ticket,    exceeding speed limit."
  52.        THEN ;
  53.  
  54. \ Display arrest msg if speed is dangerous   100 kmph and over.
  55. : DANGEROUS? ( speed -- )
  56.        100 200 [IN]
  57.        IF   ." Arrest motorist, dangerous driving."
  58.        THEN ;
  59.  
  60. \ Display broken msg if speed is invalid, negative or > 200 kmph.
  61. : BROKEN? ( speed -- )
  62.        DUP 0< SWAP 200 > OR
  63.        IF  ." Super-F Radar Gun is broken"
  64.        THEN ;
  65.  
  66. \ Check speed and print appropriate message.
  67. : SPEED_CHECK ( speed -- )
  68.     DUP VERY_SLOW?
  69.     DUP SLOW?
  70.     DUP NORMAL?
  71.     DUP FAST?
  72.     DUP VERY_FAST?
  73.     DUP DANGEROUS?
  74.     DUP BROKEN?
  75.     DROP ;
  76.  
  77.