Path: utzoo!attcan!uunet!willett!ForthNet From: ForthNet@willett.UUCP (ForthNet articles from GEnie) Newsgroups: comp.lang.forth Subject: F-PC Forth Tutorial Message-ID: <1030.UUL1.3#5129@willett.UUCP> Date: 29 May 90 03:24:29 GMT Organization: Latest link in the ForthNet chain. (Pgh, PA) Lines: 106 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