home *** CD-ROM | disk | FTP | other *** search
- ╔════════════════════════════════════════════════════════╗
- ║ Lesson 1 Part 14.0 F-PC 3.5 Tutorial by Jack Brown ║
- ╚════════════════════════════════════════════════════════╝
-
- This is the last part of Lesson 1! Have you purchased your copy of
- Starting Forth (2nd Edition) by Leo Brodie yet? Please get your copy
- soon so we can give you a reading assignment.
-
- ┌────────────────────┐
- │ Stack Pictures. │
- └────────────────────┘
-
- If we want to add two numbers together using Forth we would type:
-
- <n1> <n2> + <enter>
-
- Where <n1> and <n2> represent any two numbers. The answer or sum of n1
- and n2 is left on the parameters stack. Lets call the sum <n>= <n1+n2>.
- We could look at the sum <n> using the stack print operator " .S " or
- we could just print the answer to the display screen using " . "
-
- Forth programmers like to provide a picture depicting the "before" and
- "after" state of the parameter stack in the form of a comment. To
- illustrate what + does one would write:
-
- + ( n1 n2 -- n ) or ( n1 n2 -- sum ) or ( n1 n2 -- n1+n2 )
-
- The double dash " -- " separates the stack inputs ( the before state )
- and the stack output ( the after state ). You could also think of the
- double dash " -- " as representing the execution of the word " + ".
-
- Here are the stack pictures for some of the other words that we
- investigated.
-
- - ( n1 n2 -- n ) or ( n1 n2 -- n1-n2 ) or ( n1 n2 -- diff )
- * ( n1 n2 -- n ) or ( n1 n2 -- n1*n2 ) or ( n1 n2 -- prod )
- / ( n1 n2 -- n ) or ( n1 n2 -- n1/n2 ) or ( n1 n2 -- quot )
-
- MAX ( n1 n2 -- n ) or ( n1 n2 -- max )
- MIN ( n1 n2 -- n ) or ( n1 n2 -- min )
-
- . ( n -- ) <--- only one stack input and it is consumed!
-
- ┌───────────────────────────────────┐
- │ Our Last Program of Lesson One. │
- └───────────────────────────────────┘
-
- Type all of the following into the file CHKBOOK.SEQ
- \ Program: Check Book Register Program.
- \ Version: 1
- \ Date: September 5, 1986
- \ Author: <your name>
-
- \ Log of Changes and Modifications.
- \ JWB 22 09 88 Converted from L&P F83 Blocks to F-PC
-
- \ Print balance forward.
- : .BF ( bal -- bal )
- 5 SPACES DUP . CR ;
-
- \ Display amount of next entry and the new subtotal.
- : +. ( s1 n -- s2)
- DUP . +
- DUP . CR ;
-
- \ Done with this months checks, print the new total.
- : DONE ( s -- )
- CR ." ====================================="
- CR ." You have . . . . " . ." dollars left." CR ;
-
- \ Run the check book program on the data that starts on line 30 of
- \ this file!
- : CHECK-BOOK ( -- )
- 30 LOAD ; \ Refers to line 30 below ********
-
- \S This is a comment to the end of the file.
- \ This must be line 30 of the program *****************
- \ My checking account. CHECK-BOOK starts loading again at this point.
- CR
- .( Balance forward ) 1000 .BF
- .( Pay Check ) 1200 +.
- .( Mortgage ) -500 +.
- .( Hydro ) -120 +.
- .( Food ) -200 +.
- .( Telephone ) -25 +.
- .( Entertainment ) -15 +.
- .( Car Payment ) -300 +.
- DONE
-
- ┌───────────────────────────────────┐
- │ Please move to Lesson 1 Part 15.0 │
- └───────────────────────────────────┘
-