Post Reply 
HP42S commands with symbols renaming advice
02-13-2018, 02:28 AM (This post was last modified: 02-13-2018 02:41 AM by tcab.)
Post: #1
HP42S commands with symbols renaming advice
I have built a Python to RPN converter, a web based tool which lets you program the HP42S/Free42/DM42 using the Python language. You type in Python and the converter outputs a complete RPN program that you can paste into Free42.

HP42S commands which include symbols like ?!,.<>+-×÷≤≠↑Σ→ etc. are not valid Python syntax, so alternative names have been invented. Something like FS? is exposed as e.g. isFS(). The table below lists all renamed commands.

Code:

    '%':        'Percent',
    '%CH':      'PercentCH',
    '1/X':      'Reciprocal',
    '10↑X':     'CommonExp',
    'ALLΣ':     'ALLStat',
    'BASE+':    'BASEplus',
    'BASE+/–':  'BASEplusMinus',
    'BASEx':    'BASEtimes',
    'BASE÷':    'BASEdivide',
    'BASE–':    'BASEminus',
    'E↑X':      'Eto',
    'E↑X-1':    'EtoMinus1',
    'HMS+':     'HMSplus',
    'HMS–':     'HMSminus',
    'LINΣ':     'LINStat',
    'LN1+X':    'LN1plus',
    'N!':       'Factorial',
    'RDX,':     'RDXcomma',
    'RDX.':     'RDXperiod',
    'Σ+':       'StatPlus',
    'Σ-':       'StatMinus',
    'ΣREG':     'StatREG',
    'ΣREG?':    'StatWhichREG',
    '→DEC':     'toDEC',
    '→DEG':     'toDEG',
    '→HMS':     'toHMS',
    '→HR':      'toHR',
    '→OCT':     'toOCT',
    '→POL':     'toPOL',
    '→RAD':     'toRAD',
    '→REC':     'toREC',
    'FS?':      'isFS',
    'FC?':      'isFC',
    'REAL?':    'isREAL',
    'BIT?':     'testBIT',
    'CPX?':     'isCPX',
    'MAT?':     'isMAT',
    'STR?':     'isSTR',

I am looking for community input on the replacement function names that I have chosen. I have tried to keep the core HP42S name in uppercase, and describe the symbol where possible. I'm toying with the idea of making each function start with an uppercase letter - or does what I have chosen look ok?
Find all posts by this user
Quote this message in a reply
02-13-2018, 03:45 AM
Post: #2
RE: HP42S commands with symbols renaming advice
They look good to me. The one that stands out is 'CommonExp'. An alternative would be 'TENto' which would be consistent with 'Eto'.

Try CC41!
Find all posts by this user
Quote this message in a reply
02-13-2018, 06:13 AM
Post: #3
RE: HP42S commands with symbols renaming advice
(02-13-2018 02:28 AM)tcab Wrote:  I have built a Python to RPN converter, a web based tool which lets you program the HP42S/Free42/DM42 using the Python language. You type in Python and the converter outputs a complete RPN program that you can paste into Free42.

HP42S commands which include symbols like ?!,.<>+-×÷≤≠↑Σ→ etc. are not valid Python syntax, so alternative names have been invented. Something like FS? is exposed as e.g. isFS(). The table below lists all renamed commands.

Code:

    '%':        'Percent',
    '%CH':      'PercentCH',
    '1/X':      'Reciprocal',
    '10↑X':     'CommonExp',
    'ALLΣ':     'ALLStat',
    'BASE+':    'BASEplus',
    'BASE+/–':  'BASEplusMinus',
    'BASEx':    'BASEtimes',
    'BASE÷':    'BASEdivide',
    'BASE–':    'BASEminus',
    'E↑X':      'Eto',
    'E↑X-1':    'EtoMinus1',
    'HMS+':     'HMSplus',
    'HMS–':     'HMSminus',
    'LINΣ':     'LINStat',
    'LN1+X':    'LN1plus',
    'N!':       'Factorial',
    'RDX,':     'RDXcomma',
    'RDX.':     'RDXperiod',
    'Σ+':       'StatPlus',
    'Σ-':       'StatMinus',
    'ΣREG':     'StatREG',
    'ΣREG?':    'StatWhichREG',
    '→DEC':     'toDEC',
    '→DEG':     'toDEG',
    '→HMS':     'toHMS',
    '→HR':      'toHR',
    '→OCT':     'toOCT',
    '→POL':     'toPOL',
    '→RAD':     'toRAD',
    '→REC':     'toREC',
    'FS?':      'isFS',
    'FC?':      'isFC',
    'REAL?':    'isREAL',
    'BIT?':     'testBIT',
    'CPX?':     'isCPX',
    'MAT?':     'isMAT',
    'STR?':     'isSTR',

I am looking for community input on the replacement function names that I have chosen. I have tried to keep the core HP42S name in uppercase, and describe the symbol where possible. I'm toying with the idea of making each function start with an uppercase letter - or does what I have chosen look ok?

