// Recursively resolve pointers to other factoids func recurse(fact *factoids.Factoid, keys map[string]bool) { val := fact.Value key, start, end := util.FactPointer(val) if key == "" { return } if _, ok := keys[key]; ok || len(keys) > 20 { fact.Value = val[:start] + "[circular reference]" + val[end:] return } keys[key] = true if f2 := fc.GetPseudoRand(key); f2 != nil { fact.Value = val[:start] + f2.Value + val[end:] if start == 0 && fact.Type != f2.Type { // Propagate change of factoid type when the pointer // is at the beginning of the string. fact.Type = f2.Type } recurse(fact, keys) return } // if we get here, we found a pointer key but no matching factoid // so recurse on the stuff after that key *only* to avoid loops. fact.Value = val[end:] recurse(fact, keys) fact.Value = val[:end] + fact.Value }