HP Forums
HP42S commands with symbols renaming advice - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: Not HP Calculators (/forum-7.html)
+--- Forum: Not quite HP Calculators - but related (/forum-8.html)
+--- Thread: HP42S commands with symbols renaming advice (/thread-10160.html)



HP42S commands with symbols renaming advice - tcab - 02-13-2018 02:28 AM

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?


RE: HP42S commands with symbols renaming advice - Craig Bladow - 02-13-2018 03:45 AM

They look good to me. The one that stands out is 'CommonExp'. An alternative would be 'TENto' which would be consistent with 'Eto'.


RE: HP42S commands with symbols renaming advice - cappy2112 - 02-13-2018 06:13 AM

(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?


RE: HP42S commands with symbols renaming advice - tcab - 02-13-2018 07:27 AM

Thanks Craig, that's a good suggestion - I'll think about that. Oh and I forgot one:

Code:

    'DIM?':     'whatDIM'



RE: HP42S commands with symbols renaming advice - Vincent Weber - 02-13-2018 09:07 AM

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


RE: HP42S commands with symbols renaming advice - tcab - 02-13-2018 11:21 AM

(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


RE: HP42S commands with symbols renaming advice - salvomic - 02-13-2018 11:32 AM

Wonderful, Andy, thank you!

Another way to love DM42/Free42/HP42s!

Salvo


RE: HP42S commands with symbols renaming advice - tcab - 02-13-2018 12:04 PM

(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.


RE: HP42S commands with symbols renaming advice - Didier Lachieze - 02-13-2018 12:20 PM

@tcab, Kudos for your work, this is impressive and opens a lot of applications for the DM42 !


RE: HP42S commands with symbols renaming advice - salvomic - 02-13-2018 01:29 PM

(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