Instead of doing:
var adapters[]LogicAdapter
adapter1 := &ExampleAdapter{0.9}
adapter2 := &ExampleAdapter{0.8}
adapters = append(adapters, adapter1, adapter2)
bot := ChatterBot{"Charlie", MultiLogicAdapter{adapters}}
I tried:
bot := ChatterBot{
"Charlie",
MultiLogicAdapter{
[]LogicAdapter{
&ExampleAdapter{0.9},
&ExampleAdapter{0.8}
}
}
}
But why this won't work? I cannot see any problems with the syntax, it's like I were creating a new slice and putting it into there. Here are the errors:
./main.go:16: syntax error: unexpected semicolon or newline, expecting comma or }
./main.go:21: syntax error: unexpected semicolon or newline, expecting comma or }
./main.go:22: syntax error: unexpected semicolon or newline, expecting comma or }
You just need a comma at the end of &ExampleAdapter{0.8}
and after the closing braces that end the other elements.. Go syntax is pretty strict. If you don't have the closing brace on the same line, you need to end the line with a comma, even if it's the last element. That's what the error message is saying. Your code should look like this:
bot := ChatterBot{
"Charlie",
MultiLogicAdapter{
[]LogicAdapter{
&ExampleAdapter{0.9},
&ExampleAdapter{0.8},
},
},
}