make IF/ELSE/THEN work!
This commit is contained in:
25
words.go
25
words.go
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user