// Next returns the next term available from this reader. // Returns error NoMoreTerms if the reader can't find any more terms. func (r *TermReader) Next() (term.Term, error) { var t term.Term var ll *lex.List if r.readTerm(1200, r.ll, &ll, &t) { if term.IsError(t) { return nil, fmt.Errorf("%s", t.String()) } r.ll = ll return term.RenameVariables(t), nil } return nil, NoMoreTerms }
func (cp *headbodyCP) Follow() (Machine, error) { // rename variables so recursive clauses work clause := term.RenameVariables(cp.clause).(term.Callable) // does the machine's current goal unify with our head? head := clause if clause.Arity() == 2 && clause.Name() == ":-" { head = term.Head(clause) } env, err := cp.goal.Unify(cp.machine.Bindings(), head) if err == term.CantUnify { return nil, err } MaybePanic(err) // yup, update the environment and top goal if clause.Arity() == 2 && clause.Name() == ":-" { return cp.machine.SetBindings(env).PushConj(term.Body(clause)), nil } return cp.machine.SetBindings(env), nil // don't need to push "true" }