diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-20 22:16:39 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-20 22:16:39 +0200 |
| commit | 59d8038a2188319640863ecad33ea855b2cf3c0e (patch) | |
| tree | 1df458759107e533fe98914d1fb935ca9dabd6bd /internal/repl/repl.go | |
| parent | 77c21d86ea4c9b8621af1dcbd64acec7b65706a3 (diff) | |
feat: Implement persistent RPN state for all RPN-related input
- Modified ParseAndEvaluate() to not reset stack at beginning, only initialize if nil
- Changed runRPN() to use getRPNState() for persistent state across calls
- Fixed Stack type definition ordering in variables.go to follow Go best practices
- Updated tests to create fresh RPN instances where independence is needed
This enables REPL-style incremental RPN calculations like '3 4 +' followed by '5 +'.
Diffstat (limited to 'internal/repl/repl.go')
| -rw-r--r-- | internal/repl/repl.go | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/internal/repl/repl.go b/internal/repl/repl.go index f79f92f..3e2d4c9 100644 --- a/internal/repl/repl.go +++ b/internal/repl/repl.go @@ -109,9 +109,8 @@ func executor(input string) { // runRPN parses and evaluates an RPN expression func runRPN(input string) (string, error) { - vars := rpn.NewVariables() - rpnCalc := rpn.NewRPN(vars) - return rpnCalc.ParseAndEvaluate(input) + state := getRPNState() + return state.rpnCalc.ParseAndEvaluate(input) } // isBuiltinCommand checks if input starts with a built-in command |
