[comp.lang.forth] F-PC Forth Tutorial

ForthNet@willett.UUCP (ForthNet articles from GEnie) (03/06/90)

 Date: 03-04-90 (12:49)              Number: 503 (Echo)
   To: JACK BROWN                    Refer#: NONE
 From: JUDE DASHIELL                   Read: NO
 Subj: 2ND HOMEWORK ASSIGNMENT       Status: PUBLIC MESSAGE

 \ 2nd homework assignment to run type initials
 \ from: Mr. Jude T. DaShiell 3/4/1990.
 : l1 177 emit ;
 : l2 9 0 ;
 : l3 8 0 ;
 : l4 7 0 ;
 : l5 6 0 ;
 : l6 5 0 ;
 : l7 4 0 ;
 : l8 3 0 ;
 : l9 l2 do space loop ;
 : l10 l4 do space loop ;
 : l11 l5 do space loop ;
 : l12 l6 do space loop ;
 : l13 l2 do l1 loop space ;
 : l14 l3 do l1 loop cr ;
 : l15 l4 do l1 loop ;
 : l16 l13 l13 l14 ;
 : l17 l12 l1 ;
 : l18 l9 l1 ;
 : l19 l10 l1 ;
 : l20 l9 l1 cr ;
 : l21 l17 l18 l19 l20 ;
 : l22 l4 do l20 loop ;
 : l23 l1 l8 ;
 : l24 l1 l9 ;
 : l25 l1 l12 ;
 : l26 l1 l10 ;
 : l27 l1 cr ;
 : l28 l23 l24 l25 l26 l27 ;
 : l29 space l15 l11 l1 l12 l14 cr ;
 : initials l16 l22 l28 l29 ;
-----
This message came from GEnie via willett through a semi-automated process.
Report problems to: 'uunet!willett!dwp' or 'willett!dwp@gateway.sei.cmu.edu'

ForthNet@willett.UUCP (ForthNet articles from GEnie) (03/06/90)

 Date: 03-05-90 (00:08)              Number: 504 (Echo)
   To: JACK BROWN                    Refer#: NONE
 From: JUDE DASHIELL                   Read: NO
 Subj: 2ND HOMEWORK ASSIGNMENT       Status: PUBLIC MESSAGE

 \ 2nd homework assignment to run type initials <cr>
 \ from: Jude T. DaShiell 3/5/1990.
 : l1 cr cr 2 0 do 9 0 do 35 emit loop space loop 8 0 do 35 emit
    loop cr ;
 : l2 7 0 do 4 0 do space loop 35 emit 9 0 do space loop 35 emit
    5 0 do space loop 35 emit 7 0 do space loop 35 emit cr loop ;
 : l3 3 0 do 35 emit 3 0 do space loop 35 emit 9 0 do space loop
    35 emit 5 0 do space loop 35 emit cr loop ;
 : l4 space 3 0 do 35 emit loop 6 0 do space loop 35 emit 5 0 do
    space lspace loop 8 0 do 35 emit loop cr cr ;
 : initials l1 l2 l3 l4 ;
-----
This message came from GEnie via willett through a semi-automated process.
Report problems to: 'uunet!willett!dwp' or 'willett!dwp@gateway.sei.cmu.edu'

ForthNet@willett.UUCP (ForthNet articles from GEnie) (03/08/90)

 Date: 03-06-90 (10:46)              Number: 506 (Echo)
   To: ALL                           Refer#: NONE
 From: JUDE DASHIELL                   Read: (N/A)
 Subj: DATA BASE ASSIGMENT - 2       Status: PUBLIC MESSAGE

 TO:  Jack Brown
 FROM:  Mr. Jude T. DaShiell
 SUBJECT:  database homework assignment  Part 2

  An example of the calculations involved before anything
 goes into the database is as follows:

 Givens:
 DATE--September 19, 1989,
 FLIGHT--1672

 9+1+9+1+9+8+9=46
 4+6=10
 1+0=1
 Date Value=1

 1+6+7+2=16
 1+6=7
 Flight Value=7
 Correspondence in above table=-1 or discordant.

 Now down to forth:
 The first word I am defining is airtable and its purpose is to show the
 available flights that have been documented in this database: If it
 works the way I wanted it to, you just type airtable cr to see the
 available flights.

 : airtable cr
 ." AVAILABLE AIR CRASHES ARE: " cr
 ." FLIGHT 1672 " cr
 ." FLIGHT 5050 " cr ;

 : FLIGHT1672 CR
 ." FLIGHT 1672 DATE SEPTEMBER 19, 1989 " CR
 ." FLIGHT VALUE 7 DATE VALUE 1 " CR
 ." FORECASE VALUE -1 " CR ;

 : FLIGHT5050 CR
 ." FLIGHT 5050 DATE SEPTEMBER 20, 1989 " CR
 ." FLIGHT VALUE 1 DATE VALUE 2 " CR
 ." FORECAST VALUE -1 " CR ;

 I hope this is interesting enough for your collection.

 One note about the language operation on my computer and this has to do
 with the speech synthesizer.  I normally use the word slow for operation
 of the language.  I find that when I run these words the output to my
 speech synthesizer slows down very much when numbers are spoken by the
 forth language.  I don't know why this should be but the frequency of
 the speech synthesizer is lowered and under dos after the forth language
 is run the same thing happens each time I hit a decimal point or period
 key. Have you any ideas for a fix? We can get the active cooperation of
 artic technologies on this matter if necessary since any software
 developer willing to work with Artic will be warmly welcomed.

 Mr. Jude T. DaShiell

 P.S.
 Sorry about the delay in turning this assignment in, work got very busy
 and I just got my head out from under recently.  The work is down to a
 steady frantic now and will probably remain their for awhile.

 NET/Mail : British Columbia Forth Board - Burnaby BC - (604)434-5886   
-----
This message came from GEnie via willett through a semi-automated process.
Report problems to: 'uunet!willett!dwp' or 'willett!dwp@gateway.sei.cmu.edu'

