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-mail
From: wndalouise@aol.com (WndaLouise)
Newsgroups: comp.sys.hp48
Subject: A Goto Solution...+ A program listing
Date: 20 Jan 1998 20:12:33 GMT
Lines: 803
Message-ID: <19980120201200.PAA00709@ladder02.news.aol.com>
NNTP-Posting-Host: ladder02.news.aol.com
X-Admin: news@aol.com
Organization: AOL http://www.aol.com
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Xref: republic.btigate.com comp.sys.hp48:5871

Amazing
A Program in Basic Translated to RPL.

Or; How to deal with the dreaded GOTO statement when converting a BASIC program
to 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. Ahl
Workman Publishing Copyright 1978

The Original Programs Author was Jack Hauber.

This translation to UserRPL 
  is by TinyWanda.  January 1998
Contact me at: WndaLouise@aol.com

I tried translating this program from Basic to RPL a couple of years ago, but
very quickly went nuts in the process, as about 80% of the program lines end
with a GOTO or implied Goto...
The school of thought that i was then working from was that i would have to
convert the Basic program into a Flow-Chart, and then translate -that- into
RPL... 
I had pasted several sheets of paper together and was merrily pushing the chart
out further and further, writing smaller and smaller, drawing more and more
boxes with paths leading from one to another and back again, in several
different colours, all the while trying to keep some sense of what the program
was doing...
Ive found that whenever im engaged in something like this, i have to
completely submerse myself in it, so that nothing is allowed to compete with
the allocated neural capacity thats been set aside for this... 
Then for whatever reasons, i was somehow distracted, and when i returned to the
flowchart in question, all my meticulous scribbilings made all the sense of the
residue one might find in a slightly gelatinous puddle produced by a sick
hamster.
sigh.
So i put it aside-- until just recently when the necessary Key Insight occurred
to 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 Line
constituting one Programming Object, Then evaluate each object in the Desired
Sequence.
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 Gotos
occur...The method i used was to print out the program, paste the sheets
together so that it created one long continuous listing, and then used a red
pen 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 on
the right.
This created a very messy listing, but it was also clear that the program
consisted of essentially three parts, two of which could be converted into RPL
fairly straight-forwardly.
The middle part however was a classic example of incomprehensible spaghetti
code.
I took that middle part and copied it to another file where i could work on it
is isolation.
I then used the Find and Change-All functions to ReNumber the program lines
from; in this case, 210 through 1000, to 1 through 100, along with all the
internal references to those line numbers.
Then i changed all the Carriage returns to ProgramObject delimiters so that
each line was now enclosed in the proper << & >>s for RPL, and then i put list
delimiters { } 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(.);
{
\<< 1 GOTO 8 >>
\<< 2 IF R<>H THEN 6 \>>
\<< 3 IF S<>V THEN 5 \>>
\<< 4 R=1: S=1: GOTO 7 \>>
\<< 5 R=1: S=S+1: GOTO 7 \>>
\<< 6 R=R+1 \>>
   ...
 }

Then each individual program object would have to be tediously translated to
RPL, an annoying, but not impossibly dreary process...
The Bit of Code in the Main program that executes this list consists of this
routine;

1 WHILE DUP REPEAT Lines SWAP GET EVAL END DROP

Which takes one number, the number referring to the object that should be next
Evaluated...so that each Line/ProgramObject has to leave on the stack the
number of -Next- Line/ProgramObject to be Evaluated...???

<> means Not-Equal; \=/ 

Program Name: Lines

%%HP: T(3)A(D)F(.);
{
\<< 8 >>
\<< R H \=/ 6 3 IFTE \>>
\<< S V \=/ 5 4 IFTE \>>
\<< 1 { R S } STO 7 \>>
\<< 1 R STO 1 S STO+ 7 \>>
\<< 1 R STO+ \>>
   ...
 }

All the variables have to be either Global Variables or left-arrow prefixed
Local Variables; \<- !

Then simply arrange all the bits in their appropriate sequence and follow all
the other -normal- RPL programming directives...??? (!)

...........................................

The En-soi ( Thing in itself )

Amazing

Amazing was written in the ancient days of Basic, and is a psuedo-graphical
program that creates a unique maze, with the width & height defined by the
user, drawn with ordinary typographical characters.

Such as this:

%%HP: T(1)A(D)F(.);
"Amazing Maze
15 By 15

