-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
40 lines (31 loc) · 924 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"fmt"
"github.com/zenmodel/zenmodel"
)
func main() {
bp := zenmodel.NewBrainPrint()
bp.AddNeuron("nested", nestedBrain)
_, _ = bp.AddEntryLink("nested")
brain := bp.Build()
_ = brain.Entry()
brain.Wait()
fmt.Printf("nested result: %s\n", brain.GetMemory("nested_result").(string))
}
func nestedBrain(outerBrain zenmodel.BrainRuntime) error {
bp := zenmodel.NewBrainPrint()
bp.AddNeuron("run", func(curBrain zenmodel.BrainRuntime) error {
_ = curBrain.SetMemory("result", fmt.Sprintf("run here neuron: %s.%s", outerBrain.GetCurrentNeuronID(), curBrain.GetCurrentNeuronID()))
return nil
})
_, _ = bp.AddEntryLink("run")
brain := bp.Build()
// run nested brain
_ = brain.Entry()
brain.Wait()
// get nested brain result
result := brain.GetMemory("result").(string)
// pass nested brain result to outer brain
_ = outerBrain.SetMemory("nested_result", result)
return nil
}