ForthNet@willett.UUCP (ForthNet articles from GEnie) (03/12/90)

 Date: 03-10-90 (16:57)              Number: 413 (Echo)
   To: JACK BROWN                    Refer#: NONE
 From: KENNETH O'HESKIN                Read: NO
 Subj: BYTE ARRAY PUZZEL             Status: PUBLIC MESSAGE

         Jack,

         I'm posting my solution to your BYTE_AVG puzzel, my first crack
         at using the Forth HC11 assembler.  Pretty straightforward,
         but getting the correct comparator in the BEGIN...UNTIL loop
         hung me up for awhile. In your examples you don't seem to use
         any before the branch op (0=, U>=, whatever..) whereas in mine
         I had to explicitly declare  < memory location >  CPX, before
         it worked.  Question, do the branch operators get thier parms
         from the registers immediately before it, whether they are
         compare instructions or not?

         I'd like to work on the other puzzels, but Assignment 2 is
         giving me grim looks so I'd better get to it.

         Regards, -Ken-
 ---
  ~ EZ 1.26 ~ x

 NET/Mail : British Columbia Forth Board - Burnaby BC - (604)434-5886   
-----
This message came from GEnie via willett through a semi-automated process.
Report problems to: 'uunet!willett!dwp' or 'willett!dwp@gateway.sei.cmu.edu'

ForthNet@willett.UUCP (ForthNet articles from GEnie) (03/12/90)

 Date: 03-10-90 (16:57)              Number: 414 (Echo)
   To: JACK BROWN                    Refer#: NONE
 From: KENNETH O'HESKIN                Read: NO
 Subj: BYTE ARRAY PUZZEL             Status: PUBLIC MESSAGE

 ( BYTE_AVG  ( addr-byte array, n-size -- average )

 ( : -ROT   ROT ROT ;  )
 ( : TUCK              )
 (       DUP 2 -ROLL ; )

 ( High level definition )
 ( : BYTE_AVG   ( addr n -- average )
 (         TUCK                     )
 (         OVER + SWAP              )
 (         0 -ROT                   )
 (           DO  I C@ + LOOP        )
 (         SWAP / ;                 )

 ( Use:  DATA N BYTE_AVG . <CR>  )


 HEX
 ( 70 CONSTANT RMW   ( Reserve a variable in direct page memory )
 ( Is it cheating to declare an external variable? )
 ( If there's any danger of colliding with other data we can increment )
 ( the stack by a word and use it as a workspace; I think d p memory   )
 ( should only be used for local variables and the stack anyway.       )

 ( Code definition )
 CODE BYTE_AVG  ( addr n -- )

         2 ,Y    LDD,        ( load byte array addr d  )
         0 ,Y    ADDD,       ( add size to d           )
         70  DIR STD,        ( store loop limit in RMW )

         2 ,Y    LDX,        ( load index x with base adr  )
                 CLRA,       ( init d to hold current byte )
                 CLRB,

   BEGIN,
         0 ,X    ADDB,       ( accumulate total     )
         0 #,    ADCA,
                 INX,        ( increment addr       )
         70  DIR CPX,        ( 5 cycles, gulp!      )
                 U>=,        ( continue until x=RMW )
   UNTIL,

         0 ,Y    LDX,
                 IDIV,       ( yowl!                 )

                 INY,        ( dec stack by one word )
                 INY,
         0 ,Y    STX,        ( leave result on tos   )
                 NEXT
 END-CODE
 DECIMAL

 ( Approximate 11 times faster than hi-level definition for averaging )
 ( an 8k byte array, looped 10 times . )

 ---
  ~ EZ 1.26 ~ 

 NET/Mail : British Columbia Forth Board - Burnaby BC - (604)434-5886   
-----
This message came from GEnie via willett through a semi-automated process.
Report problems to: 'uunet!willett!dwp' or 'willett!dwp@gateway.sei.cmu.edu'

ForthNet@willett.UUCP (ForthNet articles from GEnie) (04/11/90)

 Date: 04-07-90 (12:21)              Number: 510 (Echo)
   To: PAUL BRANNON                  Refer#: 509
 From: JACK BROWN                      Read: 04-08-90 (21:31)
 Subj: RELEARNING FORTH              Status: PUBLIC MESSAGE

 >I was starting the lessons last spring when my son was born, and time
 >has been short since then. I finally have time again to learn Forth. I 
 >hope you don't mind if I resume where I left off, which was near the
 >end of lesson 2. The word below is my attempt to calculate the area of
 >a circle. It works except for printing the decimal point. Also I could

 I noticed in the output that the decimal point did not appear.  This may
 not be your problem as is versions of F-PC from 2.15 on up the phrase
 8 EMIT would not back up the cursor by one as was intended.

 Instead of using 8 EMIT  you mut use 1 BACKSPACES.  

 I am curently updating the tutorials to F-PC 3.5 but have not yet
 uploaded any of the changed lessons yet.  The problem you are working on
 is 2.17 in the revised lessons and here is the problem and your solution
 using 1 BACKSPACES.  First the corrected triangle program.

 : TRIANGLE_AREA ( b h --)
        2DUP SWAP
        CR ." Base =   "  .
           ." Height = "  .
           * 2 /MOD
           ." Area = " .
           1 BACKSPACES ( 8  EMIT  does not back up cursor in F-PC)
           ASCII . EMIT
           IF    ASCII 5 EMIT
           ELSE  ASCII 0 EMIT
           THEN ;

 COMMENT:
 Problem 2.17.
 a) What do you observe when you use 5 and 3 for the base and height?
 b) What do you observe when you use 5 and 4 for the base and height?
 c) Explain in detail why you get the result you see for question 1.
 d) Could you modify the idea contained in the above to compute the Area
 of a circle to three decimal places?  Hint:  It can be done quite easily
 and if you can do it you have the potential to become a Forth Super 
 Star!

 Solution to Problem 2.17

 a) What do you observe for output of triangle program
    with  5 3 AREA?  Answer:
 Base =   5 Height = 3 Area = 7.5

 b) What about  5 4 AREA ?  Answer:
 Base =   5 Height = 4 Area = 10.0

 c) Why the decimal result for question one when we only have
    integer math?  Answer:  Because if the remainder from the
    /MOD operation is 1 we can display the .5, if the remainder
    is 0 then we can display the required .0

 d) Computer area of a circle to three decimal places.

 COMMENT;

 \ Compute area of a circle to three decimal places.
 : CIRCLE_AREA ( r -- )
         DUP * 355 * 113 /MOD
         ." Area = " . ( 8 EMIT ) 1 BACKSPACES ASCII . EMIT
         5 0 DO
             10 * 113 /MOD . ( 8 EMIT ) 1 BACKSPACES
             LOOP DROP ;

 : TEST_CIRC ( -- )
        8 0 DO CR I CIRCLE_AREA LOOP ;

 NET/Mail : British Columbia Forth Board - Burnaby BC - (604)434-5886   
