Post Reply 
Python to RPN converter
02-19-2018, 02:29 AM
Post: #21
RE: Python to RPN converter
(02-17-2018 02:33 PM)rprosperi Wrote:  At least half the members here prefer RPN over RPL.

Thanks for the memories.

My first programming "experience" was RPN - and I learned from the books that came with the HP-41. loved it.
Eventually, I bought a 48. Hated RPL.

To this day, I still don't know whether to blame RPL itself, or the documentation that came with the HP-48.
Find all posts by this user
Quote this message in a reply
02-19-2018, 02:54 AM
Post: #22
RE: Python to RPN converter
(02-19-2018 02:29 AM)sa-penguin Wrote:  
(02-17-2018 02:33 PM)rprosperi Wrote:  At least half the members here prefer RPN over RPL.

Thanks for the memories.

My first programming "experience" was RPN - and I learned from the books that came with the HP-41. loved it.
Eventually, I bought a 48. Hated RPL.

To this day, I still don't know whether to blame RPL itself, or the documentation that came with the HP-48.

I have figured out the perfect response when somebody asks me if I prefer RPN or RPL HPs:

"How about that sweet 71b! What a BASIC!"
Find all posts by this user
Quote this message in a reply
02-19-2018, 06:27 AM
Post: #23
RE: Python to RPN converter
(02-19-2018 02:54 AM)polbit Wrote:  "How about that sweet 71b! What a BASIC!"

Not blasphemy - must be heresy.
Find all posts by this user
Quote this message in a reply
02-19-2018, 07:16 AM (This post was last modified: 02-19-2018 07:25 AM by StephenG1CMZ.)
Post: #24
RE: Python to RPN converter
Tcab, I am puzzled when you ask for source code without the line numbers "that I added".
Those line numbers are actually part of your original demo, and were not deleted after pasting here Smile


Attached File(s) Thumbnail(s)
   

Stephen Lewkowicz (G1CMZ)
Does every Android "improvement" make Android worse?
Visit this user's website Find all posts by this user
Quote this message in a reply
02-19-2018, 07:29 AM
Post: #25
RE: Python to RPN converter
Ah I see what might have happened with your copy paste fragment getting those strange line numbers... Python of course has no line numbers, but there are indeed line numbers in the margin of the Python editor (like in most programming editors) but they are not part of the source code and usually impossible to copy out - at least in desktop browsers and iOS browsers. Somehow you managed to select them and copy them!

It might better to use a desktop browser to become familiar with the site - I haven't tested the site under android yet sorry.
Find all posts by this user
Quote this message in a reply
02-19-2018, 07:48 AM
Post: #26
RE: Python to RPN converter
Its only on this forum the line numbers combine with the source - Convert didn't complain until line 7 of my demo2 so I guess wasn't seeing the line numbers.

Right now, I only have Android available - the PC needs fixing.
Thanks for your help.

Stephen Lewkowicz (G1CMZ)
Does every Android "improvement" make Android worse?
Visit this user's website Find all posts by this user
Quote this message in a reply
02-19-2018, 08:17 AM
Post: #27
RE: Python to RPN converter
No worries. I've gone ahead and implemented a Clear button and a New Project link - as well as removing the initial demo code from the converter.

Other features released today include a new LBL main start point for programs, allowing access to the Python global scope area - great for sharing variables between functions. Programs written with this paradigm are likely to be more appealing to RPN programmers and look like:
Code:

LBL("main")

length = 10
width = 20

report()

def report():
  print('length is', length, '[LF]width is', width)

Variable references now look outwards from functions into their outer functions (if any)... all the way to global scope - until they find the variable. This is how nested scope works in most programming languages, including Python. Read all about scope in the help file.

Other features released today are the ability to edit and delete cloned example snippets, as well as vote on them. A new simplified menu() command has been added - there are a couple of examples showing how you can rapidly build custom menus and submenus.
Find all posts by this user
Quote this message in a reply
02-19-2018, 11:15 AM
Post: #28
RE: Python to RPN converter
Would be interesting to see how "optimized" is the code generated by the converter (that is not a primary objective here, it is already great to get a conversion).

