Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ibudasov/rpn-calculator
๐งฎ This calculator uses CLI and Reverse ๐ต๐ฑ Notation (RPN) for operating it. Nicely extendable with new operations
https://github.com/ibudasov/rpn-calculator
memento-pattern rpn rpn-calculator stack
Last synced: 17 days ago
JSON representation
๐งฎ This calculator uses CLI and Reverse ๐ต๐ฑ Notation (RPN) for operating it. Nicely extendable with new operations
- Host: GitHub
- URL: https://github.com/ibudasov/rpn-calculator
- Owner: ibudasov
- Created: 2020-12-12T10:19:55.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2021-01-07T11:47:24.000Z (about 4 years ago)
- Last Synced: 2025-01-01T20:03:04.515Z (20 days ago)
- Topics: memento-pattern, rpn, rpn-calculator, stack
- Language: Kotlin
- Homepage:
- Size: 132 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Reverse Polish Notation (RPN) Calculator
The calculator has a stack that can contain real numbers.
โข The calculator waits for user input and expects to receive strings containing whitespace separated lists of numbers and operators.
โข Numbers are pushed on to the stack. Operators operate on numbers that are on the stack. โข Available operators are +, -, *, /, sqrt, undo, clear.
โข Operators pop their parameters off the stack, and push their results back onto the stack.
โข The โclearโ operator removes all items from the stack.
โข The โundoโ operator undoes the previous operation. โundo undoโ will undo the previo us two operations.
โข sqrt performs a square root on the top item from the stack.
โข The โ+โ, โ-โ, โ*โ, โ/โ operators perform addition, subtraction, multiplication and division respectively on the top two items from the stack.
โข After processing an input string, the calculator displays the current contents of the stack as a space-separated list.
โข Numbers should be stored on the stack to at least 15 decimal places of precision, but displayed to 10 decimal places (or less if it causes no loss of precision).
โข All numbers should be formatted as plain decimal strings (ie. no engineering formatting).
โข If an operator cannot find a sufficient number of parameters on the stack, a warning is displayed:
operator (position: ): insufficient parametersโข After displaying the warning, all further processing of the string terminates and the current state of the stack is displayed.
## Ideas behind the design
- I was trying to be as expressive in code as possible, by naming things according to domain terms and project
requirements like: `SorryCannotFindSufficientNumberOfParametersInTheStack`
, `Operation.performOperationAndAddResultToStack()`, etc., to make the code as clear as possible for those who
understand the domain
- I was trying to follow Hexagonal/DDD approach, by splitting the whole project to `domain`, `application`
and `infrastructure` layers
- `infrastructure` layer contains only CLI interface, but later on โ will be able to support also web interface
- All the calculator logic is contained in the `domain` layer, and adding a new operation shall not involve anything
from `application` or `infrastructure` layers## Install
`git clone [email protected]:ibudasov/rpn-calculator.git`
## Use
`MainKt.main` ๐ run it in your IDE ๐โ
## Todo
- preserve stack between inputs, so the operations can be chained