make IF/ELSE/THEN work!

This commit is contained in:
2021-02-20 15:52:27 -05:00
parent 2a1a6fc0d2
commit 6efa404712
7 changed files with 156 additions and 82 deletions

View File

@@ -2,25 +2,24 @@ package main
import "fmt"
// ErrNoWordFound flags if the requested word is not in the dictionary
var ErrNoWordFound = fmt.Errorf("no word found")
// Dictionary is a simple map of names to words
type Dictionary map[string]Word
// A Word defines a subroutine
type Word struct {
Name string
Impl func() error
Source []string
Immediate bool
Name string
Impl func() error
Source []string
Immediate bool
BranchCheck bool
}
// AddWord inserts a new word into the dictonary, optionally overwriting the existing word
func (d Dictionary) AddWord(name string, impl func() error, source []string, immediate bool) {
d[name] = Word{
Name: name,
Impl: impl,
Source: source,
Immediate: immediate,
}
// AddWord inserts a new word into the dictonary, overwriting any existing word by that name
func (d Dictionary) AddWord(name string, w Word) {
d[name] = w
}
// GetWord returns a word from the dictionary or an error if it's undefined
@@ -29,7 +28,7 @@ func (d Dictionary) GetWord(name string) (Word, error) {
if !ok {
return Word{
Name: name,
}, fmt.Errorf("no word found")
}, ErrNoWordFound
}
return w, nil
}