diff options
| author | Paul Buetow <paul@buetow.org> | 2026-05-23 23:56:14 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-05-23 23:56:14 +0300 |
| commit | cd74d811d257d5579fbe974abbd6ad39a751d508 (patch) | |
| tree | cc8b59822252e35231573b86593e54f6e4ab2c1e | |
| parent | d106b9ac10c67a7e1c98dbb626e17c22b70048ec (diff) | |
docs(rpn): fix misleading comments in rpn_ops.go
- EvalOperator: replace incorrect example ("1 2 +" then "+") with one
matching the actual test ("1 2 3 +" then "+") since + requires two
operands and the stack after "1 2 +" only has one value
- executeOperator: update comment to list all three callers
(handleOperator, ResultStack, EvalOperator) instead of just two
| -rw-r--r-- | internal/rpn/rpn_ops.go | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/internal/rpn/rpn_ops.go b/internal/rpn/rpn_ops.go index 0c46576..5f0863a 100644 --- a/internal/rpn/rpn_ops.go +++ b/internal/rpn/rpn_ops.go @@ -72,7 +72,8 @@ func (r *RPN) ResultStack(tokens []string) (string, error) { } // EvalOperator evaluates a single operator on the current stack state. -// This allows incremental RPN operations like: "1 2 +" then "+". +// This allows incremental RPN operations, e.g., after ParseAndEvaluate("1 2 3 +") leaves +// the stack with [1, 5], calling EvalOperator("+") produces "6". func (r *RPN) EvalOperator(op string) (string, error) { if r.currentStack == nil { r.currentStack = NewStack() @@ -97,7 +98,7 @@ func (r *RPN) EvalOperator(op string) (string, error) { } // executeOperator handles operator execution (standard or hyper) and returns (result string, handled bool, error error). -// This is a helper to avoid code duplication between handleOperator and EvalOperator. +// This is a shared helper used by handleOperator, ResultStack, and EvalOperator. func (r *RPN) executeOperator(stack *Stack, token string) (string, bool, error) { // Check for hyperoperators first if r.opRegistry.IsHyperOperator(token) { |
