Implementing Python var=input("prompt") in HP42S
|
10-25-2018, 12:12 AM
(This post was last modified: 11-04-2018 01:17 AM by tcab.)
Post: #1
|
|||
|
|||
Implementing Python var=input("prompt") in HP42S
I'd like to support Python's
Code: myvar = input() Currently Python's input() command is not supported at all by the converter. You have to use the native HP42S command INPUT, which is ok, since you can access all HP42S functions from the Python converter by invoking them as uppercase functions. Thus type INPUT(myvar) into the converter to get the RPN output INPUT "myvar". So it would be trivial for me to implement the conversion of the Python native expression myvar = input("prompt") as INPUT "myvar", which will run nicely on the HP42S, DM42, Free42. So far so good. Where it gets interesting is that Python allows you to specify a parameter to the input function, which is the prompt. I'm thinking of implementing it in RPN like this: "enter value>" PROMPT STO "myvar" a more sophisticated implementation would display the old value of the variable underneath the prompt, cater for nonexistent variables (hence the flag 25 magic) and clean up the stack as best I can afterwards, thus: SF 25 RCL "myvar" FC?C 25 0 "enter value>" PROMPT STO "myvar" RDN RDN If anybody has any thoughts on improving this implementation, please comment. Thus the full future experience would convert the Python Code: # Python code for use in www.pyrpn.atug.com Code: 00 LBL "PROMPTIN" This enhancement proposal should allow people who are typing the Python input() command to get a useful result, rather than being puzzled why that particular bit of syntax is not being converted properly. Its arguably a common enough idiom that it should be supported. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)