newmanrs / rpncalc Goto Github PK
View Code? Open in Web Editor NEWBuilding out the command line calculator that I wish I had in college, now with history buffers and support for matrix algebra.
License: MIT License
Building out the command line calculator that I wish I had in college, now with history buffers and support for matrix algebra.
License: MIT License
Catching generic errors especially in interactive mode is a bit dirty. Make custom errors to catch in all of the calculator operators.
Stored variables and other state are not stored in the command history, only the input command. Edit to store the full stack, stored variables, and flags given to the program. See #5. The lines might get long if I store json objects in addition to the commands, so printing may require textwrapping to terminal width like the help page did.
Save/load functions have some quirky json serialization of data structures (casting deque to list) and probably ought to have tests.
The state.py
submodule contains singleton pattern that makes using this project as a submodule of another awkward. Consider refactoring and make the main command line loop (or wherever) thread instantiate a Calculator() object that encapsulates the state.
This probably a significant refactor, at the least:
Fixing this should also allow me to use this project as a submodule for a streamlit app so I can have browser or phone based access to my own calculator demo using their free cloudservice.
Refactor utils classes to have better error handling.
Main state "stack" for calculator possibly better as deque than list. Changing this probably requires some patches in most print statements involving the stack, which also probably should go via centralized functions instead of different parts of the code directly accessing the stack.
Add interface to save and restore calculator state to files using the state classes' snapshot mechanisms to dictionary/json. This will allow users that store values as named variables to reload them later.
Interactive mode would be better with a command history bound to up-arrow key.
Command history in non-interactive mode always appends command history even if it's the same command. I.e. running rpncalc 1 1 +
twice in a row will append twice.
Last refactor changed behaviour of the print statements showing the stored values. This kind of just makes a horrible mess of an output to things like: rpncalc 0 1 2 3 4 veca store_x 2 3 4 5 6 veca store_y _x 0 ^ _x 1 ^ hstack store_V _V T _V dot inv _V T dot _y dot
Having the stack in a module is not the only state that needs access and mutation from the calculator actions, as well as roll-back upon crash.
Create a "State" class that also contains verbose/not verbose modes, toggles for clearing the stack (or not) after commands, and move the stored values into this class as well.
This would also be a good time to store a history of the most recent few actions so that they can be repeated, something akin to rpncalc d4 10 repeat_n
to roll 4-sided dice 10 times.
The input parsing and behavior of the calculator with different arg flags in parse_expression and compute_rpn remains awkward. The function run_from_expr in the test suite, interactive and noninteractive modes call these functions slightly differently, but these should be unified. The clever hack of inserting print statements to implement verbose mode also causes kludges elsewhere when repeating last command (have to ignore prints). This could be removed just by making flags incl/ verbose part of the calculator state, and triggering on item.action() consumption.
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.