Good idea, would you give us the link to the repo?
Find all posts by this user
Quote this message in a reply
02-13-2018, 07:27 AM
Post: #4
RE: HP42S commands with symbols renaming advice
Thanks Craig, that's a good suggestion - I'll think about that. Oh and I forgot one:

Code:

    'DIM?':     'whatDIM'
Find all posts by this user
Quote this message in a reply
02-13-2018, 09:07 AM
Post: #5
RE: HP42S commands with symbols renaming advice
Wow that looks awesome !
Quick question: I have thought of implementing in RPN an algebraic equation editor/parser for the 42S, to give it this missing feature from the 32SII. I wanted to use a matrix to store a tree-like structure to store the compiled equation tokens. I have given up, no time.

But I wonder if Python could help ! Do you support something like equation parsing that would be translated into RPN ?

Thanks and cheers,

Vincent
Find all posts by this user
Quote this message in a reply
02-13-2018, 11:21 AM
Post: #6
RE: HP42S commands with symbols renaming advice
(02-13-2018 09:07 AM)Vincent Weber Wrote:  But I wonder if Python could help ! Do you support something like equation parsing that would be translated into RPN ?

Hey Vincent. Equation parsing sounds pretty ambitious - certainly a higher level language like Python will multiply your chances significantly. My Python to RPN converter doesn't have any specific parsing or token related functionality like e.g. the tokenize module. It is simply core Python syntax (which is very powerful), but no built in Python libraries that you would get in desktop Python. You have to rely on the ability to call HP42S commands from Python to do your work. Specifically, it has the following capabilities:
  1. Variables
  2. Functions, Multiple functions, nested functions
  3. Parameter passing, receiving return values, multiple return values
  4. if elif else
  5. Comparison operators == != > < >= <=
  6. Booleans True, False and operators not or and
  7. for loops, range(), for..in iteration through lists and dictionary keys
  8. while loops, while...else
  9. continue and break operations in for loops and while loops
  10. Lists and Dictionaries (basic operations only).
  11. Matrices, Pythonic matrix element access syntax [row,col]
  12. NumPy compatible slicing syntax for sub-matrices
  13. Complex numbers using either 42S or Python native syntax
  14. Expressions involving nested brackets
  15. assert
  16. Testing and clearing of flags
  17. Access most HP42S commands as function calls e.g. FIX(2)
  18. Some enhanced functions to make like easier e.g. varmenu() automates and simplifies the generation of MVAR based code.

You write in Python, hit a button and RPN is generated. Paste the RPN into Free42 or transfer it to your DM42 - and it runs.
I've sent you a PM with the beta site url. If anybody else is interested, feel free to PM me.

cheers,
Andy
Find all posts by this user
Quote this message in a reply
02-13-2018, 11:32 AM
Post: #7
RE: HP42S commands with symbols renaming advice
Wonderful, Andy, thank you!

Another way to love DM42/Free42/HP42s!

Salvo

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
02-13-2018, 12:04 PM
Post: #8
RE: HP42S commands with symbols renaming advice
(02-13-2018 11:32 AM)salvomic Wrote:  Wonderful, Andy, thank you!

Another way to love DM42/Free42/HP42s!

Salvo

Thanks Salvo. I agree - in fact I'm specifically targeting the HP42S/Free42/DM42 because it is the HP design that I love the most. I am so happy that Free42 will always be there and that the DM42 was recently created.

Python does open up possibilities for the DM42 e.g. I ported some graphic primitive routines originally written for the Raspberry Pi in C into Python:
Code:

draw_line(x0, y0, x1, y1)
draw_rect(x0, y0, w, h)
fill_rect(x0, y0, w, h)
draw_circle(x0, y0, r)
fill_circle(x0, y0, r)

which I then converted to HP42S RPN using my converter. This then allowed me to create images like this:

[Image: 20180127-11561967.png?raw=1]

and targeting the larger screen size of the DM42 - this image:

[Image: 20180127-12134373.png?raw=1]

Creating these drawing primitives directly in RPN would have been a big project for someone, I think. It only took me a few hours using Python, and I could draw upon existing algorithms I found on the internet.
Find all posts by this user
Quote this message in a reply
02-13-2018, 12:20 PM
Post: #9
RE: HP42S commands with symbols renaming advice
@tcab, Kudos for your work, this is impressive and opens a lot of applications for the DM42 !
Find all posts by this user
Quote this message in a reply
02-13-2018, 01:29 PM
Post: #10
RE: HP42S commands with symbols renaming advice
(02-13-2018 12:04 PM)tcab Wrote:  in fact I'm specifically targeting the HP42S/Free42/DM42 because it is the HP design that I love the most. I am so happy that Free42 will always be there and that the DM42 was recently created.

Python does open up possibilities for the DM42 e.g. I ported some graphic primitive routines originally written for the Raspberry Pi in C into Python:
...

which I then converted to HP42S RPN using my converter. This then allowed me to create images like this:
...

Creating these drawing primitives directly in RPN would have been a big project for someone, I think. It only took me a few hours using Python, and I could draw upon existing algorithms I found on the internet.

Well, right!
Please, if you think is ok, could you post something about this subject in the SwissMicros forum also?
I think there many people could appreciate your work...

Salvo

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




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