home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / forth / compiler / fpc / source / l3p150.seq < prev    next >
Encoding:
Text File  |  1988-11-06  |  2.3 KB  |  73 lines

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