.--.--.--.--.--.--.--.  .--.--.--.--.--.--.--.
I                    I        I     I     I  I
:  :--:  :--:--:--:--:  :--:  :  :  :  :  :  :
I     I     I              I     I     I  I  I
:--:  :--:  :  :--:--:--:  :--:--:--:  :  :  :
I     I     I     I     I           I  I  I  I
:--:--:  :--:  :--:  :  :--:--:  :  :  :  :  :
I        I     I     I           I  I  I     I
:  :--:--:  :--:  :  :--:  :--:--:  :  :--:--:
I           I     I     I  I     I  I  I     I
:--:--:--:--:  :--:--:  :--:  :--:  :  :  :  :
I           I  I     I     I     I  I     I  I
:  :  :  :--:  :  :  :--:  :--:  :  :--:--:  :
I  I  I     I  I  I     I        I     I  I  I
:  :  :--:  :  :  :--:  :--:--:--:--:  :  :  :
I  I     I           I  I           I  I     I
:--:--:  :--:--:--:  :--:  :--:--:  :  :--:--:
I     I  I     I           I     I  I  I     I
:  :  :--:  :  :  :--:--:--:  :  :  :  :  :  :
I  I  I     I  I           I  I  I  I     I  I
:  :  :  :--:--:  :--:--:  :  :  :--:--:--:  :
I  I  I  I     I     I     I  I        I     I
:  :  :  :  :  :--:  :  :--:--:  :--:  :  :--:
I  I     I  I  I     I        I     I  I     I
:  :--:--:  :  :--:--:--:--:  :  :  :--:--:  :
I        I  I     I     I     I  I  I     I  I
:  :--:  :  :--:  :  :  :  :--:--:  :  :  :  :
I  I     I  I     I  I     I     I  I  I  I  I
:  :  :--:  :  :--:  :--:--:  :  :  :  :--:  :
I  I     I  I  I              I     I     I  I
:  :  :--:  :--:  :--:--:--:--:  :--:  :  :  :
I  I     I        I           I     I  I     I
:  :--:  :--:--:--:  :--:--:  :--:  :--:--:--:
I  I     I           I        I  I           I
:  :  :--:--:--:--:  :  :--:--:  :  :--:--:  :
I  I     I     I     I  I     I     I     I  I
:  :--:  :  :  :  :--:  :  :--:  :--:  :  :--:
I  I     I  I  I     I     I     I     I     I
:  :--:--:  :  :  :  :--:--:  :--:  :--:--:  :
I  I        I  I  I  I     I  I        I     I
:  :  :  :--:  :  :  :  :  :  :--:--:  :  :--:
I     I     I  I  I  I  I  I           I  I  I
:  :--:--:  :  :  :  :  :--:  :--:--:--:  :  :
I     I     I     I  I  I     I        I  I  I
:--:--:  :--:--:  :--:  :  :  :  :--:  :  :  :
I        I     I  I     I  I  I     I  I  I  I
:  :--:--:  :--:  :  :--:  :  :  :  :--:  :  :
I        I     I  I        I  I  I     I  I  I
:--:--:  :  :  :  :--:--:--:--:  :  :  :  :  :
I     I  I  I  I     I     I     I  I  I     I
:  :  :  :--:  :  :--:  :  :  :  :--:  :  :--:
I  I           I        I     I  I           I
:--:--:--:--:--:--:--:--:--:--:--:  :--:--:--:
"
.............................
The Directory consists of Eight Objects:

Start  The Maze Creator
->.    Holds the Number used to Name/Store the Mazes
->Sto  Bonus Program
Abc    Bonus Program used to Name/Store the Mazes
Cba    Bonus Program; Inversion of Abc
?      Display Routine for Countdown
Alrm   Bonus Program to alert you that its done
Lines  List of BasicLines/RPL-Programs

.............................

To Use Start

Start incorporates the double click feature!

Double Click on Start;
And an Input prompt appears urging you to define the Width and Height of the
Maze 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  Width
1:   real integer  Height

While the program is running, it displays a countdown to let you know that its
making some progress in creating the maze, as this process is -really- very
slow...!!!
It also displays the Line/Object that is currently being evaluated...???...it
may seem that occasionally, particularly toward the end of the maze
calculations, that the program will conk-out and get trapped in a dead-end
loop...but...if you wait, and wait some more, suddenly, contrary to youre
expectations, it will slowly begin to creep towards the end of its
calculations again...???

