<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/subex
diff options
context:
space:
mode:
Diffstat (limited to 'subex')
-rw-r--r--subex/arithmetic.go10
-rw-r--r--subex/main.go13
2 files changed, 14 insertions, 9 deletions
diff --git a/subex/arithmetic.go b/subex/arithmetic.go
index 52f576d..a7dc73a 100644
--- a/subex/arithmetic.go
+++ b/subex/arithmetic.go
@@ -10,7 +10,7 @@ func sumValues(atoms []walk.Atom) ([]walk.Atom, error) {
allBools := true
var sum float64 = 0
var any bool = false
- values, err := walk.MemoryCompound(atoms)
+ values, err := walk.Compound(atoms)
if err != nil {
return nil, err
}
@@ -50,7 +50,7 @@ func multiplyValues(atoms []walk.Atom) ([]walk.Atom, error) {
allBools := true
var product float64 = 1
var all bool = false
- values, err := walk.MemoryCompound(atoms)
+ values, err := walk.Compound(atoms)
if err != nil {
return nil, err
}
@@ -89,7 +89,7 @@ func multiplyValues(atoms []walk.Atom) ([]walk.Atom, error) {
// Does tries to cast all to numbers and negates them
func negateValues(atoms []walk.Atom) ([]walk.Atom, error) {
var negatedNumbers []walk.Atom
- values, err := walk.MemoryCompound(atoms)
+ values, err := walk.Compound(atoms)
if err != nil {
return nil, err
}
@@ -123,7 +123,7 @@ func negateValues(atoms []walk.Atom) ([]walk.Atom, error) {
// Else errors
func reciprocalValues(atoms []walk.Atom) ([]walk.Atom, error) {
var reciprocals []walk.Atom
- values, err := walk.MemoryCompound(atoms)
+ values, err := walk.Compound(atoms)
if err != nil {
return nil, err
}
@@ -156,7 +156,7 @@ func reciprocalValues(atoms []walk.Atom) ([]walk.Atom, error) {
// If all are castable to booleans, NOTs all and returns them
// Else errors
func notValues(atoms []walk.Atom) (notted []walk.Atom, err error) {
- values, err := walk.MemoryCompound(atoms)
+ values, err := walk.Compound(atoms)
if err != nil {
return nil, err
}
diff --git a/subex/main.go b/subex/main.go
index 9824f10..bb688e9 100644
--- a/subex/main.go
+++ b/subex/main.go
@@ -103,13 +103,13 @@ func pruneStates(states []SubexBranch) (newStates []SubexBranch) {
}
// Run the subex transducer
-func RunTransducer(transducer SubexState, input <-chan walk.Atom) (output []walk.Atom, err bool) {
+func RunTransducer(transducer SubexState, input []walk.Atom) (output []walk.Atom, err bool) {
states := []SubexBranch{{
state: transducer,
outputStack: OutputStackNil{}.push(nil),
store: make(Store),
}}
- for piece := range input {
+ for _, piece := range input {
var newStates []SubexBranch
for _, state := range states {
newStates = append(newStates, state.eat(piece)...)
@@ -149,7 +149,12 @@ func Main() {
close(out)
}(jsonStream, tokenStream)
- atoms := walk.Atomise(tokenStream)
+ var tokens []walk.WalkValue
+ for token := range tokenStream {
+ tokens = append(tokens, token)
+ }
+
+ atoms := walk.Atomise(tokens)
output, err := RunTransducer(transducer, atoms)
if err {
@@ -157,7 +162,7 @@ func Main() {
return
}
- valueOut, error := walk.MemoryCompound(output)
+ valueOut, error := walk.Compound(output)
if error != nil {
fmt.Println(error.Error())
return