For example with a summation: http://www.hpmuseum.org/forum/thread-9750.html

Or some array work: http://www.hpmuseum.org/cgi-sys/cgiwrap/...i?read=700

From the last one the code for the dm42 is
Code:

LBL A   CLRG
         8 STO 11
 LBL 00  RCL 00 RCL 11
         X=Y? GTO 04
         ISG 00 DEG
         STO IND 00
 LBL 01  ISG 10 DEG
         RCL 00 STO 09
 LBL 02  DSE 09 DEG
         RCL 09 X=0? GTO 00
         RCL IND 00 RCL IND 09 -
         X=0? GTO 03
         ABS RCL 00 RCL 09 -
         X<>Y? GTO 02
 LBL 03  DSE IND 00 GTO 01
         DSE 00 GTO 03
 LBL 04  RCL 10
         RTN

Wikis are great, Contribute :)
Find all posts by this user
Quote this message in a reply
02-19-2018, 07:36 PM
Post: #29
RE: Python to RPN converter
Thanks Tcab, that new UI is now usable on Android...much better.

Stephen Lewkowicz (G1CMZ)
Does every Android "improvement" make Android worse?
Visit this user's website Find all posts by this user
Quote this message in a reply
02-20-2018, 02:28 PM (This post was last modified: 02-20-2018 02:43 PM by StephenG1CMZ.)
Post: #30
RE: Python to RPN converter
I have a couple of queries, which may be obvious to anyone that has used HP42 before.

First, with any code formatted like this, I am finding that the converted code starts with a label followed by a RTN. I seem to have to delete the RTN for the program to execute.

I presume I am doing something wrong. I tried moving the LBL but so far without success.

Second, if I include LOCAT() in the source, I get a Label Not Found error executing the program.
I guess that means free42's LOCAT is not available to Python.
I am sure there must be some way of using it, but being new to the 42 I haven't yet figured it out.
I tried creating LOC8 which called LOCAT, but haven't figured out the 42 usage yet.
Code:



LBL("H1")

def Here():
  Lat=42
  Lon=24
  Lat,Lon,Elv,XX=LOC8()
  print('Lat',Lat,'Lon',Lon,'Elv',Elv)
  AVIEW()
I am using free42 and Android.

Stephen Lewkowicz (G1CMZ)
Does every Android "improvement" make Android worse?
Visit this user's website Find all posts by this user
Quote this message in a reply
02-20-2018, 10:39 PM (This post was last modified: 02-20-2018 11:43 PM by tcab.)
Post: #31
RE: Python to RPN converter
The reason your program is not running when you call "H1" is that it is not calling the "Here" function. You have to call Python functions to run them. So your code should be:
Code:

LBL("H1")
Here()

def Here():
  Lat=42
  Lon=24
  Lat,Lon,Elv,XX=LOC8()
  print('Lat',Lat,'Lon',Lon,'Elv',Elv)
  AVIEW()

Another way to write this is to get rid of the LBL and simply
Code:

def Here():
  Lat=42
  Lon=24
  Lat,Lon,Elv,XX=LOC8()
  print('Lat',Lat,'Lon',Lon,'Elv',Elv)
  AVIEW()
in which case the first function name becomes the RPN global label "Here", and you can execute that from your calculator.

Or you can even run your code in the global namespace like this:
Code:

LBL("H1")

Lat=42
Lon=24
Lat,Lon,Elv,XX=LOC8()
print('Lat',Lat,'Lon',Lon,'Elv',Elv)
AVIEW()

As for your calls to LOCAT and LOC8 - they are not defined anywhere and don't exist on the HP42S (see cmd reference) and so are being converted to local label calls starting with single letters e.g. XEQ B - which won't exist if you try to run the code.

Finally - a small point - you don't need the AVIEW after the print() because print() already generates an AVIEW for you. See the section on text and the alpha register in the help page.
Find all posts by this user
Quote this message in a reply
06-01-2018, 01:39 AM
Post: #32
RE: Python to RPN converter
Very nice work!
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)