prefix notation and () on newRPL project
|
01-21-2019, 05:06 PM
Post: #1
|
|||
|
|||
prefix notation and () on newRPL project
Hi Claudio,
2 Crazy ideas =) ◉ Observing the u_LISP project that has a notation similar to the prefix notation, and that the R-PN is a inverse prefix. So I "think" it's easy to add a second type of operation engine PN/prefix ("eliminate" the Reverse) or consult it in this community if they are involved in this type of notation in your project. (3+4) * (5-6) returns -7 // "infix" operation or what better should be called standard notation *( +(3,4), -(5,6) ) prefix operation with ( ) * + 3 4 - 5 6 prefix operation ◉ A second idea, RPN with parentheses, this gives a faster interpretation of the source code 3 4 + 5 6 - * postfix operation ((3,4)+, (5,6)-)* postfix operation with () The importance of the use of parentheses is that each operator can operate on n arguments (a,b,c)+ (a,b,c,d,e)- |
|||
01-21-2019, 05:51 PM
Post: #2
|
|||
|
|||
RE: prefix notation and () on newRPL project
(01-21-2019 05:06 PM)compsystems Wrote: Hi Claudio, While crazy, adding alternate syntax rules to RPL is possible and I'm considering an alternate language to the same code. The idea is to compile code in other languages to an RPL stream. Decompiling is much more complex so it would probably have to keep the source code separate (like most compiled languages). Lisp would be very straighforward: An opening parenthesis simply compiles as the start of a list '{', everything gets pushed to the stream until a closing parenthesis is found, which is compiled as an end of list '}'. Then parenthesis simply pushes the number of arguments, then does LIST-> ROLL EVAL to execute the first argument. But rather than adding a language of similar difficulty as RPL, the idea is to add a much higher level language, like Lua or python. Compiling these languages is very difficult, so I'm still studying this as a possibility, not saying I might do it. |
|||
01-21-2019, 06:17 PM
Post: #3
|
|||
|
|||
RE: prefix notation and () on newRPL project
(01-21-2019 05:51 PM)Claudio L. Wrote: Lisp would be very straightforward … Not sure if you are aware of the power of Lisp macros. Cheers Thomas |
|||
01-21-2019, 07:40 PM
(This post was last modified: 01-21-2019 08:24 PM by Albert Chan.)
Post: #4
|
|||
|
|||
RE: prefix notation and () on newRPL project
(01-21-2019 05:06 PM)compsystems Wrote: ◉ Observing the u_LISP project that has a notation similar to the prefix notation, and that the R-PN is a inverse prefix. Infix or rpn macro is not hard, but you are better off stay with lisp syntax. It does not take much time to get used to (* (+ 3 4) (- 5 6)) BTW, does u-lisp support macro ? Quote:◉ A second idea, RPN with parentheses, this gives a faster interpretation of the source code It might not run faster. I never tried u-lisp, but with Chez scheme 7.4d, (+ a b c) is slower than (+ (+ a b) c) Above assumed a,b,c are variables. With numbers, both form optimized to a single number. |
|||
01-21-2019, 09:37 PM
Post: #5
|
|||
|
|||
RE: prefix notation and () on newRPL project
(01-21-2019 06:17 PM)Thomas Klemm Wrote: Not sure if you are aware of the power of Lisp macros. I wasn't. I did a lot of Lisp programming many years ago, but not on a general purpose Lisp. I used to code AutoLISP, the implementation used in AutoCAD. I have no idea if that implementation had macros (since AutoCAD has another syntax for macros called Diesel), and I never needed to use them anyway. But it looks really powerful. Unfortunately, that's not what I was talking about in this thread, implementing macros is a whole different animal than just doing the basic syntax over the RPL execution engine. |
|||
01-22-2019, 03:06 PM
Post: #6
|
|||
|
|||
RE: prefix notation and () on newRPL project
(01-21-2019 05:51 PM)Claudio L. Wrote: But rather than adding a language of similar difficulty as RPL, the idea is to add a much higher level language, like Lua or python. Python on my 50g would be quite incredible! List comprehension alone would make my day. Hmm. How hard would it be to do list comprehension in newRPL? I'm guessing very, but I honestly have no real idea. Syntax would be something like the bastard love-child of FOR/NEXT and SEQ. |
|||
01-22-2019, 07:32 PM
Post: #7
|
|||
|
|||
RE: prefix notation and () on newRPL project
(01-22-2019 03:06 PM)The Shadow Wrote: List comprehension alone would make my day. What's wrong with SEQ? Python >>> [ x**2 + 1 for x in range(1, 11, 2) ] [2, 10, 26, 50, 82] Algebraic 'SQ(X)+1' 'X' 1 9 2 SEQ { 2 10 26 50 82 } Or using RPL « X SQ 1 + » 'X' 1 9 2 SEQ { 2 10 26 50 82 } Kind regards Thomas |
|||
04-20-2020, 02:01 AM
(This post was last modified: 04-22-2020 08:43 PM by Albert Chan.)
Post: #8
|
|||
|
|||
RE: prefix notation and () on newRPL project
Here is a *fast* rpn macro for Chez Scheme
Instead of using macro pattern matching, the code rearrange the list of syntax objects. Code: (define ^ expt) scheme> (load "rpn.ss") scheme> (define phi (rpn 5 sqrt @ 1 + 2 /)) scheme> (define (fib n) (rpn phi n ^ 1 phi - n ^ - 5 sqrt @ /)) scheme> (fib 10) 55.000000000000014 scheme> (fib 20) 6765.000000000005 |
|||
04-23-2020, 05:06 PM
(This post was last modified: 11-04-2024 05:55 PM by Albert Chan.)
Post: #9
|
|||
|
|||
RE: prefix notation and () on newRPL project
For completeness, this is my attempt for infix-to-prefix calc macro, for Chez Scheme
Note: the code scan tokens in reverse, from right to left. This simplified code to use stack only for (* /) (calc whatever +/- x) ⇒ (+/- (calc whatever) x) ; unary ± has higher precedence than infix ± (calc whatever x ^ y) ⇒ (calc whatever (^ x y)) ; ^ has associativity right to left Code: (define ^ expt) scheme> (load "calc.ss") scheme> (calc - 2 ^ 3 ^ 4) ; = - (2 ^ (3 ^ 4)) -2417851639229258349412352 scheme> (calc - (2 ^ 3) ^ 4) -4096 scheme> (calc 1 + 2 3 4) ; implied multiply 25 scheme> (define (calc-expand s) (syntax->datum (calc-aux (syntax->list s)))) scheme> (calc-expand #'(1 + 2 3 4)) (+ 1 (* (* 2 3) 4)) scheme> (define phi (calc (1 + (@ sqrt 5)) / 2)) scheme> (define (fib n) (calc (phi ^ n - (1 - phi) ^ n) / (@ sqrt 5))) scheme> (fib 10) 55.000000000000014 scheme> (fib 20) 6765.000000000005 calc macro had unary (+ -) between binary (* /) and (+ -), similar to Fortran 77 see http://macnauchtan.com/pub/precedence.html#_Fortran 2024/11/4: 1. added unary +/- feature (next post) scheme> (calc-aux '(- 3 * + 4 ^ - 5)) (* (- 3) (+ (^ 4 (- 5)))) 2. added recursing into @ function arguments scheme> (calc (@ sqrt (5 *(((((1 + .2 *(350 / 661.5)^ 2)^ 3.5 - 1)* (1 - 6.875E-6 * 25500)^ - 5.2656)+ 1)^ .286 - 1)))) 0.8357245351752515 |
|||
12-23-2022, 02:59 AM
(This post was last modified: 12-25-2022 06:12 PM by Albert Chan.)
Post: #10
|
|||
|
|||
RE: prefix notation and () on newRPL project
(12-23-2022 12:02 AM)Albert Chan Wrote: How to distinguish subtraction from negation Patched above (op +/-) logic to calc macro (previous post) Also, unary +/- precedence placed below POW, above MUL/DIV, similar to Python/Lua Before: Code: ((+ -) (if (null? (cdr e)) After: Code: ((+ -) (if (null? (cdr e)) Test with calc-expand macro (previous post) scheme> (calc-expand '(2 ^ - 3 ^ 4)) ; op +/- tests (^ 2 (- (^ 3 4))) scheme> (calc-expand '(2 * - 3 / 4)) (/ (* 2 (- 3)) 4) scheme> (calc-expand '(- 2 ^ 3 ^ 4)) ; unary +/- precedence below POW (- (^ 2 (^ 3 4))) scheme> (calc-expand '(- 2 * 3 / 4 )) ; unary +/- precedence above MUL/DIV (/ (* (- 2) 3) 4) And, for Mach number test. Spaces are needed to separate the tokens. scheme> (sqrt (calc 5 *(((((1 + .2 *(350 / 661.5)^ 2)^ 3.5 - 1)* (1 - 6.875E-6 * 25500)^ - 5.2656)+ 1)^ .286 - 1))) 0.8357245351752515 For comparison, we figured precedence rules, then use rpn macro. scheme> (rpn 350 661.5 / 2 ^ .2 * 1 + 3.5 ^ 1 - 1 6.875E-6 25500 * - -5.2656 ^ * 1 + .286 ^ 1 - 5 * sqrt @) 0.8357245351752515 |
|||
01-13-2023, 04:15 PM
(This post was last modified: 01-13-2023 11:22 PM by carey.)
Post: #11
|
|||
|
|||
RE: prefix notation and () on newRPL project
(01-22-2019 07:32 PM)Thomas Klemm Wrote:(01-22-2019 03:06 PM)The Shadow Wrote: List comprehension alone would make my day. Thomas, thanks for this clear comparison! Just out of curiosity to see what this SEQ example would look like using the HP50g's not-often used algebraic mode (in contrast to the algebraic example in the quoted post that uses an algebraic expression in rpn mode), the following worked: Code:
{ 2 10 26 50 82 } Two things surprised me: (i) the algebraic mode parameter list for SEQ was intuitive so it was easy to guess right the first time, and although I'm reluctant to admit it, (ii) the function call looks nicer (to me) in algebraic mode than in RPL or Python. |
|||
01-14-2023, 12:29 AM
Post: #12
|
|||
|
|||
RE: prefix notation and () on newRPL project
(01-13-2023 04:15 PM)carey Wrote:(01-22-2019 07:32 PM)Thomas Klemm Wrote: What's wrong with SEQ? I agree with you. But fortunately, you can do the same thing in RPN mode. It's probably a little slower though. Just surround the entire expression with the character #96. I mean: << 96 CHR >> on your calculator or SHIFT↱ + CHARS ... then it's just the character before the lowercase "a" (unicode U+2035 on a computer). << ‵SEQ('SQ(X) + 1', 'X', 1, 9, 2)‵ >> Bruno Sanyo CZ-0124 ⋅ TI-57 ⋅ HP-15C ⋅ Canon X-07 + XP-140 Monitor Card ⋅ HP-41CX ⋅ HP-28S ⋅ HP-50G ⋅ HP-50G |
|||
01-14-2023, 01:20 AM
(This post was last modified: 01-14-2023 01:51 AM by carey.)
Post: #13
|
|||
|
|||
RE: prefix notation and () on newRPL project
(01-14-2023 12:29 AM)FLISZT Wrote: I agree with you. FLISZT, That's so cool that entire algebraic mode function calls (and not just algebraic expressions) can be used in rpn mode! Thank you, Carey |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: