Esempio n. 1
0
func (x *choose) Cognize(eye *plumb.Eye, dvalve string, dvalue interface{}) {
	x.Lock()
	defer x.Unlock()
	switch dvalve {
	case "From":
		x.from = dvalue.(Image)
	case "When":
		x.when = dvalue
	case "_":
	default:
		panic("eh")
	}
	j := rand.Intn(x.from.Len())
	for i, key := range x.from.Names() {
		if i != j {
			continue
		}
		eye.Show(
			"_",
			Image{
				"When":   x.when,
				"Choice": x.from[key],
			},
		)
	}
}
Esempio n. 2
0
func (x *join) Cognize(eye *plumb.Eye, dvalve string, dvalue interface{}) {
	x.Lock()
	defer x.Unlock()
	switch dvalve {
	case "Head":
		head := dvalue.(string)
		x.head = &head
	case "Tail":
		tail := dvalue.(string)
		x.tail = &tail
	default:
		return
	}
	if x.head == nil || x.tail == nil {
		return
	}
	eye.Show("_", path.Join(*x.head, *x.tail))
}
Esempio n. 3
0
func (x *strobe) Cognize(eye *plumb.Eye, dvalve string, dvalue interface{}) {
	switch dvalve {
	case "Charge":
		select {
		case y := <-x.when: // if a when is already waiting, couple it with the charge and send a strobe pair
			eye.Show("Strobe", New().Grow("When", y).Grow("Charge", dvalue))
		default: // otherwise remember the charge
			x.charge <- dvalue
		}
	case "When":
		select {
		case y := <-x.charge: // if a charge is already waiting, couple it with the when and send a strobe pair
			eye.Show("Strobe", New().Grow("When", dvalue).Grow("Charge", y))
		default: // otherwise remember the when
			x.when <- dvalue
		}
	}
}
Esempio n. 4
0
func (h *memory) loop(eye *plumb.Eye) {
	var root = &space{
		Space: make(be.Space),
	}
	focus, recall := &attention{root: root}, &attention{root: root}
	var lesson *eu.Circuit
	for {
		select {
		case lesson = <-h.learn:
		case walk := <-h.focus:
			focus.Point(walk...)
			if lesson == nil {
				break
			}
			eye.Show("Use", focus.Remember(lesson))
		case walk := <-h.recall:
			recall.Point(walk...)
			eye.Show("Use", recall.Recall())
		}
	}
}
Esempio n. 5
0
func (x *remember) Cognize(eye *plumb.Eye, dvalve string, dvalue interface{}) {
	x.Lock()
	defer x.Unlock()
	switch dvalve {
	case "From":
		x.from = dvalue.(Image)
	case "What":
		x.what = dvalue.(Image)
	case "When":
		x.when = dvalue
	case "_":
	default:
		panic("eh")
	}
	eye.Show(
		"_",
		Image{
			"Memory": emphasize(x.from, x.what),
			"When":   x.when,
		},
	)
}
Esempio n. 6
0
func (x *focus) Cognize(eye *plumb.Eye, dvalve string, dvalue interface{}) {
	x.Lock()
	defer x.Unlock()
	switch dvalve {
	case "From":
		x.from = dvalue.(Image)
	case "On":
		x.on = dvalue.(string)
	case "When":
		x.when = dvalue
	case "_":
	default:
		panic("eh")
	}
	eye.Show(
		"_",
		Image{
			"Focus": x.from.Copy().Cut(x.on),
			"When":  x.when,
		},
	)
}
Esempio n. 7
0
func (x *association) Cognize(eye *plumb.Eye, dvalve string, dvalue interface{}) {
	x.Lock()
	defer x.Unlock()
	switch dvalve {
	case "Name":
		x.name = dvalue.(string)
	case "With":
		x.with = dvalue
	case "When":
		x.when = dvalue
	case "_":
	default:
		panic("eh")
	}
	eye.Show(
		"_",
		Image{
			x.name: x.with,
			"When": x.when,
		},
	)
}
Esempio n. 8
0
func (x *sum) Cognize(eye *plumb.Eye, dvalve string, dvalue interface{}) {
	x.save(dvalve, plumb.AsInt(dvalue))
	var wg sync.WaitGroup
	defer wg.Wait()
	wg.Add(2)
	switch dvalve {
	case "X":
		go func() { // Cognize
			defer func() {
				recover()
			}()
			defer wg.Done()
			eye.Show("Y", x.u("Sum")-x.u("X"))
		}()
		go func() {
			defer func() {
				recover()
			}()
			defer wg.Done()
			eye.Show("Sum", x.u("Y")+x.u("X"))
		}()
	case "Y":
		go func() {
			defer func() {
				recover()
			}()
			defer wg.Done()
			eye.Show("X", x.u("Sum")-x.u("Y"))
		}()
		go func() {
			defer func() {
				recover()
			}()
			defer wg.Done()
			eye.Show("Sum", x.u("Y")+x.u("X"))
		}()
	case "Sum":
		go func() {
			defer func() {
				recover()
			}()
			defer wg.Done()
			eye.Show("X", x.u("Sum")-x.u("Y"))
		}()
		go func() {
			defer func() {
				recover()
			}()
			defer wg.Done()
			eye.Show("Y", x.u("Sum")-x.u("X"))
		}()
	}
}
Esempio n. 9
0
func CognizeExploreOnStrobe(eye *plumb.Eye, dvalve string, dvalue interface{}) {
	if dvalve != "Strobe" {
		return
	}
	strobe := dvalue.(Circuit)
	charge := strobe.CircuitAt("Charge")
	//
	var start = view{
		Index:   0,
		Circuit: charge.CircuitAt("Circuit"),
		Image:   charge.StringAt("Image"),
		Valve:   charge.StringAt("Valve"),
	}
	var v = start
	var memory list.List
	for {
		// Current view
		eye.Show("Sequence", v.SequenceTerm(strobe.At("When"))) // yield current view

		// transition
		entering := v.Circuit.At(v.Image) // address of next image
		switch t := entering.(type) {
		case Address:
			//
			if memory.Len() > 100 {
				log.Fatalf("memory overload")
				// memory.Remove(memory.Front())
			}
			memory.PushFront(v) // remember
			//
			_, lookup := faculty.Root.LookupAddress(t.String())
			v.Circuit = lookup.(Circuit) // transition to next circuit
			toImg, toValve := v.Circuit.Follow(t.Name(), v.Valve)
			v.Image, v.Valve = toImg.(string), toValve.(string)

		case Super:
			e := memory.Front() // backtrack
			if e == nil {
				log.Fatalf("insufficient memory")
			}
			u := e.Value.(view)
			memory.Remove(e)
			//
			v.Circuit = u.Circuit
			// log.Printf("Following %s:%s in %s", u.Image, v.Valve, v.Circuit)
			toImg, toValve := v.Circuit.Follow(u.Image, v.Valve)
			v.Image, v.Valve = toImg.(string), toValve.(string)

		default:
			panic("unknown image meaning")
		}
		v.Index++
		//
		if v.Same(start) {
			x := v.SequenceTerm(strobe.At("When"))
			x.Grow("Charge", "Loop")
			eye.Show("Sequence", x)
			break
		}
	}
}
Esempio n. 10
0
func (d dir) Cognize(eye *plumb.Eye, dvalve string, dvalue interface{}) {
	if dvalve != "Path" {
		return
	}
	eye.Show("_", string(d))
}