Advertisement
logicmoo

Untitled

Aug 16th, 2018
543
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 16.36 KB | None | 0 0
  1. // ConsoleApplication2.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5.  
  6. /* prolog.c: a simple Prolog interpreter written in C++,               */
  7. /*           including an example test run as main().                  */
  8. /* Copyright (c) Alan Mycroft, University of Cambridge, 2000.          */
  9. /*
  10.  
  11.         original from https://www.cl.cam.ac.uk/~am21/research/funnel/prolog.c
  12.  
  13.       Dmiles Added :
  14.         cuts
  15.         nonstatic trial
  16.         Atom Table
  17.         Interaction
  18.         Lisp constants  
  19.  
  20. */
  21.  
  22. // #define LISP90 1
  23. #define DEBUGGING 1
  24. #define USE_CUT 1
  25.  
  26. void myBreak() {
  27.   ;;;
  28. }
  29.  
  30.  
  31. int test_program_append(bool interactive);
  32.  
  33. #ifdef LISP90
  34. #include "lisp90.cpp"
  35. #else
  36. #define nonvar char*
  37. #define read_atom(s) s
  38. // #define to_string(s) s
  39. #endif
  40.  
  41. #define C_TEXT( text ) ((char*)std::string( text ).c_str())
  42. #undef C_TEXT
  43. #define C_TEXT( text ) ((char*)text)
  44.  
  45. #define MKATOM(TEXT) SymTable::GetAtom(TEXT)
  46. #define FACT(TEXT) new Clause(TEXT)
  47. #define RULE(HEAD,...) new Clause(HEAD,__VA_ARGS__)
  48.  
  49. /*Psuedovars for source translation */
  50. #define PSUEDOVAR(NAME)  Var* V(NAME) = new Var()
  51. #define V(NAME) VAR_ ## NAME
  52.  
  53.  
  54. /* Create a Callable Compound*/
  55. #define CC(...) new Fun(__VA_ARGS__)
  56. /* Create a List*/
  57. #define LL(...) CC(ATOM_dot,__VA_ARGS__)
  58.  
  59. #ifdef DEBUGGING
  60. //#define DEBUG(mask,CPP) if ((mask & debugflags)!=0) CPP
  61. #define DEBUG(mask,CPP) CPP
  62. #else
  63. #define DEBUG(mask,CPP)
  64. #endif
  65.  
  66. #include <iostream>
  67. using namespace std;
  68. #include <string.h>
  69. #include <string>
  70. #include <map>
  71. #include <unordered_map>
  72. #include <vector>
  73.  
  74. void indent(ostream& str, int n) {
  75.   for (int i = 0; i < n; i++) str << "    ";
  76. }
  77. void indent(int n) {
  78.   indent(cout, n);
  79. }
  80.  
  81. class Prolog; class Term;
  82.  
  83. class Prog1Pred;
  84. #define HashMap std::unordered_map<std::string, Prog1Pred*>
  85.  
  86. class PredTable
  87. {
  88. public:
  89.   std::vector<HashMap> tables;
  90.  
  91.   PredTable()
  92.   {
  93.     tables = std::vector<HashMap>(33);
  94.   }
  95.  
  96.  
  97.   void InsertNameArity(const std::string& N, const int& A, Prog1Pred* Adr)
  98.   {
  99.     HashMap T = tables[A];
  100.     if (T.empty())
  101.     {
  102.       tables[A] = T = HashMap();
  103.     }
  104.     T.emplace(N, Adr);
  105.   }
  106.  
  107.   Prog1Pred* IsInPredTable(const std::string& N, const int& A)
  108.   {
  109.     if (tables[A].empty())
  110.     {
  111.       return nullptr;
  112.     }
  113.     return static_cast<Prog1Pred*>(tables[A][N]);
  114.   }
  115. };
  116.  
  117. class Prog1Pred;
  118.  
  119. class Sym {
  120.  
  121. #ifdef LISP90
  122.   nonvar atomname;
  123. #else
  124.   std::string atomname;
  125. #endif
  126.  
  127. public:
  128.   Sym(const char* s) :
  129. #ifdef LISP90
  130.     atomname(read_atom(s)) {
  131.   }
  132. #else
  133.     atomname(s) {
  134.     // cout << "made '" << atomname << "' from '" << s << "'\n";        
  135.   }
  136. #endif
  137.   virtual ostream& operator<<(ostream& str) {
  138.     print(str); return(str);
  139.   }
  140.   virtual void print(ostream& str) {
  141.     // str <<  "'" ;
  142.     str << atomname;
  143.     // str << "'";
  144.   }
  145.  
  146.   virtual Sym* copyAtom(Prolog* m) {
  147.     return(this);
  148.   }
  149.  
  150.   const char* c_str() {
  151.     return(atomname.c_str());
  152.   }
  153.  
  154.   bool eqatom(Sym* t) {
  155.     return(strcmp(c_str(), t->c_str()) == 0);
  156.   }
  157.  
  158.   // Might store preds here?
  159.   // std::vector<Prog1Pred*> preds = std::vector<Prog1Pred*>(33);
  160.  
  161. };
  162.  
  163. #define AtomHashMap std::unordered_map<std::string,Sym*>
  164. class SymTable
  165. {
  166. public:
  167.   static AtomHashMap symtable;
  168.  
  169.   static Sym* GetAtom(const std::string N)
  170.   {
  171.     Sym* A = symtable[N];
  172.     if (A == NULL) {
  173.       symtable[N] = A = new Sym(N.c_str());
  174.     }
  175.     return A;
  176.   }
  177. };
  178. AtomHashMap SymTable::symtable = AtomHashMap();
  179.  
  180.  
  181. class Fun;
  182. class Term {
  183. public:
  184.   void print() {
  185.     print(cout);
  186.   }
  187.   virtual ostream& operator<<(ostream& str) {
  188.     print(str); return(str);
  189.   }
  190.   virtual void print(ostream& str) = 0;
  191.   virtual bool unifyTerm(Prolog*, Term*) = 0;
  192.   virtual bool unifyStructure(Prolog*, Fun*) = 0;
  193.   virtual Term* copyTerm(bool fresh, Prolog*) = 0;
  194.   virtual void reset(Prolog*) = 0;
  195. };
  196.  
  197.  
  198. Sym* ATOM_nil = MKATOM("[]");
  199. Sym* ATOM_dot = MKATOM(".");
  200.  
  201. class Fun : public Term {
  202.   Sym* fsym; int arity; Term** Arguments;
  203. private:
  204.  
  205. public:
  206.   Fun(const char* f) : fsym(MKATOM(f)), arity(0), Arguments(NULL) {}
  207.   Fun(Sym* f) : fsym(f), arity(0), Arguments(NULL) {}
  208.   Fun(Sym* f, Term* a1) : fsym(f), arity(1), Arguments(new Term*[1]) { Arguments[0] = a1; };
  209.   Fun(Sym* f, Term* a1, Term* a2) : fsym(f), arity(2), Arguments(new Term*[2]) { Arguments[0] = a1, Arguments[1] = a2; };
  210.   Fun(Sym* f, Term* a1, Term* a2, Term* a3) : fsym(f), arity(3), Arguments(new Term*[3]) { Arguments[0] = a1, Arguments[1] = a2, Arguments[2] = a3; };
  211.   Sym* name() { return fsym; }
  212.  
  213.   virtual void print(ostream& str) {
  214.     if (fsym == ATOM_dot) {
  215.       str << "[";
  216.       for (int i = 0; i < arity; ) {
  217.         Arguments[i++]->print(str);
  218.         if (Arguments[i] == NULL)               continue;
  219.         if (i < arity)  str << "|";
  220.       }
  221.       str << "]";
  222.       return;
  223.     }
  224.     fsym->print(str);
  225.     if (arity > 0) {
  226.       str << "(";
  227.       for (int i = 0; i < arity; ) {
  228.         Arguments[i]->print(str);
  229.         if (++i < arity)                str << ",";
  230.       }
  231.       str << ")";
  232.     }
  233.   }
  234.   bool unifyTerm(Prolog* m, Term* t) {
  235.     return(t->unifyStructure(m, this));
  236.   }
  237.   Term* copyTerm(bool fresh, Prolog* m) {
  238.     return(copyStructure(fresh, m));
  239.   }
  240.   Fun* copyStructure(bool fresh, Prolog* m) {
  241.     return(new Fun(fresh, m, this));
  242.   }
  243.   void reset(Prolog* m) {}
  244.  
  245. private:
  246.   Fun(bool fresh, Prolog* m, Fun* p)
  247.     : fsym(p->fsym->copyAtom(m)), arity(p->arity),
  248.     Arguments(p->arity == 0 ? NULL : new Term*[p->arity]) {
  249.     for (int i = 0; i < arity; i++) Arguments[i] = p->Arguments[i]->copyTerm(fresh, m);
  250.   }
  251.   virtual bool unifyStructure(Prolog* m, Fun* t);
  252. };
  253.  
  254. class Var : public Term {
  255. private:
  256.   Term * instance;
  257.   int varno;
  258.   static int timestamp;
  259. public:
  260.   Var() : instance(this), varno(++timestamp) {
  261.   }
  262.   virtual void print(ostream& str) {
  263.     if (instance != this) instance->print(str);
  264.     else str << "_" << varno;
  265.   };
  266.   bool unifyTerm(Prolog* m, Term* t);
  267.   Term* copyTerm(bool fresh, Prolog* m);
  268.   virtual void reset(Prolog* m) {
  269.     instance = this;
  270.   }
  271.   virtual bool unifyStructure(Prolog* m, Fun* t) {
  272.     return(this->unifyTerm(m, t));
  273.   }
  274. };
  275.  
  276. int Var::timestamp = 0;
  277.  
  278. class Prog1Pred;
  279. class TermVarMapping;
  280.  
  281. class Goal {
  282. private:
  283.   Fun * head; Goal* tail;
  284. public:
  285.   Goal(Fun* h) : head(h), tail(NULL) {}
  286.   Goal(Fun* h, Goal* t) : head(h), tail(t) {}
  287.  
  288.   Goal* copyGoal(bool fresh, Prolog* m) {
  289.     return(new Goal(head->copyStructure(fresh, m), tail == NULL ? NULL : tail->copyGoal(fresh, m)));
  290.   }
  291.   Goal* appendGoal(Goal* l) {
  292.     return(new Goal(head, tail == NULL ? NULL : tail->appendGoal(l)));
  293.   }
  294.   virtual void print(ostream& str) { head->print(str); if (tail != NULL) { str << "; "; tail->print(str); } }
  295.   virtual bool unifyGoal_Unused(Prolog* m, Goal* c2);
  296.   int solve(Prolog* m, Prog1Pred* p, bool interactive, int results, int level, TermVarMapping* map);
  297. };
  298.  
  299. class Prolog {
  300. private:
  301.   Var * tcar; Prolog* sofar;
  302.   Prolog(Var* h, Prolog* t) : tcar(h), sofar(t) {
  303.   }
  304.  
  305. public:
  306.   Prolog() : tcar(NULL), sofar(NULL) {
  307.   }
  308.   Prolog* Note() {
  309.     return(sofar);
  310.   }
  311.   Prolog* Push(Var* x) {
  312.     return(sofar = new Prolog(x, sofar));
  313.   }
  314.   void Undo(Prolog* whereto) {
  315.     for (; sofar != whereto; sofar = sofar->sofar)          sofar->tcar->reset(this);
  316.   }
  317. };
  318.  
  319. class Clause {
  320. public:
  321.   Fun * head; Goal* body;
  322.   Clause(Fun* h, Goal* t) : head(h), body(t) {}
  323.   Clause(Fun* h, Fun* t) : head(h), body(new Goal(t)) {}
  324.   Clause(Fun* h) : head(h), body(NULL) {}
  325.   virtual ostream& operator<<(ostream& str) {
  326.     print(str); return(str);
  327.   }
  328.  
  329.   virtual Clause* copyClause(bool fresh, Prolog* m) {
  330.     return(new Clause(head->copyStructure(fresh, m), body == NULL ? NULL : body->copyGoal(fresh, m)));
  331.   }
  332.  
  333.   bool unifyTerm_Unused(Prolog* m, Clause* c2) {
  334.     Prolog* mark = m->Note();
  335.     if (!(head->unifyTerm(m, c2->head) && body->unifyGoal_Unused(m, c2->body))) {
  336.       m->Undo(mark);
  337.       return false;
  338.     }
  339.     return true;
  340.   }
  341.  
  342.   virtual Clause* copyForEdit() {
  343.     auto tv = new Prolog();
  344.     auto tvm = tv->Note();
  345.     Clause* c3 = copyClause(false, tv);
  346.     auto newtvm = tv->Note();
  347.     if (newtvm != tvm) {
  348.       // secretly this shouldnt really happen with copyClause(false, tv);
  349.       tv->Undo(tvm);
  350.     }
  351.     return(c3);
  352.   }
  353.  
  354.   virtual void print(ostream& str) {
  355.     head->print(str);  str << " :- ";
  356.     if (body == NULL) {
  357.       str << "true";
  358.     }
  359.     else {
  360.       body->print(str);
  361.     }
  362.   }
  363.  
  364.   Goal* appendBody(Fun* l) {
  365.     Goal* item = new Goal(l);
  366.     if (body == NULL) {
  367.       body = item;
  368.     }
  369.     else {
  370.       body->appendGoal(item);
  371.     }
  372.     return(item);
  373.   }
  374.  
  375. };
  376.  
  377. class Prog1Pred {
  378. public:
  379.   Clause * pcar; Prog1Pred* pcdr;
  380.   Prog1Pred(Clause* h) : pcar(h), pcdr(NULL) {}
  381.   Prog1Pred(Clause* h, Prog1Pred* t) : pcar(h), pcdr(t) {}
  382.   Prog1Pred(Clause* h, Clause* t) : pcar(h), pcdr(new Prog1Pred(t)) {}
  383.   Prog1Pred(Clause* h, Clause* h2, Clause* t) : pcar(h), pcdr(new Prog1Pred(h2, t)) {}
  384.  
  385.   /* returns the newly appended Prog1Pred*/
  386.   Prog1Pred* appendStatement(Clause* l) {
  387.     if (pcdr != NULL) return(pcdr->appendStatement(l));
  388.     pcdr = new Prog1Pred(l);
  389.     return(pcdr);
  390.   }
  391.  
  392.   /* returns itself*/
  393.   Prog1Pred* prependStatement(Clause* h) {
  394.     pcdr = new Prog1Pred(pcar, pcdr);
  395.     pcar = h;
  396.     return(this);
  397.   }
  398.  
  399. };
  400.  
  401. bool Goal::unifyGoal_Unused(Prolog* m, Goal* c2) {
  402.   Prolog* mark = m->Note();
  403.   if (!(head->unifyTerm(m, c2->head) && tail->unifyGoal_Unused(m, c2->tail))) {
  404.     m->Undo(mark);
  405.     return false;
  406.   }
  407.   return true;
  408. }
  409.  
  410.  
  411. bool Fun::unifyStructure(Prolog* m, Fun* t) {
  412.   Prolog* mark = m->Note();
  413.   if (!(arity == t->arity && fsym->eqatom(t->fsym))) { m->Undo(mark); return(false); }
  414.   for (int i = 0; i < arity; i++) if (!Arguments[i]->unifyTerm(m, t->Arguments[i])) { m->Undo(mark); return(false); }
  415.   return(true);
  416. };
  417.  
  418. bool Var::unifyTerm(Prolog* m, Term* t) {
  419.   if (instance != this) return(instance->unifyTerm(m, t)); m->Push(this); instance = t; return(true);
  420. }
  421. Term* Var::copyTerm(bool fresh, Prolog* m) {
  422.   if (instance == this) {
  423.     if (!fresh) return this;
  424.     m->Push(this);
  425.     instance = new Var();
  426.     return(instance);
  427.   }
  428.   return(instance);
  429. }
  430.  
  431.  
  432. class TermVarMapping {
  433. private:
  434.   Var * * varvar;
  435.   const char** vartext;
  436.   int size;
  437. public:
  438.   TermVarMapping(Var* vv[], const char* vt[], int vs)
  439.     :varvar(vv), vartext(vt), size(vs) {
  440.   }
  441.   void showanswer(ostream& str) {
  442.     if (size == 0)          str << "yes\n";
  443.     else {
  444.       for (int i = 0; i < size; i++) {
  445.         str << vartext[i] << " = "; varvar[i]->print(str); str << "\n";
  446.       }
  447.     }
  448.   }
  449. };
  450.  
  451. Fun* NIL = CC(ATOM_nil);
  452. Sym* ATOM_cut = MKATOM("!");
  453. Fun* CUT = CC(ATOM_cut);
  454.  
  455. int Goal::solve(Prolog* m, Prog1Pred* p, bool interactive, int results, int level, TermVarMapping* map) {
  456.   std::string line = "";
  457.   ostream& str = cout;
  458.   bool cutted = false;
  459.   bool success = false;
  460.   DEBUG(SOLVE, { indent(level); str << "solve@" << level << ": ";
  461.        this->print(str); str << "\n"; });
  462.  
  463.   for (Prog1Pred* q = p; q != NULL; q = q->pcdr) {
  464.     Prolog* t = m->Note();
  465.     Clause* c = q->pcar->copyClause(true, m);
  466.     int nextLevel = 1;
  467.     m->Undo(t);
  468.     DEBUG(SOLVE, { indent(level); str << "  try:"; c->print(str); str << "\n"; });
  469.     if (head->unifyTerm(m, c->head)) {
  470.       Goal* gdash = c->body == NULL ?  tail :  (nextLevel = 0,
  471.         c->body->appendGoal(tail));
  472.       if (gdash != NULL) {
  473.         if (gdash->head->name() == ATOM_cut) {
  474.           gdash = NULL;
  475.           cutted = true;
  476.         }
  477.       }
  478.       if (gdash == NULL) {
  479.         success = true;
  480.         results++;
  481.         map->showanswer(str);        
  482.         if (interactive) {
  483.           std::cout << "(ENTER) - next solution \t (stop+ENTER) - stop finding solution" << std::endl;
  484.           std::getline(std::cin, line);
  485.         }
  486.       }
  487.       else {
  488.         int waz = gdash->solve(m, p,interactive,results, level + nextLevel, map);
  489.         if (waz == 0) {
  490.           DEBUG(SOLVE, { indent(level); str << "  parent fails.\n"; });
  491.         }        
  492.       }
  493.     }
  494.     else {
  495.       DEBUG(SOLVE, { indent(level); str << "  nomatch.\n"; });
  496.       if (interactive) {
  497.         if(results!=0) {
  498.         std::cout << "(ENTER) no more solutions" << std::endl;
  499.          std::getline(std::cin, line);
  500.         }
  501.       }
  502.     }
  503.     if (cutted) break;
  504.     m->Undo(t);
  505.     if (line == "stop") break;
  506.   }
  507.   return results;
  508. }
  509.  
  510.  
  511. /* A sample test program: append*/
  512. int test_program_append_prev(bool interactive) {
  513.   ostream& str = cout;
  514.  
  515.   Sym* at_app = MKATOM("append_3");
  516.   Sym* at_cons = MKATOM(".");
  517.   Fun* f_nil = new Fun(MKATOM("[]"));
  518.   Fun* f_1 = new Fun(MKATOM("1"));
  519.   Fun* f_2 = new Fun(MKATOM("2"));
  520.   Fun* f_3 = new Fun(MKATOM("3"));
  521.  
  522.   Term* v_x = new Var();
  523.   Fun* lhs1 = new Fun(at_app, f_nil, v_x, v_x);
  524.   Clause* c1 = new Clause(lhs1);
  525.  
  526.   Term* v_l = new Var();
  527.   Term* v_m = new Var();
  528.   Term* v_n = new Var();
  529.   Fun* rhs2 = new Fun(at_app, v_l, v_m, v_n);
  530.   Fun* lhs2 = new Fun(at_app, new Fun(at_cons, v_x, v_l),
  531.     v_m,
  532.     new Fun(at_cons, v_x, v_n));
  533.   Clause* c2 = new Clause(lhs2, new Goal(rhs2, NULL));
  534.  
  535.   Var* v_i = new Var();
  536.   Var* v_j = new Var();
  537.   Fun* rhs3 = new Fun(at_app, v_i, v_j,
  538.     new Fun(at_cons, f_1,
  539.       new Fun(at_cons, f_2,
  540.         new Fun(at_cons, f_3, f_nil))));
  541.  
  542.   Goal* g1 = new Goal(rhs3, NULL);
  543.  
  544.   Prog1Pred* test_p = new Prog1Pred(c1, new Prog1Pred(c2));
  545.   Prog1Pred* test_p2 = new Prog1Pred(c2, new Prog1Pred(c1));
  546.  
  547.   Var* varvar[] = { v_i, v_j };
  548.   const char* varname[] = { "I", "J" };
  549.   TermVarMapping* var_name_map = new TermVarMapping(varvar, varname, 2);
  550.  
  551.   Prolog* m = new Prolog();
  552.   str << "=D=======Append with normal clause order:\n";
  553.   g1->solve(m, test_p,true, 0,0, var_name_map);
  554.   str << "\n=E=======Append with reversed normal clause order:\n";
  555.   g1->solve(m, test_p2,true, 0,0, var_name_map);
  556.   return(0);
  557. }
  558.  
  559. #ifndef LISP90
  560. int main(int argc, char* argv[]) {
  561.   test_program_append( true);
  562.   test_program_append_prev( true);
  563. }
  564. #endif
  565.  
  566.  
  567. /* A sample test program: append*/
  568.  
  569. int test_program_append(bool interactive) {
  570.   ostream& str = cout;
  571.   /*Psuedovars for source translation */
  572.   PSUEDOVAR(X);
  573.   PSUEDOVAR(L);
  574.   PSUEDOVAR(M);
  575.   PSUEDOVAR(N);
  576.   PSUEDOVAR(I);
  577.   PSUEDOVAR(J);
  578.  
  579.  
  580.   Sym* APPEND3 = MKATOM("append_3");
  581.  
  582.  
  583.  
  584.  
  585.   /* append_3([],X,X). */
  586.   Clause* c1 = FACT(CC(APPEND3, NIL, VAR_X, VAR_X));
  587.   /*  append([X|LL],M,[X|N]):- append(LL,M,N). */
  588.   Clause* c2 = RULE(CC(APPEND3, LL(VAR_X, VAR_L), VAR_M, LL(VAR_X, VAR_N)), CC(APPEND3, VAR_L, VAR_M, VAR_N));
  589.  
  590.  
  591.   /*
  592.            Test normally:
  593.  
  594.                   append_3([],X,X).
  595.                   append([X|LL],M,[X|N]):- append(LL,M,N).
  596.   */
  597.   Prog1Pred* test_program_normally = new Prog1Pred(c1, c2);
  598.  
  599.  
  600.   /*
  601.           Test reversed:
  602.  
  603.                   append([X|LL],M,[X|N]):- append(LL,M,N).
  604.                   append_3([],X,X).
  605.   */
  606.   Prog1Pred* test_program_reversed = new Prog1Pred(c2, c1);
  607.  
  608.  
  609.   /*
  610.            Test Cat:
  611.  
  612.                   append_3([],X,X):- !.
  613.                   append([X|LL],M,[X|N]):- append(LL,M,N).
  614.   */
  615.  
  616.   // #undef USE_CUT
  617.  
  618.  
  619.   cout << "\n"; cout << "\n"; cout << "\n"; cout << "\n";
  620.   c1->print(cout);
  621.   cout << "\n"; cout << "\n"; cout << "\n"; cout << "\n";
  622.  
  623. #ifdef USE_CUT
  624.   Clause* c3 = c1->copyForEdit();
  625.  
  626.   c3->appendBody(CUT);
  627.  
  628.   Prog1Pred* test_program_cut = new Prog1Pred(c3, c2);
  629.  
  630.   cout << "\n"; cout << "\n"; cout << "\n"; cout << "\n";
  631.   c1->print(cout);
  632.   cout << "\n"; cout << "\n"; cout << "\n"; cout << "\n";
  633.  
  634.   cout << "\n"; cout << "\n"; cout << "\n"; cout << "\n";
  635.   c3->print(cout);
  636.   cout << "\n"; cout << "\n"; cout << "\n"; cout << "\n";
  637.  
  638. #endif
  639.  
  640.  
  641.   Var* varvar[] = { VAR_I,VAR_J };
  642.   const char* varname[] = { "I", "J" };
  643.   TermVarMapping* var_name_map = new TermVarMapping(varvar, varname, 2);
  644.  
  645.   /*
  646.            ?- append_3(I,J,[1,2,3]).
  647.   */
  648.   Goal* g1 = new Goal(CC(APPEND3, VAR_I, VAR_J, LL(CC("1"), LL(CC("2"), LL(CC("3"), NIL)))));
  649.  
  650.   Prolog* m = new Prolog();
  651.  
  652.   str << "=A=======Append with normal clause order:\n";
  653.   g1->solve(m, test_program_normally, true, 0,0, var_name_map);
  654.  
  655.   str << "\n=B========Append with reversed normal clause order:\n";
  656.   g1->solve(m, test_program_reversed, true, 0,0, var_name_map);
  657.  
  658. #ifdef USE_CUT
  659.   str << "\n=C=======Append with a cut:\n";
  660.   g1->solve(m, test_program_cut, true, 0, 0,var_name_map);
  661. #endif
  662.   return(0);
  663. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement