diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2023-10-01 20:02:22 -0400 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2023-10-01 20:02:22 -0400 |
| commit | 4f9e220638ea62443db25d252c4e12ede2c7f9c5 (patch) | |
| tree | ed40edf989f2907e58e3d5fd0fd0a85cde919386 /stack.go | |
| parent | 6e3073f5e835b19b39d0853dece386067218b1ce (diff) | |
| download | pfc-4f9e220638ea62443db25d252c4e12ede2c7f9c5.zip | |
error handling and tidying
Diffstat (limited to 'stack.go')
| -rw-r--r-- | stack.go | 12 |
1 files changed, 9 insertions, 3 deletions
@@ -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" } |