goto

Upload: rodolfo-sergio-cruz-fuentes

Post on 07-Jan-2016

213 views

Category:

Documents


0 download

DESCRIPTION

goto HP RPL

TRANSCRIPT

Path: republic.btigate.com!news-xfer.netaxs.com!fastnet!news-pen-1.sprintlink.net!news-east.sprintlink.net!news-peer.sprintlink.net!news.sprintlink.net!Sprint!newsfeed.internetmci.com!152.163.199.19!portc03.blue.aol.com!audrey02.news.aol.com!not-for-mailFrom: [email protected] (WndaLouise)Newsgroups: comp.sys.hp48Subject: A Goto Solution...+ A program listingDate: 20 Jan 1998 20:12:33 GMTLines: 803Message-ID: NNTP-Posting-Host: ladder02.news.aol.comX-Admin: [email protected]: AOL http://www.aol.comMime-Version: 1.0Content-Type: text/plain; charset=ISO-8859-1Content-Transfer-Encoding: 8bitXref: republic.btigate.com comp.sys.hp48:5871AmazingA Program in Basic Translated to RPL.Or; How to deal with the dreaded GOTO statement when converting a BASIC programto the Object Oriented Reverse Polish Lisp/Language.This program was found in:BASIC Computer Games: MicroComputer Edition 101 Great Games to play on Your Home Computer. Edited by David H. AhlWorkman Publishing Copyright 1978The Original Programs Author was Jack Hauber.This translation to UserRPL is by TinyWanda. January 1998Contact me at: [email protected] tried translating this program from Basic to RPL a couple of years ago, butvery quickly went nuts in the process, as about 80% of the program lines endwith a GOTO or implied Goto...The school of thought that i was then working from was that i would have toconvert the Basic program into a Flow-Chart, and then translate -that- intoRPL... I had pasted several sheets of paper together and was merrily pushing the chartout further and further, writing smaller and smaller, drawing more and moreboxes with paths leading from one to another and back again, in severaldifferent colours, all the while trying to keep some sense of what the programwas doing...Ive found that whenever im engaged in something like this, i have tocompletely submerse myself in it, so that nothing is allowed to compete withthe allocated neural capacity thats been set aside for this... Then for whatever reasons, i was somehow distracted, and when i returned to theflowchart in question, all my meticulous scribbilings made all the sense of theresidue one might find in a slightly gelatinous puddle produced by a sickhamster.sigh.So i put it aside-- until just recently when the necessary Key Insight occurredto me, in conjunction with a collection of postings on the comp.sys.hp48.The Key Insight is this:Dont even Try to Understand the program.Simply create a List of all the Basic program lines, With each Program Lineconstituting one Programming Object, Then evaluate each object in the DesiredSequence.Its mighty dang slow, but the criteria that i was working from was that;a) i just want the program to work.b) i dont want to figure it out.c) & dont want to put alot of effort into it.The procedure then becomes:Type the Basic program into your Big Box.PROOF READ IT!PROOF READ IT AGAIN!!If possible; isolate the most offensive areas where the most number of Gotosoccur...The method i used was to print out the program, paste the sheetstogether so that it created one long continuous listing, and then used a redpen to draw links from line to line going down through the program on the left,and a blue pen to draw links from line to line going up through the program onthe right.This created a very messy listing, but it was also clear that the programconsisted of essentially three parts, two of which could be converted into RPLfairly straight-forwardly.The middle part however was a classic example of incomprehensible spaghetticode.I took that middle part and copied it to another file where i could work on itis isolation.I then used the Find and Change-All functions to ReNumber the program linesfrom; in this case, 210 through 1000, to 1 through 100, along with all theinternal references to those line numbers.Then i changed all the Carriage returns to ProgramObject delimiters so thateach line was now enclosed in the proper >s for RPL, and then i put listdelimiters { } around the outside of these, and an HP header at the top.So that it now looked something like this;%%HP: T(3)A(D)F(.);{\>\>\>\>\>\> ... }Then each individual program object would have to be tediously translated toRPL, an annoying, but not impossibly dreary process...The Bit of Code in the Main program that executes this list consists of thisroutine;1 WHILE DUP REPEAT Lines SWAP GET EVAL END DROPWhich takes one number, the number referring to the object that should be nextEvaluated...so that each Line/ProgramObject has to leave on the stack thenumber of -Next- Line/ProgramObject to be Evaluated...??? means Not-Equal; \=/ Program Name: Lines%%HP: T(3)A(D)F(.);{\>\>\>\>\>\> ... }All the variables have to be either Global Variables or left-arrow prefixedLocal Variables; \. Holds the Number used to Name/Store the Mazes->Sto Bonus ProgramAbc Bonus Program used to Name/Store the MazesCba Bonus Program; Inversion of Abc? Display Routine for CountdownAlrm Bonus Program to alert you that its doneLines List of BasicLines/RPL-Programs.............................To Use StartStart incorporates the double click feature!Double Click on Start;And an Input prompt appears urging you to define the Width and Height of theMaze to be created.Or-Load the Stack with the width and height, and click on Start, or activate Start from another program.2: real integer Width1: real integer HeightWhile the program is running, it displays a countdown to let you know that itsmaking some progress in creating the maze, as this process is -really- veryslow...!!!It also displays the Line/Object that is currently being evaluated...???...itmay seem that occasionally, particularly toward the end of the mazecalculations, that the program will conk-out and get trapped in a dead-endloop...but...if you wait, and wait some more, suddenly, contrary to youreexpectations, it will slowly begin to creep towards the end of itscalculations again...???The display will countdown once for the calculations phase, and again for thedrawing phase, the drawing phase is comparatively much quicker!When its done, an alarm will go off.To shut it off, simply hit ON.The program will also store the Maze under a unique name, defined by the ->.variable, in conjunction with the Abc program which takes any number andconverts it to a zeroless base 26 number ( A-Z & beyound ).Just to be sure that these names dont conflict with any of the variables usedby Start, each name is prefixed with a RightArrow.The Bonus program ->Sto has been gratuitously included.->Sto allows you to store several variables from the stack, in severaldifferent ways, by using a bit of AI, in one quick step.Auto Store is designed to store Global Variables in that Local Variable Mannerthat is So Much more Friendly...!!!->Sto uses a bit of Artificial Intelligence (???) to figure out What is on theStack and how and what should be stored under which Names...!!!The Stack configurations that are allowed are:6: Object A5: Object B4: Object C3: 'A'2: 'B'1: 'C'This structure, above, allows for any number of Objects and Names to be on theStack, just so long as the bottom most object to be stored, Object C in thisexample, is not a Type 6 or 7 ( A Global or Local Name ). 4: Object A3: Object B2: Object C1: { A B C }Again; this allows for any number of Objects and Names...4: A: Object3: B: Object2: C: Object1: 3or 1: A: ObjectPosition 1: Refers to the number of the Tagged Objects to be stored, If any ofthe Tags would form an Illegal Name, then That Object and it's Tag will be lefton the Stack.If there in Only one Tagged Object to be Stored, then It may be left alone inPosition 1: 1: Real NumberIn this case, the Number is the Stored under the Number itself, prefixed with Character (183), the tiny dot.For Optimum Ease of Use, Reference this Program through a UserKey... ->Sto32 ASN .........................................Program Listing:DirectoryName: MAZeCheckSum: # 7D15hSize: 7276%%HP: T(3)A(D)F(.);DIR Start \> IFT DUP2DUP2 * 2 * 3 ROLLD2 \->LIST 0 CON DUP 00 RAND 8 PICK *CEIL DUP 2 1"Amazing Maze" 12PICK DTAG " By " 14PICK DTAG "" + ++ + 13 CHR 10 CHR +RCLF { h v \162 W V qz x r c s $ \|v f }\->Sto STD 1 h FOR i '$' i x== ". " ".--" IFTESTO+ NEXT '$' "."\|v + STO+ 'W' x 1 2\->LIST 1 PUT CLLCD" Calculating Maze"1 DISP 1 WHILE DUP REPEAT'Lines' SWAP " "OVER + 5 DISP GETEVAL END DROPCLLCD" Drawing Maze" 1DISP h v * 2 * '\162'STO 1 v FOR j '$' "I"STO+ 1 h FOR i V { ij } GET 2 < \> \> IFTE ? NEXT '$' \|vSTO+ 1 h FOR i { 0 2} 'V' { i j } GETPOS \> \> IFTE ? NEXT '$'":" \|v + STO+ NEXT $ "\->"'\->\183' INCR Abc +OBJ\-> STO f STOF { hv \162 W V x r c s $ \|vq z f } PURGE :&:Alrm EVAL \>> \->\183 0 \->Sto \> \-> $ \164 \GD \TAG \162 ROLLD END\>>\> IFTE -1 STEP \>> \ STO \>> IFTE END $ 5== THEN DUPSIZE 1 FOR \162SWAP OVER \162 GET STO-1 STEPDROP END { 6 7} $ POS THEN 1 DO 1 +DUP PICK TYPE { 6 7} SWAP POS NOT UNTIL END 1 -2 FOR \162 \162ROLL SWAP STO -1 STEP END $ 12== THEN OBJ\-> IFERROBJ\-> STO THEN\->TAG \GD EVAL END END \GDEVAL END \164 STOF \>> \>> Abc \ REPEAT OVER26 SWAP 1 - SWAPMOD 1 + DUP 64 +CHR EVAL ROT + 3ROLLD - 26 / SWAP END SWAP 64 +CHR EVAL SWAP + \>> Cba \ \162 \> \>> ? \> Alrm \LIST RAND 6 * 2 +CEIL \-> h y \ DROP -56 SF \>> \>> Lines { \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> }END-[ TERMINUS ]-