philrunninger / rpn Goto Github PK
View Code? Open in Web Editor NEWMy Ruby and Erlang implementations of a Reverse Polish Notation calculator
License: MIT License
My Ruby and Erlang implementations of a Reverse Polish Notation calculator
License: MIT License
The math problem to be solved can be entered on the command line, like so:
prompt$ rpn 6 7 *
42
In addition to printing the result, it is put into the paste buffer. This might/should also include separating the calculation engine from the UI.
The hard part will be the operators. Some will need to be escaped, which will put a damper on this even being user friendly.
Make it possible to undo operations to any prior state within the session.
It would be easier to retrieve the stack values without having to type the <
prefix, but this is the same way we invoke macros. Remove the <
prefix, and keep the current way of invoking macros the same.
<
prefix.<<
prefix. Users will just have to do a cs foo
instead of <<foo
. That's a fair tradeoff, IMO.>foo
remains the same.>>foo
remains the same.Currently, changing the colors requires changes to the code. Given that different color schemes can cause undesirable looking calculator, there should be a better, configurable way to choose colors from the palette.
Use Javascript's way of handling numbers. From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types...
Integers
Integers can be expressed in decimal (base 10), hexadecimal (base 16), octal (base 8) and binary (base 2).
- Decimal integer literal consists of a sequence of digits without a leading 0 (zero).
- Leading 0 (zero) on an integer literal indicates it is in octal. Octal integers can include only the digits 0-7.
- Leading 0x (or 0X) indicates hexadecimal. Hexadecimal integers can include digits (0-9) and the letters a-f and A-F.
- Leading 0b (or 0B) indicates binary. Binary integers can include digits only 0 and 1.
Some examples of integer literals are:
- 0, 117 and -345 (decimal, base 10)
- 015, 0001 and -077 (octal, base 8)
- 0x1123, 0x00111 and -0xF1A7 (hexadecimal, "hex" or base 16)
- 0b11, 0b0011 and -0b11 (binary, base 2)
Error message is:
wrong number of arguments (given 2, expected 1)
That's all I got right now.
This is kinda like a "Oops! I have a typo 23 numbers ago." remedy. It should present the existing stack as in initial value to be edited; otherwise, it's no better than cs
followed by retyping the stack.
DEG> 12 3 4 5 6 7 8 9 10
12 3 4 5 6 7 8 9 10 DEG> edit
New Stack: 1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10 DEG> sum
sample=[1 2 3 4 5 6 7 8 9 10] ⋅ 55 DEG>
Let the user write macros for commonly used or lengthy calculations, so they can be run quickly.
Here is the sequence of operations that reproduce the error.
$ cat ~/.rpnrc
{
"stack": [
{
"0": 1.0
},
{
"0": 2.0
},
{
"0": 3.0
}
],
"registers": {
},
"macros": {
},
"base": 0,
"angle": "DEG",
"colors": {
"title": "green",
"error": "light_red",
"register": "yellow",
"help_heading": "blue",
"help": "light_blue"
}
}
$ rpn
RPN Calculator, ©2016, Phil Runninger ═════════════════════ Enter ? for help.
1 2 3 DEG► 0 \
865: Infinity not allowed in JSON
1 2 3 Infinity DEG► <C-Z>
[1]+ Stopped rpn
At this point, I've put rpn in the background to look at the ~/.rpnrc
file. It is empty. Then I bring rpn back to the foreground, where deleting the Infinity causes the ~/.rpnrc
file to be written correctly.
JOBS philr2 ~/projects $ cat ~/.rpnrc
JOBS philr2 ~/projects $ fg
rpn
del
1 2 3 DEG►
═══════════════════════════════════════════════════════ Thanks for using rpn.
3 was copied to the clipboard.
$ cat ~/.rpnrc
{
"stack": [
{
"0": 1.0
},
{
"0": 2.0
},
{
"0": 3.0
}
],
"registers": {
},
"macros": {
},
"base": 0,
"angle": "DEG",
"colors": {
"title": "green",
"error": "light_red",
"register": "yellow",
"help_heading": "blue",
"help": "light_blue"
}
}
$
Next time into rpn, I need to reconfigure my colors, base, and angle; and I've lost my stack, registers, and macros.
Allow Infinity to be stored in the JSON file, so it's not destroyed.
This could be a big change.
It's allowing foo)
to be entered, which does nothing.
Change the display of the stack and multi-value registers to something like this before it starts wrapping on the screen.
{85 more} 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 DEG► sum
sample=[{90 more} 91 92 93 94 95 96 97 98 99 100] • 5050 DEG►
To reproduce:
RPN Calculator, ©2016, Phil Runninger ═══════════ Enter ? for help.
DEG▶︎ 1 2 3
1 2 3 DEG▶︎ asin
Numerical argument is out of domain - "asin"
1 2 3 DEG▶︎ <Enter>
═════════════════════════════════════════════ Thanks for using rpn.
Expected behavior is that 3 is put in the clipboard, but this doesn't happen.
The calculator should be able to switch between degrees and radians (the current fixed mode). This is not conversion, as is provided by deg>rad
and rad>deg
, but rather a persistent switch of mode. Once set to deg or rad, trig functions assume inputs to be in that mode or return angles in that mode.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.