diff options
| author | Paul Buetow <paul@buetow.org> | 2026-05-24 14:08:41 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-05-24 14:08:41 +0300 |
| commit | f02d0996bcaee49a4226ba678788e7550b06be29 (patch) | |
| tree | f9c8eecdb36b95d4e28fc00c7aa1d913ebcd2387 /internal/rpn/operations_variables.go | |
| parent | f3a0760739049a42be7b446eab1d4d085ebe2702 (diff) | |
refactor(rpn): extract 'd' operator into Delete method (pj)
Move the inline logic for the 'd' (delete variable) operator into a
proper Operations.Delete method, following the same registration pattern
as all other operators. Adds Delete to the StackOperator interface.
Diffstat (limited to 'internal/rpn/operations_variables.go')
| -rw-r--r-- | internal/rpn/operations_variables.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/internal/rpn/operations_variables.go b/internal/rpn/operations_variables.go index 49cab57..56bf9cd 100644 --- a/internal/rpn/operations_variables.go +++ b/internal/rpn/operations_variables.go @@ -65,6 +65,26 @@ func (o *Operations) DeleteVariable(name string) error { return nil } +// Delete pops a variable name from the stack and deletes that variable. +// Usage: `name d` +func (o *Operations) Delete(stack *Stack) error { + val, err := popStack(stack, "d") + if err != nil { + return err + } + + 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 o.DeleteVariable(name) +} + // ListVariables lists all variables. // Usage: `vars` func (o *Operations) ListVariables() (string, error) { |
