prosper/words.go

35 lines
784 B
Go

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(string) error
Source []string
Immediate bool
BranchCheck bool
}
// 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
func (d Dictionary) GetWord(name string) (Word, error) {
w, ok := d[name]
if !ok {
return Word{
Name: name,
}, ErrNoWordFound
}
return w, nil
}