aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2023-07-29 10:41:57 -0230
committerSam Anthony <sam@samanthony.xyz>2023-07-29 10:41:57 -0230
commit88bf9516752558207bd34c4fec73ce2632c22b2c (patch)
tree814aaa9195138aac5388bd84146b2e3dc00b7463
parent0e1cd2b6a328887c1a630eae0b34366a607bb1b8 (diff)
downloadpfc-88bf9516752558207bd34c4fec73ce2632c22b2c.zip
use Stack push, pop methods
-rw-r--r--calculator.go3
-rw-r--r--ui.go4
2 files changed, 3 insertions, 4 deletions
diff --git a/calculator.go b/calculator.go
index b5dae10..8afc43a 100644
--- a/calculator.go
+++ b/calculator.go
@@ -56,8 +56,7 @@ func (c *Calculator) performOp(op byte) error {
} else if fl, err := strconv.ParseFloat(c.buf, 64); err == nil {
fn(&c.stack[len(c.stack)-1], fl)
} else if len(c.stack) > 1 {
- fn(&c.stack[len(c.stack)-2], c.stack[len(c.stack)-1])
- c.stack = c.stack[:len(c.stack)-1]
+ fn(&c.stack[len(c.stack)-2], *c.stack.pop())
}
c.buf = ""
return nil
diff --git a/ui.go b/ui.go
index 85919c4..9bf9caa 100644
--- a/ui.go
+++ b/ui.go
@@ -58,9 +58,9 @@ func (ui UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if fn := parseFunction(ui.calc.buf); fn != nil {
fn(ui.calc.stack)
} else if con := parseConstant(ui.calc.buf); con != nil {
- ui.calc.stack = append(ui.calc.stack, *con)
+ ui.calc.stack.push(*con)
} else if f, err := strconv.ParseFloat(ui.calc.buf, 64); err == nil {
- ui.calc.stack = append(ui.calc.stack, f)
+ ui.calc.stack.push(f)
}
ui.calc.buf = ""
default: