home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / forth / compiler / fpc / tutor / l1p140 < prev    next >
Text File  |  1990-05-16  |  3KB  |  93 lines

  1.       ╔════════════════════════════════════════════════════════╗
  2.       ║   Lesson 1 Part 14.0  F-PC 3.5 Tutorial by Jack Brown  ║
  3.       ╚════════════════════════════════════════════════════════╝
  4.  
  5. This is the last part of Lesson 1!   Have you purchased your copy of
  6. Starting Forth (2nd Edition) by Leo Brodie yet?  Please get your copy
  7. soon so we can give you a reading assignment.
  8.  
  9.                   ┌────────────────────┐
  10.                   │   Stack Pictures.  │
  11.                   └────────────────────┘
  12.  
  13. If we want to add two numbers together using Forth we would type:
  14.  
  15. <n1> <n2>  +  <enter>
  16.  
  17. Where <n1> and <n2> represent any two numbers.  The answer or sum of n1
  18. and n2 is left on the parameters stack.  Lets call the sum <n>= <n1+n2>.
  19. We could look at the sum <n> using the stack print operator  " .S " or
  20. we could just print the answer to the display screen using " . "
  21.  
  22. Forth programmers like to provide a picture depicting the "before" and
  23. "after" state of the parameter stack in the form of a comment.  To
  24. illustrate what + does one would write:
  25.  
  26.  +   ( n1 n2 -- n )   or  ( n1 n2 -- sum )  or  ( n1 n2 -- n1+n2 )
  27.  
  28. The double dash " -- " separates the stack inputs ( the before state )
  29. and the stack output ( the after state ).  You could also think of the
  30. double dash " -- " as representing the execution of the word " + ".
  31.  
  32. Here are the stack pictures for some of the other words that we
  33. investigated.
  34.  
  35.  -  ( n1 n2 -- n )   or  ( n1 n2 -- n1-n2 )  or ( n1 n2 -- diff )
  36.  *  ( n1 n2 -- n )   or  ( n1 n2 -- n1*n2 )  or ( n1 n2 -- prod )
  37.  /  ( n1 n2 -- n )   or  ( n1 n2 -- n1/n2 )  or ( n1 n2 -- quot )
  38.  
  39. MAX ( n1 n2 -- n )   or  ( n1 n2 -- max )
  40. MIN ( n1 n2 -- n )   or  ( n1 n2 -- min )
  41.  
  42.  .  ( n -- )     <--- only one stack input and it is consumed!
  43.  
  44.              ┌───────────────────────────────────┐
  45.              │  Our Last Program of Lesson One.  │
  46.              └───────────────────────────────────┘
  47.  
  48. Type all of the following into the file CHKBOOK.SEQ
  49. \ Program: Check Book Register Program.
  50. \ Version: 1
  51. \ Date:    September 5, 1986
  52. \ Author:  <your name>
  53.  
  54. \ Log of Changes and Modifications.
  55. \ JWB 22 09 88  Converted from L&P F83 Blocks to F-PC
  56.  
  57. \ Print balance forward.
  58. : .BF  ( bal -- bal )
  59.        5 SPACES DUP  .  CR ;
  60.  
  61. \ Display amount of next entry and the new subtotal.
  62. : +.  ( s1 n -- s2)
  63.       DUP    .   +
  64.       DUP    .  CR ;
  65.  
  66. \ Done with this months checks, print the new total.
  67. : DONE ( s -- )
  68.        CR  ." ====================================="
  69.        CR  ."  You have . . . . "  .  ."  dollars left." CR ;
  70.  
  71. \ Run the check book program on the data that starts on line 30 of
  72. \ this file!
  73. : CHECK-BOOK ( -- )
  74.         30  LOAD ;   \ Refers to line 30 below ********
  75.  
  76. \S  This is a comment to the end of the file.
  77. \ This must be line 30 of the program *****************
  78. \ My checking account.  CHECK-BOOK starts loading again at this point.
  79. CR
  80. .( Balance forward )    1000   .BF
  81. .( Pay Check       )    1200   +.
  82. .( Mortgage        )    -500   +.
  83. .( Hydro           )    -120   +.
  84. .( Food            )    -200   +.
  85. .( Telephone       )     -25   +.
  86. .( Entertainment   )     -15   +.
  87. .( Car Payment     )    -300   +.
  88. DONE
  89.  
  90. ┌───────────────────────────────────┐
  91. │ Please move to Lesson 1 Part 15.0 │
  92. └───────────────────────────────────┘
  93.