Last active
March 21, 2024 08:09
-
-
Save refaktor/63693faae0bea092da092f45920daaa9 to your computer and use it in GitHub Desktop.
Improved RPN Calculator in Rye, original made by Capital-EX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; This is improved example of *RPN calculator* originally made CapitalEx from Discord/Concatenative | |
; https://gist.github.com/Capital-EX/d08a37765ef898cd432f662ffc7aaf98 | |
rye .needs { fyne } | |
do\in fyne { | |
append-a: fn { n } { value-a .get-text .concat n |set-text* value-a } | |
num-button: fn { n } { button n [ 'append-a n ] } | |
calc-button: fn { lbl op1 } { | |
op: get first op1 | |
button lbl closure { } { | |
value-b .get-text .to-integer :x | |
value-a .get-text .to-integer :y | |
op x y |to-string .set-text* value-a | |
value-b .set-text "" | |
} | |
} | |
vbox: container 'vbox _ ; this is experimental, might not stay in lang (currying variant) | |
hbox: container 'hbox _ | |
cont: vbox [ | |
hbox [ label "B:" entry :value-b ] | |
hbox [ label "A:" entry :value-a ] | |
hbox [ | |
num-button "1" num-button "2" num-button "3" | |
calc-button "/" { / } | |
] | |
hbox [ | |
num-button "4" num-button "5" num-button "6" | |
calc-button "*" { * } | |
] | |
hbox [ | |
num-button "7" num-button "8" num-button "9" | |
calc-button "-" { - } | |
] | |
hbox [ | |
num-button "0" | |
button "=" { value-a .get-text .set-text* value-b , value-a |set-text "" } | |
button "~" { value-b .get-text .pass { value-a .get-text .set-text* value-b } |set-text* value-a } | |
calc-button "+" { + } | |
] | |
] | |
app .new-window "RPN calculator" |set-content cont |show-and-run | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment