Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!willett!ForthNet From: ForthNet@willett.UUCP (ForthNet articles from GEnie) Newsgroups: comp.lang.forth Subject: F-PC Forth Tutorial Message-ID: <759.UUL1.3#5129@willett.UUCP> Date: 11 Apr 90 01:57:07 GMT Organization: Latest link in the ForthNet chain. (Pgh, PA) Lines: 78 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'