-----
This message came from GEnie via willett through a semi-automated process.
Report problems to: 'uunet!willett!dwp' or 'willett!dwp@gateway.sei.cmu.edu'

ForthNet@willett.UUCP (ForthNet articles from GEnie) (04/11/90)

 Date: 04-08-90 (10:23)              Number: 511 (Echo)
   To: PAUL BRANNON                  Refer#: 509
 From: JACK BROWN                      Read: NO
 Subj: RELEARNING FORTH              Status: PUBLIC MESSAGE

 >end of lesson 2. The word below is my attempt to calculate the area of
 >a circle. It works except for printing the decimal point. Also I could
 >not round the answer when appropriate. Any suggestions or comments? 

 > \ word for calculating circle area to 3 decimals    
 > : circle_area    ( r -- )
 >     dup * 355 * 113 /mod
 >    ." area = " . ascii . emit
 >    5 0 do
 >        10 * 113 /mod 8 emit .
 >    loop drop ;

 Hi Paul,  I was thinking about your solution and really like your 
 application of /MOD to compute each decimal digit.  I don't really
 like the 1 BACKSPACES  required by F-PC in place of  8 EMIT because
 although clear it is not Forth 83 Standard.  Also the use of */MOD
 in the first line of CIRC_AREA will allow a greater range of radii.
 To get around the  1 BACKSPACES we can use the  right justified display 
 operator which  we present in lesson 3.

 \ Alternate to Problem 2.17 (d)

 \ In this solution we use the right justified display operator .R
 \ to avoid the use of 1 BACKSPACES which was used to back up over
 \ the trailing blank that  .   provides.
 \ We have also replaced the phrase  355 * 113 /MOD
 \ with the phrase  355 113 */MOD  for a greater range of radii.
 \ */MOD   will first multiply by 355 leaving a 32 bit intermediate
 \ product and then divide this 32 bit product by 113.


 \ Compute area of a circle to three decimal places.
 : CIRCLE_AREA ( r -- )
         DUP * 355 113 */MOD
         ." Area = " 5 .R        \ ( 8 EMIT ) 1 BACKSPACES
         ASCII . EMIT
         5 0  DO
              10 * 113 /MOD 1 .R \ ( 8 EMIT ) 1 BACKSPACES
              LOOP DROP ;

 : TEST_CIRC ( -- )
        11 1 DO CR I CIRCLE_AREA LOOP ;


 I just thought of an even better solution than   using

    1  .R

 How about just replacing   1. R  with

    48  +  EMIT

 Can you explain why this will work??

 NET/Mail : British Columbia Forth Board - Burnaby BC - (604)434-5886   
-----
This message came from GEnie via willett through a semi-automated process.
Report problems to: 'uunet!willett!dwp' or 'willett!dwp@gateway.sei.cmu.edu'

ForthNet@willett.UUCP (ForthNet articles from GEnie) (05/03/90)

 Date: 05-01-90 (17:10)              Number: 3180 (Echo)
   To: JACK BROWN                    Refer#: NONE
 From: CHRIS WATERS                    Read: NO
 Subj: F-PC TUTORIAL                 Status: PUBLIC MESSAGE

    Hello Jack, from one of the people out in MetroNet land.  I'm afraid
 that since I'm no novice at Forth, I didn't read your tutorial, but I
 was still happy to see it there.  I like the idea of having some posts
 that present a basic introduction to Forth, to help novices and
 curiousity seekers find out what Forth is about.  Especially in
 something like the MetroNet, where conferences are available on a wide
 variety of topics, this sort of thing can be very useful.

    I would like to comment that the MetroNet board I call has absolutely
 no Forth-related files, except a copy of F83 (v2.18) which I uploaded.
 F-PC is not available here; is this a shareware or PD product?  (Yeah, I
 know, I should have read the tutorial, it probably would have told me.
 I download messages, and already deleted it to save disk space.  Sorry.)

 Chris

 -> MegaMail(tm) #0:~ Artificial Stupidity Conference Host
    1.13

 PCRelay:SNAKEPIT -> RelayNet (TM)
 4.10a14             The Snake Pit - (408)287-2353 - San Jose, CA
-----
This message came from GEnie via willett through a semi-automated process.
Report problems to: 'uunet!willett!dwp' or 'willett!dwp@gateway.sei.cmu.edu'

ForthNet@willett.UUCP (ForthNet articles from GEnie) (05/03/90)

 Date: 05-01-90 (16:24)              Number: 3182 (Echo)
   To: JACK BROWN                    Refer#: 3155
 From: IAN GREEN                       Read: NO
 Subj: F-PC TUTORIAL                 Status: PUBLIC MESSAGE

    I found your tutorial quite good. Easy to read and follow. Perhaps 
 though you could, in addition to posting the tutorials, you could also 
 make them available for downloading for those who have the capability of
 doing so. Do not however stop posting the lessons as those who cannot 
 download because they are on the net or on a diferent net would loose a 
 valuable training session.

 Ian

 NET/Mail : British Columbia Forth Board - Burnaby BC - (604)434-5886   
-----
This message came from GEnie via willett through a semi-automated process.
Report problems to: 'uunet!willett!dwp' or 'willett!dwp@gateway.sei.cmu.edu'

