aboutsummaryrefslogtreecommitdiffstats
path: root/stack.go
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2023-10-01 20:02:22 -0400
committerSam Anthony <sam@samanthony.xyz>2023-10-01 20:02:22 -0400
commit4f9e220638ea62443db25d252c4e12ede2c7f9c5 (patch)
treeed40edf989f2907e58e3d5fd0fd0a85cde919386 /stack.go
parent6e3073f5e835b19b39d0853dece386067218b1ce (diff)
downloadpfc-4f9e220638ea62443db25d252c4e12ede2c7f9c5.zip
error handling and tidying
Diffstat (limited to 'stack.go')
-rw-r--r--stack.go12
1 files changed, 9 insertions, 3 deletions
diff --git a/stack.go b/stack.go
index 182d418..1a52e94 100644
--- a/stack.go
+++ b/stack.go
@@ -6,11 +6,17 @@ func (s *Stack) push(v float64) {
*s = append(*s, v)
}
-func (s *Stack) pop() *float64 {
+func (s *Stack) pop() (float64, error) {
if len(*s) > 0 {
v := (*s)[len(*s)-1]
*s = (*s)[:len(*s)-1]
- return &v
+ return v, nil
}
- return nil
+ return 0, EmptyStackErr{}
+}
+
+type EmptyStackErr struct{}
+
+func (e EmptyStackErr) Error() string {
+ return "empty stack"
}