Giter VIP home page Giter VIP logo

rpncalc's People

Contributors

newmanrs avatar

Watchers

 avatar

rpncalc's Issues

Printing storage is annoying

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

Command history should serialize full state

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.

Refactor global state

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.

Singleton state

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:

  • Move compute functions into new Calculator class
  • Add instance of State to Calculator class
  • ActionEnum class constructors needs to know what State object this calculator is using instead of module variables
    • Consider better control of access to the state object (most code uses take_1, take_2, take_n, and push operators) but others seem to read or mutate the state directly. Maybe should provide a read_all or read_n method, or add the print functions to the state class (#11?) and not custom to the ActionEnums.
  • History module also is stateful/singleton and needs to be made into a class that is optionally instantiated by the Calculator class. This also should also improve the now hardcoded HIST_LENGTH and HIST_LOC constants as init parameters.

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.

Add Save/Restore State Snapshots

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.

List to Deque

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.

Throw custom errors

Catching generic errors especially in interactive mode is a bit dirty. Make custom errors to catch in all of the calculator operators.

Verbose mode too verbose

  • Compact pushing of values/constants to stack to have one print statement only.
  • Print statements also ought not trigger double print in verbose mode.
  • Check which other operators should not trigger print statements. Probably the entire set of idempotent operators.

Clean up expression parser interactions with flags

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.