ForthNet@willett.UUCP (ForthNet articles from GEnie) (05/06/90)

 Date: 05-03-90 (23:49)              Number: 3199 (Echo)
   To: JACK BROWN                    Refer#: 3191
 From: JERRY SHIFRIN                   Read: NO
 Subj: F-PC TUTORIAL                 Status: PUBLIC MESSAGE

 JB>I would prefer that they appear in a form where interaction is possib
 JB>and would prefer that the messages stay around for longer than one we

 It sounds like there is some MetroLink interest in your tutorial
 even if it isn't huge.  Why not diddle around with lesson #1 for
 a while longer, maybe repost here if some new people express
 interest, and later plan on sending the tutorial out to both
 MetroLink and Forthnet conferences.  This would allow the few
 remote folks to get the messages and also place them in our
 semi-permanent Tutorial area.
 ---
  ~ EZ 1.26 ~ 
-----
This message came from GEnie via willett through a semi-automated process.
Report problems to: 'uunet!willett!dwp' or 'willett!dwp@gateway.sei.cmu.edu'

ForthNet@willett.UUCP (ForthNet articles from GEnie) (05/09/90)

 Date: 05-06-90 (23:24)              Number: 2 (Echo)
   To: JACK BROWN                    Refer#: NONE
 From: PAUL BRANNON                    Read: NO
 Subj: L. 3, P. 3 EXERCISES          Status: PUBLIC MESSAGE

 Jack,
     Here are some more solutions to the exercises. (More to come)
                                      Paul
 \ exercise 3.7 single number display operator table
 : 1table        ( n -- )
         cr 1 spaces
            ."     unsigned " ."       signed " ."     unsigned "
            ."       signed " ."     unsigned " ."       signed "
         cr 1 spaces
            ."      decimal " ."      decimal " ."        otcal "
            ."        octal " ."         hex  " ."         hex  "
         20 0 do
                 cr
                 decimal dup 13 u.r
                         dup 13  .r
                 octal   dup 13 u.r
                         dup 13  .r
                 hex     dup 13 u.r
                         dup 13  .r
                 1 + loop drop decimal cr ;

 \ output below is from word above
 -9 1table
    unsigned      signed    unsigned      signed    un91gned      signed
     decimal     decimal       otcal       octal        hex          hex
       65527          -9      177767         -11        FFF7          -9
       65528          -8      177770         -10        FFF8          -8
       65529          -7      177771          -7        FFF9          -7
       65530          -6      177772          -6        FFFA          -6
       65531          -5      177773          -5        FFFB          -5
       65532          -4      177774          -4        FFFC          -4
       65533          -3      177775          -3        FFFD          -3
       65534          -2      177776          -2        FFFE          -2
       65535          -1      177777          -1        FFFF          -1
           0           0           0           0           0           0
           1           1           1           1           1           1
           2           2           2           2           2           2
           3           3           3           3           3           3
           4           4           4           4           4           4
           5           5           5           5           5           5
           6           6           6           6           6           6
           7           7           7           7           7           7
           8           8          10          10           8           8
           9           9          11          11           9           9
          10          10          12          12           A           A

 \ lesson 3, part 4, exercise 3.8
 : binary   ( -- )       2 base ! ;
 : .h       ( n -- )     hex . decimal ;
 : u.h      ( n -- )     hex u. decimal ;
 : .o       ( n -- )     octal . decimal ;
 : u.o      ( n -- )     octal u. decimal ;
 : .b       ( n -- )     binary . decimal ;
 : u.b      ( n -- )     binary u. decimal ;
 : test_base_printing   ( -- )
         16 -5 do cr
                 i .
                 i u.
                 i .h
                 i u.h
                 i .o
                 i u.o
                 i .b
                 i u.b loop cr ;

 The base value is reset to decimal after each word to make sure that
 sure that the stack is a familiar base, without suprises. Since each
 word resets the base value to decimal, there is not a need within
 these words, but if there are words for printing binary, octal, and
 hexadecimal values, there should be one for printing decimal values,
 since the current base cannot always be assumed to be decimal.

 test_base_printing
 -5 65531 -5 FFFB -5 177773 -101 1111111111111011
 -4 65532 -4 FFFC -4 177774 -100 1111111111111100
 -3 65533 -3 FFFD -3 177775 -11 1111111111111101
 -2 65534 -2 FFFE -2 177776 -10 1111111111111110
 -1 65535 -1 FFFF -1 177777 -1 1111111111111111
 0 0 0 0 0 0 0 0
 1 1 1 1 1 1 1 1
 2 2 2 2 2 2 10 10
 3 3 3 3 3 3 11 11
 4 4 4 4 4 4 100 100
 5 5 5 5 5 5 101 101
 6 6 6 6 6 6 110 110
 7 7 7 7 7 7 111 111
 8 8 8 8 10 10 1000 1000
 9 9 9 9 11 11 1001 1001
 10 10 A A 12 12 1010 1010
 11 11 B B 13 13 1011 1011
 12 12 C C 14 14 1100 1100
 13 13 D D 15 15 1101 1101
 14 14 E E 16 16 1110 1110
 15 15 F F 17 17 1111 1111
-----
This message came from GEnie via willett through a semi-automated process.
Report problems to: 'uunet!willett!dwp' or 'willett!dwp@gateway.sei.cmu.edu'

