public ProveResult ExecuteSharp(Term thisTerm, PartListImpl goalList, PEnv environment, PDB db, int level, reportDelegate reportFunction) { Term collect0 = value((Part)thisTerm.ArgList[1], environment).AsTerm(); string methodName = collect0.fname; var partObj = value((Part)thisTerm.ArgList[0], environment); object result; TextWriter warns = new StringWriter(); try { if (partObj.IsObject) { if (!CanInvokeObject(partObj.Functor0, methodName, collect0.ArgList, out result, warns)) { Warn(warns); return(new ProveResult() { Failed = true }); } } else { if (!CanInvokeObjectByName(partObj.Text, methodName, collect0.ArgList, true, out result, warns)) { Warn(warns); return(new ProveResult() { Failed = true }); } } } catch (Exception e2) { Warn(warns); throw e2; return(new ProveResult() { Failed = true }); } //print("Debug: unifying "); into.print(); print(" with "); answers.print(); print("\n"); var env2 = unify(thisTerm.ArgList[2], ObjectToPart(result), environment); if (env2 == null) { //print("Debug: bagof cannot unify anslist with "); into.print(); print(", failing\n"); return(null); } // Just prove the rest of the goallist, recursively. return(prove(goalList, env2, db, level + 1, reportFunction)); }
private void SetText(Control control, string text) { if (control.InvokeRequired) { reportDelegate d = new reportDelegate(SetText); control.Invoke(d, new object[] { control, text }); } else { control.Text += text; } }
public ProveResult TripleQuery(Term thisTerm, PartListImpl goalList, PEnv environment, PDB db, int level, reportDelegate reportFunction) { // bagof(Term, ConditionTerm, ReturnList) // PartList goalList = (PartList)goalIn; Part collect0 = value((Part)thisTerm.ArgList[0], environment); Part subgoal = value((Part)thisTerm.ArgList[1], environment); Part into = value((Part)thisTerm.ArgList[2], environment); Part collect = renameVariables(collect0, level, thisTerm); //var newGoal = new Term(subgoal.name, renameVariables(subgoal.ArgList, level, thisTerm)); Term newGoal = new Term(subgoal.fname, false, (PartListImpl)renameVariables(((PartListImpl)subgoal), level, thisTerm)); newGoal.parent = thisTerm; //var newGoals = []; //newGoals[0] = newGoal; PartListImpl newGoals = new PartListImpl(); newGoals.AddPart(newGoal); // Prove this subgoal, collecting up the environments... PartListImpl anslist = new PartListImpl(); anslist.renumber = -1; var ret = prove(newGoals, environment, db, level + 1, BagOfCollectFunction(collect, anslist)); // Turn anslist into a proper list and unify with 'into' // optional here: nil anslist -> fail? Part answers = Atom.FromSource(FUNCTOR_NIL); /* * print("Debug: anslist = ["); * for (var j = 0; j < anslist.length; j++) { * anslist[j].print(); * print(", "); * } * print("]\n"); */ for (int i = anslist.Arity; i > 0; i--) { answers = MakeList(anslist.ArgList[i - 1], answers); } //print("Debug: unifying "); into.print(); print(" with "); answers.print(); print("\n"); var env2 = unify(into, answers, environment); if (env2 == null) { //print("Debug: bagof cannot unify anslist with "); into.print(); print(", failing\n"); return(null); } // Just prove the rest of the goallist, recursively. return(prove(goalList, env2, db, level + 1, reportFunction)); }