initial commit; we have evaluation!
This commit is contained in:
33
words.go
Normal file
33
words.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
// AddWord inserts a new word into the dictonary, optionally overwriting the existing word
|
||||
func (d Dictionary) AddWord(name string, impl func() error, source string) {
|
||||
d[name] = Word{
|
||||
Name: name,
|
||||
Impl: impl,
|
||||
Source: source,
|
||||
}
|
||||
}
|
||||
|
||||
// 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,
|
||||
}, fmt.Errorf("no word found")
|
||||
}
|
||||
return w, nil
|
||||
}
|
Reference in New Issue
Block a user