summaryrefslogtreecommitdiff
path: root/internal/rpn/operator_registry.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-23 23:04:11 +0300
committerPaul Buetow <paul@buetow.org>2026-05-23 23:04:11 +0300
commitd56e16dc85ff3efe7b5865bd27e4804423a6e463 (patch)
tree4d2d94459dd3ea74d71dc26ce2d952419c7d9f02 /internal/rpn/operator_registry.go
parente3978519df6e7ec34627100401805a6bda619f92 (diff)
feat: wire DeleteVariable to OperatorRegistry as 'd' operator
The 'd' token was previously a no-op error. Now it pops a value from the stack and deletes the variable with that name. Accepts Symbol (:x) or StringNum as the variable name. Added DeleteVariable to VariableOperator interface so the operator can call it through the Operator interface. Example: x 5 = :x d vars → No variables defined
Diffstat (limited to 'internal/rpn/operator_registry.go')
-rw-r--r--internal/rpn/operator_registry.go16
1 files changed, 15 insertions, 1 deletions
diff --git a/internal/rpn/operator_registry.go b/internal/rpn/operator_registry.go
index f2ea64f..9f8e9c8 100644
--- a/internal/rpn/operator_registry.go
+++ b/internal/rpn/operator_registry.go
@@ -54,7 +54,21 @@ func NewOperatorRegistry(op Operator) *OperatorRegistry {
registry.registerStandardOperator("swap", func(stack *Stack) error { return op.Swap(stack) })
registry.registerStandardOperator("pop", func(stack *Stack) error { return op.Pop(stack) })
registry.registerStandardOperator("d", func(stack *Stack) error {
- return fmt.Errorf("'d' command not supported as standalone token")
+ val, err := popStack(stack, "d")
+ if err != nil {
+ return err
+ }
+ // Extract variable name from the value
+ var name string
+ switch v := val.(type) {
+ case *Symbol:
+ name = v.Name()
+ case *StringNum:
+ name = v.String()
+ default:
+ return fmt.Errorf("delete expects a variable name, got %T", val)
+ }
+ return op.DeleteVariable(name)
})
// Commands that return immediately