ForthNet@willett.UUCP (ForthNet articles from GEnie) (05/09/90)

 Date: 05-06-90 (23:28)              Number: 3 (Echo)
   To: JACK BROWN                    Refer#: NONE
 From: PAUL BRANNON                    Read: NO
 Subj: L. 3, P. 4 EXERCISES          Status: PUBLIC MESSAGE

 \ exercise 3.9 single number display operator table using BINARY
 : bitable        ( n -- )
         cr 1 spaces
            ."  unsigned " ."    signed " ."          unsigned "
            ."    signed " ."  unsigned " ."    signed "
         cr 1 spaces
            ."   decimal " ."   decimal " ."            binary "
            ."    binary " ."      hex  " ."      hex  "
         20 0 do
                 cr
                 decimal dup 10 u.r
                         dup 10  .r
                 binary  dup 18 u.r
                         dup 10  .r
                 hex     dup 10 u.r
                         dup 10  .r
                 1 + loop drop decimal cr ;

 -9 bitable
   unsigned    signed          unsigned    signed  unsigned    signed
    decimal   decimal            binary    binary      hex       hex
      65527        -9  1111111111110111     -1001      FFF7        -9
      65528        -8  1111111111111000     -1000      FFF8        -8
      65529        -7  1111111111111001      -111      FFF9        -7
      65530        -6  1111111111111010      -110      FFFA        -6
      65531        -5  1111111111111011      -101      FFFB        -5
      65532        -4  1111111111111100      -100      FFFC        -4
      65533        -3  1111111111111101       -11      FFFD        -3
      65534        -2  1111111111111110       -10      FFFE        -2
      65535        -1  1111111111111111        -1      FFFF        -1
          0         0                 0         0         0         0
          1         1                 1         1         1         1
          2         2                10        10         2         2
          3         3                11        11         3         3
          4         4               100       100         4         4
          5         5               101       101         5         5
          6         6               110       110         6         6
          7         7               111       111         7         7
          8         8              1000      1000         8         8
          9         9              1001      1001         9         9
         10        10              1010      1010         A         A

 \ exercise 3.10, true and false data sets
 : true_set  ( -- )
         cr
         4 4 = u.b cr
         4 5 <> u.b cr
         4 5 < u.b cr
         4 3 > u.b cr
         0 0= u.b cr
         4 0<> u.b cr
         -4 0< u.b cr
         4 0> u.b cr
         true true and u.b cr
         true false or u.b cr
  false not u.b cr ;

 : false_set  ( -- )
         cr
         4 5 = u.b cr
         4 4 <> u.b cr
         4 3 < u.b cr
         4 5 > u.b cr
         2 0= u.b cr
         0 0<> u.b cr
         4 0< u.b cr
         -4 0> u.b cr
         false true and u.b cr
         false false or u.b cr
         true not u.b cr ;

 \ Compute area of a circle to three decimal places (character printing)
 : CIRCLE_AREA ( r -- )
         DUP * 355 113 */MOD
         ." Area = " 5 .r
         ASCII . EMIT
         5 0  DO
              10 * 113 /MOD 48 + emit
              LOOP DROP ;
 : TEST_CIRC ( -- )
        11 1 DO CR I CIRCLE_AREA LOOP ;
 \ > an even better solution than  1 .R  is   48  +  EMIT
 \ > Can you explain why this will work??
 \ This turns the numerical digit into an ASCII character. That's a
 \ pretty good solution. Below is output for modified CIRCLE_AREA
 test_circ
 Area =     3.14159
 Area =    12.56637
 Area =    28.27433
 Area =    50.26548
 Area =    78.53982
 Area =   113.09734
 Area =   153.93805
 Area =   201.06194
 Area =   254.46902
 Area =   314.15929
-----
This message came from GEnie via willett through a semi-automated process.
Report problems to: 'uunet!willett!dwp' or 'willett!dwp@gateway.sei.cmu.edu'

ForthNet@willett.UUCP (ForthNet articles from GEnie) (05/29/90)

 Date: 05-27-90 (14:31)              Number: 14 (Echo)
   To: JACK BROWN                    Refer#: NONE
 From: ROY RICE                        Read: NO
 Subj: LESSON3                       Status: PUBLIC MESSAGE

 Jack: Here is a beginning on lesson 3. I used the f-pc editor and put it
 into seq file format so that I could test it easily while working.
 \ RARL3.seq
 \ Lesson 3 ex.1 -6
 \ Roy Rice, 3848 Fox Glen Ct., Atlanta, Ga.30319   404-451-0079
 comment:
 Jack, I hope that it is OK to jump in at lesson 3. I have had some
 experience with Forth, and think that I am familiar with most of the
 basic words. I do need a lot of work on the more advanced items, though
 and am looking forward to future lessons and the conversion of the
 current ones to version 3.5. Thanks for providing this course!
 comment;

 \ from lesson 3, part 1:
 : .SD ( -- )
      DEPTH ?DUP IF
                  0 ?DO DEPTH I - 1- PICK
                        DEPTH I - 2- PICK
                        D.  8 EMIT ASCII . EMIT
                  2 +LOOP
                 ELSE ." Empty" THEN ;

 \ L3P2, ex 1:
 : .SS ( -- )  \ print all single numbers on stack
      DEPTH ?DUP IF
                  0 ?DO DEPTH I - 1- PICK
                        .  8 EMIT ASCII . EMIT
                  LOOP
                 ELSE ." Empty" THEN ;

 \ L3P2 ex 2:
 : .SD2 ( -- ) \ print stack as double #s if depth is even, as single if 
 odd
         DEPTH  ?DUP  IF
                      2 MOD  ( -- 0|1 ) \ 1 if depth is odd
                         IF  .SS
                         ELSE  .SD   THEN
                 ELSE ." empty"    THEN   ;

 \ L3P2 ex3.3:
 : MY2SWAP ( a, b, c, d -- c, d, a, b)
         3 ROLL 3 ROLL  ;
 : MY2DROP ( a, b -- )
         DROP  DROP  ;
 : MY2DUP  ( a, b -- a, b, a, b )
         OVER OVER  ;
 : MY2OVER ( a, b, c, d -- a, b, c, d, a, b )
         3 PICK 3 PICK  ;
 : MY2NIP  ( a, b, c, d -- c, d )
         ROT DROP ROT DROP  ;
 : MY2TUCK ( d1, d2 -- d2, d1, d2 )
         MY2SWAP MY2OVER ;
 : MY2ROT  ( d1, d2, d3 -- d2, d3, d1 )
         5 ROLL 5 ROLL   ;
 : MY-2ROT ( d1, d2, d3  -- d3, d1, d2 )
         MY2ROT MY2ROT  ;

 comment:
 results of ex3.4:


  C - 35k : - 49k   Depth 6     B:\lesson3\RARL3.SEQ                     
  19:59
 3. 4. .sd2 3.  4.   ok                                                  
 FORTH
 myy2swap .sd 4.  3.   ok                                               
 FORTH
 my2drop .sd 4.   ok                                                   
 FORTH
 5. .sd 4.  5.   ok                                                    
 ROOT
 my2dup .sd 4.  5.  5.   ok
 my2nip .sd 4.  5.   ok
 my2over .sd 4.  5.  4.   ok
 my2drop .sd 4.  5.   ok
 my2nip .sd 5.   ok
 6.  ok
 .sd 5.  6.   ok
 my2tuck .sd 6.  5.  6.   ok
 my2drop 4. .sd 6.  5.  4.   ok
 my2rot .sd 5.  4.  6.   ok
 my-2rot .sd 6.  5.  4.   ok

 EX3.5 Still need some work on floored division for negative numbers!
       Will review lesson 2 further.
 comment;

 \ ex.3.6:

 : D1+ ( d -- D+1 )   1. D+ ;
 : D2+ ( d -- d+2 )   2. D+ ;
 : D1- ( d -- d-1 ))   1. D- ;
 : D2- ( d -- d-2 )   2. D- ;
 comment:
 : D2* ( d -- 2d )     2 *D  ;
 this won't work, because *D takes a 16 bit integer as its argument.
 Hoe visual editor!
