Initial upload

This commit is contained in:
2022-08-24 14:28:45 +02:00
parent c67653ddee
commit 57bc7b0289
370 changed files with 18479 additions and 0 deletions

24
go/forth/stack.go Normal file
View File

@@ -0,0 +1,24 @@
package forth
import "fmt"
type Stack struct {
stack []int
ptr int
}
func (s *Stack) Push(k int) {
s.stack = append(s.stack, k)
}
func (s *Stack) Pop() (int, error) {
if len(s.stack) == 0 {
return 0, fmt.Errorf("cannot pop empty stack")
}
el := s.stack[len(s.stack)-1]
s.stack = s.stack[:len(s.stack)-1]
return el, nil
}