The display will countdown once for the calculations phase, and again for the
drawing 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 and
converts it to a zeroless base 26 number ( A-Z & beyound ).
Just to be sure that these names dont conflict with any of the variables used
by 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 several
different ways, by using a bit of AI, in one quick step.

Auto Store is designed to store Global Variables in that Local Variable Manner
that is So Much more Friendly...!!!

->Sto uses a bit of Artificial Intelligence (???) to figure out What is on the
Stack and how and what should be stored under which Names...!!!

The Stack configurations that are allowed are:

6:           Object A
5:           Object B
4:           Object C
3:                'A'
2:                'B'
1:                'C'

This structure, above, allows for any number of Objects and Names to be on the
Stack, just so long as the bottom most object to be stored, Object C in this
example, is not a Type 6 or 7 ( A Global or Local Name ). 

4:           Object A
3:           Object B
2:           Object C
1:          { A B C }

Again; this allows for any number of Objects and Names...

4:           A: Object
3:           B: Object
2:           C: Object
1:                   3

or 

1:           A: Object

Position 1:  Refers to the number of the Tagged Objects to be stored, If any of
the Tags would form an Illegal Name, then That Object and it's Tag will be left
on the Stack.
If there in Only one Tagged Object to be Stored, then It may be left alone in
Position 1: 

1:           Real Number

In 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...  ->Sto
32 ASN 

.........................................

Program Listing:

DirectoryName:          MAZe
CheckSum:            # 7D15h
Size:                   7276

%%HP: T(3)A(D)F(.);
DIR
  Start
    \<<
"Amazing Program
originally found in
BASIC Computer Games
Edited by David H. Ahl
Workman Publishing CR 1978
Conversion From BASIC to RPL
by TinyWanda
WndaLouise@aol.com"
DROP .2 WAIT KEY
      \<< DROP
"Enter Width & Height
Of The Maze? "
{ ":W: 
:H: " { 1 5
} V } INPUT OBJ\->
      \>> IFT DUP2
DUP2 * 2 * 3 ROLLD
2 \->LIST 0 CON DUP 0
0 RAND 8 PICK *
CEIL DUP 2 1
"Amazing Maze
" 12
PICK DTAG " By " 14
PICK DTAG "

" + +
+ + 13 CHR 10 CHR +
RCLF { h v \162 W V q
z x r c s $ \|v f }
\->Sto STD 1 h
      FOR i '$' i x
== ".  " ".--" IFTE
STO+
      NEXT '$' "."
\|v + STO+ 'W' x 1 2
\->LIST 1 PUT CLLCD
"  Calculating Maze"
1 DISP 1
      WHILE DUP
      REPEAT
'Lines' SWAP "  "
OVER + 5 DISP GET
EVAL
      END DROP
CLLCD
"   Drawing Maze" 1
DISP h v * 2 * '\162'
STO 1 v
      FOR j '$' "I"
STO+ 1 h
        FOR i V { i
j } GET 2 <
          \<< '$'
"  I" STO+
          \>>
          \<< '$'
"   " STO+
          \>> IFTE ?
        NEXT '$' \|v
STO+ 1 h
        FOR i { 0 2
} 'V' { i j } GET
POS
          \<< '$'
":--" STO+
          \>>
          \<< '$'
":  " STO+
          \>> IFTE ?
        NEXT '$'
":" \|v + STO+
      NEXT $ "\->"
'\->\183' INCR Abc +
OBJ\-> STO f STOF { h
v \162 W V x r c s $ \|v
q z f } PURGE :&:
Alrm EVAL
    \>>
  \->\183 0
  \->Sto
    \<< DUP TYPE RCLF
      \<< PICT RCL