-----
This message came from GEnie via willett through a semi-automated process.
Report problems to: uunet!willett!dwp or willett!dwp@hobbes.cert.sei.cmu.edu

ForthNet@willett.UUCP (ForthNet articles from GEnie) (05/29/90)

 Date: 05-27-90 (14:37)              Number: 15 (Echo)
   To: JACK BROWN                    Refer#: NONE
 From: ROY RICE                        Read: NO
 Subj: MY PREV MESSAGE               Status: PUBLIC MESSAGE

 Jack: In reviewing my previous message, it looks like the last dozen 
 lines or so didnt get on. It looks like there may be a limit as to the 
 number of lines the editor will take. I will add those lines to my next 
 message with the remainder of the exercises in lesson 3.
-----
This message came from GEnie via willett through a semi-automated process.
Report problems to: uunet!willett!dwp or willett!dwp@hobbes.cert.sei.cmu.edu

ForthNet@willett.UUCP (ForthNet articles from GEnie) (06/01/90)

 Date: 05-30-90 (22:48)              Number: 17 (Echo)
   To: JACK BROWN                    Refer#: NONE
 From: ROY RICE                        Read: NO
 Subj: LESSON3                       Status: PUBLIC MESSAGE

 jACK, HERE IS LESSON 3, EX.3.6:
 \ rarl3a.seq - answers to lesson 3, continued at ex.3.6

 : D1+ ( d -- D+1 )   1. D+ ;
 : D2+ ( d -- d+2 )   2. D+ ;
 : D1- ( d -- d-1 )   1. D- ;
 : D2- ( d -- d-2 )   2. D- ;
 comment:   05/26/90
 : D2* ( d -- 2d )    2 *D  ;
 this won't work, because *D takes a 16 bit integer as its argument.
 The "normal" D2* is code, because a multiply by 2 is just a left
 shift of a binary number, which is how numbers are stored and
 manipulated in the machine.
 So far I haven't found an arithmetic operator that I can use to form
 the reqiired word.
 Later:     05/28/90
 The following seems to be a bruite force way. Am I over complicating
 this question?? It seems that you must handle the overflow from the
 low order 2 bytes some way, and this is the only way I could come up
 with to do it.
 comment;

 : d2* ( d -- 2d )  \ multiply the double number by 2
         \ stack comments du= upper 2 bytes, dl= lower 2 bytes
         2 UM*    ( dl dh*2_lo dh*2_hi --)  \ mul high byte x2
         ROT      ( dh*2_lo dh*2_hi dl --)
         2 UM*    ( dh*2_lo dh*2_hi dl*2_lo dl*2_hi -- )
         \ both are now doubles, but the dh*2 must be swapped to get
         \ its bytes in the proper order
         2SWAP SWAP  D+ ;  \ add with bytes in proper order


 : D2/ ( d -- d/2 )   2  MU/MOD ROT DROP ;

 comment:
 um/mod leaves a single quotient, so it will give a wrong result on
 any devide which results in a double quotient. Is this definition
 of any use, or is it just in the kernel as a  source for mu/mod?

 CODE UM/MOD     ( ud un -- URemainder UQuotient )
 \ Unsigned double number divided by unsigned single results in unsigned
 \ remainder and quotient, with quotient on top.
                 POP BX          POP DX          POP AX
                 CMP DX, BX
             U>=  ( divide by zero? )
             IF
                 MOV AX, # -1    MOV DX, AX      2PUSH
             THEN
                 DIV BX          2PUSH           END-CODE

 : MU/MOD        ( ud# un1 -- rem d#quot )
 \  Divide unsigned double by a single, leaving a remainder and quotient.
                 >R  0  R@  UM/MOD  R>  SWAP  >R  UM/MOD  R>   ;
 The stack comments above are confusing. Why did he use ud# instead of
 ud and un1 instead of un in the second definition?
 comment;

 : test2 ( d -- ) \ test the above double number operators
         2 ?ENOUGH
         2DUP CR          ." INPUT= " D.  CR
         2DUP D1+         ." D1+  = " D.  CR
         2DUP D2+         ." D2+  = " D.  CR
         2DUP D1-         ."" D1-  = " D.  CRR
         2DUP D2-         ." D2-  = " D.  CR
         2DUP D2*         ." D2*  = " D.  CR
              D2/         ." D2/  = " D.  CR   ;

 best, Roy
-----
This message came from GEnie via willett through a semi-automated process.
Report problems to: uunet!willett!dwp or willett!dwp@hobbes.cert.sei.cmu.edu

ForthNet@willett.UUCP (ForthNet articles from GEnie) (06/01/90)

 Date: 05-30-90 (22:51)              Number: 18 (Echo)
   To: JACK BROWN                    Refer#: NONE
 From: ROY RICE                        Read: NO
 Subj: LESSON3, CONT.                Status: PUBLIC MESSAGE

 Jack: ex.3.7-9:
 \ rarl3b.seq continuation of answers to lesson 3, starting with ex.3.7

 \ ex3.7
 \ Illustration of Number bases and formatted display operators.
 \ modified by rar  05/28/90 20:02:05.74
 : NTABLE ( dn -- )
          CR ."      unsigned"  ."        signed" ."      unsigned"
             ."        signed"  ."      unsigned" ."        signed"
          CR ."       decimal"  ."       decimal" ."        octal "
             ."        octal "  ."         hex  " ."         hex  "
          20 0 DO
               CR
               DECIMAL DUP 13 U.R
                       DUP 13  .R
               OCTAL   DUP 13 U.R
                       DUP 13  .R
               HEX     DUP 13 U.R
                       DUP 13  .R
               1+
               LOOP
               DROP DECIMAL ;

 \ EX.3.8
 : BINARY ( --) 2 BASE ! ;
 :  .H ( n -- ) HEX     . DECIMAL ;  \ Display top number in HEX
 : U.HH ( n -- ) HEX    U. DECIMAL ;  \ Displlay top as unsigned HEX
 :  .O ( n -- ) OCTAL   . DECIMAL ;  \ Display top number in OCTAL
 : U.O ( n -- ) OCTAL  U. DECIMAL ;  \ Display top as unsigned OCTAL
 :  .B ( n -- ) BINARY  . DECIMAL ;  \ Display top number in BINARY
 : U.B ( n -- ) BINARY U. DECIMAL ;  \ Display top as unsigned BINARY

 comment:
 The above definitions end with DECIMAL because we want to reset the
 base to decimal after outputting the number. They could be modified
 to save the current base and restore it after printing the number
 ( I think I saw this in Starting Forth)
 as in this definition to display the number in decimal and then restore
 the base:
 comment;

 :  .D ( n -- ) BASE @ SWAP DECIMAL  . BASE ! ;
 : U.D ( n -- ) BASE @ SWAP DECIMAL U. BASE ! ;

 : BNTABLE ( dn -- )
   CR ." unsigned     signed          unsigned            "
      ." signed     unsigned       signed"
   CR ."  decimal     decimal           binary            "
      ." binary          hex          hex"
          20 0 DO
               CR
               DECIMAL DUP 10 U.R
                       DUP 10  .R
               BINARY  DUP 17 U.R
                       DUP 17  .R
               HEX     DUP 13 U.R
                       DUP 13  .R
               1+
               LOOP
               DROP DECIMAL ;


-----
This message came from GEnie via willett through a semi-automated process.
Report problems to: uunet!willett!dwp or willett!dwp@hobbes.cert.sei.cmu.edu

ForthNet@willett.UUCP (ForthNet articles from GEnie) (06/01/90)

 Date: 05-30-90 (22:54)              Number: 19 (Echo)
   To: JACK BROWN                    Refer#: NONE
 From: ROY RICE                        Read: NO
 Subj: LESSON3, EX3.10               Status: PUBLIC MESSAGE

 \ RARL3C.SEQ  continuation of answers to lesson3
 \ l3p5 conditionals ex.3.10

 : .FLAG ( f --) \ tell us the type flag on stack
         0=  IF  ." FALSE  "  ELSE ." TRUE   "    THEN ;

 : EQUTEST ( n m -- ) \ test of equality/inequality
         CR ." TEST=      TEST<>     TEST>      TEST<"  CR
         2DUP =  .FLAG  4 SPACES
         2DUP <> .FLAG  4 SPACES
         2DUP >  .FLAG  4 SPACES
              <  .FLAG  4 SPACES CR  ;

 : 0TEST  ( n --)  \ test 0=, etc.
         CR ." TEST0=     TEST0<>    TEST0>     TEST0<"  CR
         DUP 0=  .FLAG  4 SPACES
         DUP 0<> .FLAG  4 SPACES
         DUP 0>  .FLAG  4 SPACES
             0<  .FLAG  4 SPACES CR  ;

 : LOGITEST ( f1 f2 -- )  \  test logical operators
         CR  ." TEST AND   TEST OR    TEST NOT "  CR
         2DUP AND  .FLAG  4 SPACES
         2DUP  OR  .FLAG  4 SPACES
         DUP .FLAG ." NOT --> " NOT  .FLAG  CR  22 SPACES
         DUP .FLAG ." NOT --> "  NOT  .FLAG  CR   ;

 COMMENT:   Here are the rsults of the test of above:
 -1 1 EQUTEST
 TEST=      TEST<>     TEST>      TEST<
 FALSE      TRUE       FALSE      TRUE
  ok
 1 -1 EQUTEST
 TEST=      TEST<>     TEST>      TEST<
 FALSE      TRUE       TRUE       FALSE
  ok
 -5 -7 EQUTEST
 TEST=      TEST<>     TEST>      TEST<
 FALSE      TRUE       TRUE       FALSE
  ok
 -7 -5 EQUTEST
 TEST=      TEST<>     TEST>      TEST<
 FALSE      TRUE       FALSE      TRUE
  ok
 0 0 EQUTEST
 TEST=      TEST<>     TEST>      TEST<
 TRUE       FALSE      FALSE      FALSE

 0 0TEST
 TEST0=     TEST0<>    TEST0>     TEST0<
 TRUE       FALSE      FALSE      FALSE
 65535 0TEST
 TEST0=     TEST0<>    TEST0>     TEST0<
 FALSE      TRUE       FALSE      TRUE
 -32000 0TEST
 TEST0=     TEST0<>    TEST0>     TEST0<
 FALSE      TRUE       FALSE      TRUE
 32767 0TEST
 TEST0=     TEST0<>    TEST0>     TEST0<
 FALSE      TRUE       TRUE       FALSE
 32768 0TEST
 TEST0=     TEST0<>    TEST0>     TEST0<
 FALSE      TRUE       FALSE      TRUE

 : T TRUE ;   : F FALSE ;  ok
 T F LOGITEST
 TEST AND   TEST OR    TEST NOT
 FALSE      TRUE       FALSE  NOT --> TRUE
                       TRUE   NOT --> FALSE
 T T LOGITEST
 TEST AND   TEST OR    TEST NOT
 TRUE       TRUE       TRUE   NOT --> FALSE
                       TRUE   NOT --> FALSE
 F T LOGITEST
 TEST AND   TEST OR    TEST NOT
 FALSE      TRUE       TRUE   NOT --> FALSE
                       FALSE  NOT --> TRUE
 F F LOGITEST
 TEST AND   TEST OR    TEST NOT
 FALSE      FALSE      FALSE  NOT --> TRUE
                       FALSE  NOT --> TRUE
 comment;
-----
This message came from GEnie via willett through a semi-automated process.
Report problems to: uunet!willett!dwp or willett!dwp@hobbes.cert.sei.cmu.edu

ForthNet@willett.UUCP (ForthNet articles from GEnie) (06/01/90)

 Date: 05-30-90 (22:56)              Number: 20 (Echo)
   To: JACK BROWN                    Refer#: NONE
 From: ROY RICE                        Read: NO
 Subj: LESSON3, EX3.11-12            Status: PUBLIC MESSAGE

 \ RARL3D.SEQ  ccontinuation of lesson 3
 \ (IN)  leaves a true flag if   a < x < b
 : (IN)  ( x a b --  flag )  ( JWB 28 09 88 )
          2DUP < NOT ABORT" Invalid interval."
          -ROT OVER < -ROT > AND ;

 \ Exercise 3.12
 \ Write definitions of [IN] (IN] and [IN) that do not use (IN) or
 \ each other!
 : [IN) ( x a b -- f )  \ true if a <= x < b
         2DUP < NOT ABORT" Invalid interval."
         -ROT OVER <= -ROT > AND ;

 : (IN] ( x a b -- f )  \ true if  a < x <= b
         2DUP < NOT ABORT" Invalid interval."
         -ROT OVER < -ROT >= AND ;


 : [IN]  ( x a b -- f ) \ true if a <= x <= b
         2DUP < NOT ABORT" Invalid interval."
                 -ROT OVER <= -ROT >=  AND ;

 \ ex 3.11 tests using my words
 : .F ( f -- ) \ display flag
         IF ." true    "  ELSE ." false   "  then  ;

 : TESTIN ( x a b -- ) \  test the interval words
         2DUP < NOT ABORT" Invalid interval."
         CR   3DUP
         SWAP  ." a = " .  4 SPACES
         SWAP  ." x = " .  4 SPACES ." b = " . CR
         ." (IN)    [IN)    (IN]    [IN] "     CR
         ." a<x<b   a<=x<b  a<x<=b  a<=x<=b"   CR
         3DUP (IN)  .F
         3DUP [IN)  .F
         3DUP (IN]  .F
              [IN]  .F   CR   ;
 comment:
 4 4 6 testin
 a = 4     x = 4     b = 6
 (IN)    [IN)    (IN]    [IN]
 a<x<b   a<=x<b  a<x<=b  a<=x<=b
 false   true    false   true
  ok
 4 5 6 testin
 a = 5     x = 4     b = 6
 (IN)    [IN)    ((IN]    [IN]
 a<x<b   a<=x<b  a<x<=b  a<=x<=b
 false   false   false   false
  ok
 5 4 6 testin
 a = 4     x = 5     b = 6
 (IN)    [IN)    (IN]    [IN]
 a<x<b   a<=x<b  a<x<=b  a<=x<=b
 true    true    true    true
  ok
 6 4 6 testin
 a = 4     x = 6     b = 6
 (IN)    [IN)    (IN]    [IN]
 a<x<b   a<=x<b  a<x<=b  a<=x<=b
 false   false   true    true
  ok
 comment;
-----
This message came from GEnie via willett through a semi-automated process.
Report problems to: uunet!willett!dwp or willett!dwp@hobbes.cert.sei.cmu.edu

ForthNet@willett.UUCP (ForthNet articles from GEnie) (06/16/90)

 Date: 06-13-90 (20:29)              Number: 26 (Echo)
   To: ALL                           Refer#: NONE
 From: GORDON GANDERTON                Read: (N/A)
 Subj: TUTORIAL                      Status: PUBLIC MESSAGE

 \ CHECKER BOARD PROGRAM
 \ Version Number: 2
 \ Date: September 18, 1988
 \ Autho: Gordon Ganderton
 : BLACK ( -- )
         SPACE SPACE ;
 : HALFWHITE ( -- )
         177 EMIT ;
 : WHITE ( -- )
         177 EMIT 177 EMIT ;
 : XBORDER 13 0 DO WHITE LOOP ;
 : LEFTBORDER  WHITE SPACE SPACE SPACE ;
 : RIGHTBORDER 8 SPACES WHITE ;
 : RIGHTSIDE SPACE SPACE SPACE WHITE ;
 : ROW1 CR LEFTBORDER 4 0 DO BLACK WHITE LOOP RIGHTSIDE ;
 : ROW2 CR LEFTBORDER 4 0 DO WHITE BLACK LOOP RIGHTSIDE ;
 : BOARD 4 0 DO ROW1 ROW2 LOOP ;
 : CHECKER_BOARD  CLS CR XBORDER CR
                 LEFTBORDER 11 SPACES RIGHTBORDER
                 BOARD CR
                 LEFTBORDER 11 SPACES RIGHTBORDER CR
                 XBORDER ;

 CHECKER_BOARD
 11111111111111111111111111
 11                      11
 11     11  11  11  11   11
 11   11  11  11  11     11
 11     11  11  11  11   11
 11   11  11  11  11     11
 11     11  11  11  11   11
 11   11  11  11  11     11
 11     11  11  11  11   11
 11   11  11  11  11     11
 11                      11
 11111111111111111111111111 ok

 It took me quite a while to figure this out and I did it mostly
 through trial and error.

 ---
  ~ EZ 1.26 ~ .EXE -ex

 NET/Mail : British Columbia Forth Board - Burnaby BC - (604)434-5886   
-----
This message came from GEnie via willett through a semi-automated process.
Report problems to: uunet!willett!dwp or willett!dwp@hobbes.cert.sei.cmu.edu