Skip to content

Commit

Permalink
Replace whitespace in word names with underscores
Browse files Browse the repository at this point in the history
  • Loading branch information
brendantang committed Aug 15, 2021
1 parent 312d392 commit 77f9a7e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion data/dictionary.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package data

import (
"fmt"
"strings"
)

// A Dictionary binds words to data. When a word is evaluated, it is substituted
Expand Down Expand Up @@ -33,8 +34,10 @@ func (dict *Dictionary) Get(word string) (d Value, ok bool) {
return
}

// Set saves the definition of a word.
// Set saves the definition of a word. If the word name contains any white space, it
// is replaced with a single underscore.
func (dict *Dictionary) Set(word string, val Value) {
word = strings.Join(strings.Fields(word), "_")
dict.Bindings[word] = val
}

Expand Down

0 comments on commit 77f9a7e

Please sign in to comment.