LCD\-> NEG PICT STO {
# 0d # 0d } PVIEW
RAND 2000 * 500 +
.05 BEEP TEXT PICT
STO
      \>> \-> $ \164 \GD
      \<< -55 -56 CF
CF
        CASE $ NOT
          THEN
            IFERR
OVER TYPE 12 ==
            THEN 0
            END
            \<< 1
              FOR \162
DUP TYPE 12 ==
\<< OBJ\->
  IFERR OBJ\-> STO
  THEN \->TAG \162 ROLLD
  END
\>>
\<< \162 ROLLD
\>> IFTE -1
              STEP
            \>>
            \<< "\183"
OVER + OBJ\-> STO
            \>> IFTE
          END $ 5
==
          THEN DUP
SIZE 1
            FOR \162
SWAP OVER \162 GET STO
-1
            STEP
DROP
          END { 6 7
} $ POS
          THEN 1
            DO 1 +
DUP PICK TYPE { 6 7
} SWAP POS NOT
            UNTIL
            END 1 -
2
            FOR \162 \162
ROLL SWAP STO -1
            STEP
          END $ 12
==
          THEN OBJ\->
            IFERR
OBJ\-> STO
            THEN
\->TAG \GD EVAL
            END
          END \GD
EVAL
        END \164 STOF
      \>>
    \>>
  Abc
    \<< ""
      WHILE OVER 26
>
      REPEAT OVER
26 SWAP 1 - SWAP
MOD 1 + DUP 64 +
CHR EVAL ROT + 3
ROLLD - 26 / SWAP
      END SWAP 64 +
CHR EVAL SWAP +
    \>>
  Cba
    \<< DUP SIZE \-> \162
      \<< 0 1 \162
        FOR $ OVER
$ $ SUB NUM 64 - 26
\162 $ - ^ * +
        NEXT SWAP
DROP
      \>>
    \>>
  ?
    \<< "  " '\162' DECR
+ 3 DISP
    \>>
  Alrm
    \<< -56 CF DEPTH
\->LIST RAND 6 * 2 +
CEIL \-> h y
      \<<
        IFERR { } 1
y
          START
RAND 4400 * + RAND
+
          NEXT 1 8
          START DUP
EVAL 1 y
            START
BEEP
            NEXT
          NEXT
        THEN
        END CLEAR h
OBJ\-> DROP -56 SF
      \>>
    \>>
  Lines {
    \<< 8
    \>>
    \<< r h \=/ 6 3
IFTE
    \>>
    \<< s v \=/ 5 4
IFTE
    \>>
    \<< 1 { r s } STO
7
    \>>
    \<< 1 'r' STO 's'
1 STO+ 7
    \>>
    \<< 'r' 1 STO+ 7
    \>>
    \<< 'W' { r s }
GET 0 == 2 8 IFTE
    \>>
    \<< r 1 - 0 == 41
9 IFTE
    \>>
    \<< 'W' { 'r-1' s
} GET 0 \=/ 41 10
IFTE
    \>>
    \<< s 1 - 0 == 24
11 IFTE
    \>>
    \<< 'W' { r 's-1'
} GET 0 \=/ 24 12
IFTE
    \>>
    \<< r h == 16 13
IFTE
    \>>
    \<< 'W' { 'r+1' s
} GET 0 \=/ 16 14
IFTE
    \>>
    \<< RAND 3 * CEIL
'x' STO 15
    \>>
    \<< { 75 79 83 }
x GET
    \>>
    \<< s v \=/ 19 17
IFTE
    \>>
    \<< z 1 == 22 18
IFTE
    \>>
    \<< 1 'q' STO 20
    \>>
    \<< 'W' { r 's+1'
} GET 0 \=/ 22 20
IFTE
    \>>
    \<< RAND 3 * CEIL
'x' STO 21
    \>>
    \<< { 75 79 90 }
x GET
    \>>
    \<< RAND 2 * CEIL
'x' STO 23
    \>>
    \<< { 75 79 } x
GET
    \>>
    \<< r h == 34 25
IFTE
    \>>
    \<< 'W' { 'r+1' s
} GET 0 \=/ 34 26
IFTE
    \>>
    \<< s v \=/ 29 27
IFTE
    \>>
    \<< z 1 == 32 28
IFTE
    \>>
    \<< 1 'q' STO 30
    \>>
    \<< 'W' { r 's+1'
} GET 0 \=/ 32 30
IFTE
    \>>
    \<< RAND 3 * CEIL
'x' STO 31
    \>>
    \<< { 75 83 90 }
x GET
    \>>
    \<< RAND 2 * CEIL
'x' STO 33
    \>>
    \<< { 75 83 } x
GET
    \>>
    \<< s v \=/ 37 35
IFTE
    \>>
    \<< z 1 == 40 36
IFTE
    \>>
    \<< 1 'q' STO 38
    \>>
    \<< 'W' { r 's+1'
} GET 0 \=/ 40 38
IFTE
    \>>
    \<< RAND 2 * CEIL
'x' STO 39
    \>>
    \<< { 75 90 } x
GET
    \>>
    \<< 75
    \>>
    \<< s 1 - 0 == 60
42 IFTE
    \>>
    \<< 'W' { r 's-1'
} GET 0 \=/ 60 43
IFTE
    \>>
    \<< r h == 53 44
IFTE
    \>>
    \<< 'W' { 'r+1' s
} GET 0 \=/ 53 45
IFTE
    \>>
    \<< s v \=/ 48 46
IFTE
    \>>
    \<< z 1 == 51 47
IFTE
    \>>
    \<< 1 'q' STO 49
    \>>
    \<< 'W' { r 's+1'
} GET 0 \=/ 51 49
IFTE
    \>>
    \<< RAND 3 * CEIL
'x' STO 50
    \>>
    \<< { 79 83 90 }
x GET
    \>>
    \<< RAND 2 * CEIL
'x' STO 52
    \>>
    \<< { 79 83 } x
GET
    \>>
    \<< s v \=/ 56 54
IFTE
    \>>
    \<< z 1 == 59 55
IFTE
    \>>
    \<< 1 'q' STO 57
    \>>
    \<< 'W' { r 's+1'
} GET 0 \=/ 59 57
IFTE
    \>>
    \<< RAND 2 * CEIL
'x' STO 58
    \>>
    \<< { 79 90 } x
GET
    \>>
    \<< 79
    \>>
    \<< r h == 69 61
IFTE
    \>>
    \<< 'W' { 'r+1' s
} GET 0 \=/ 69 62
IFTE
    \>>
    \<< s v \=/ 65 63
IFTE
    \>>
    \<< z 1 == 68 64
IFTE
    \>>
    \<< 1 'q' STO 80
    \>>
    \<< 'W' { r 's+1'
} GET 0 \=/ 68 66
IFTE
    \>>
    \<< RAND 2 * CEIL
'x' STO 67
    \>>
    \<< { 83 90 } x
GET
    \>>
    \<< 83
    \>>
    \<< s v \=/ 72 70
IFTE
    \>>
    \<< z 1 == 74 71
IFTE
    \>>
    \<< 1 'q' STO 73
    \>>
    \<< 'W' { r 's+1'
} GET 0 \=/ 74 73
IFTE
    \>>
    \<< 90
    \>>
    \<< 100
    \>>
    \<< 'W' { 'r-1' s
} c PUT ? 76
    \>>
    \<< 'c' 1 STO+
'V' { 'r-1' s } 2
PUT ? 'r' 1 STO- 77
    \>>
    \<< h v * 1 + c
== 0 78 IFTE
    \>>
    \<< 0 'q' STO 8
    \>>
    \<< 'W' { r 's-1'
} c PUT ? 80
    \>>
    \<< 'c' 1 STO+ 81
    \>>
    \<< 'V' { r 's-1'
} 1 PUT ? 's' 1
STO- h v * 1 + c ==
0 82 IFTE
    \>>
    \<< 0 'q' STO 8
    \>>
    \<< 'W' { 'r+1' s
} c PUT ? 84
    \>>
    \<< 'c' 1 STO+
'V' { r s } GET 0
== 86 85 IFTE
    \>>
    \<< 'V' { r s } 3
PUT ? 87
    \>>
    \<< 'V' { r s } 2
PUT ? 87
    \>>
    \<< 'r' 1 STO+ 88
    \>>
    \<< h v * 1 + c
== 0 89 IFTE
    \>>
    \<< 41
    \>>
    \<< q 1 == 96 91
IFTE
    \>>
    \<< 'W' { r 's+1'
} c PUT ? 'c' 1
STO+ 'V' { r s }
GET 0 == 93 92 IFTE
    \>>
    \<< 'V' { r s } 3
PUT ? 94
    \>>
    \<< 'V' { r s } 1
PUT ? 94
    \>>
    \<< 's' 1 STO+ h
v * 1 + c == 0 95
IFTE
    \>>
    \<< 8
    \>>
    \<< 1 'z' STO 97
    \>>
    \<< 'V' { r s }
GET 0 == 99 98 IFTE
    \>>
    \<< 'V' { r s } 3
PUT ? 0 'q' STO 100
    \>>
    \<< 'V' { r s } 1
PUT ? 0 'q' STO 1 {
r s } STO 7
    \>>
    \<< 2
    \>> }
END



-[ TERMINUS ]-