SWI-prolog to C# assert not working -


i'm working on solution using sbssw.swiplcs dll integration between c# application , prolog .pl source file, i'm facing problem assert(atom) command.

my prolog file set of airports , flights between airports, during running time assert new airports , flights this:

        internal void alta(flight new)     {         try         {             plengine.initialize(new string[] { "" });             //plengine.initialize(param);              plquery.plcall("consult(vuelos)");              //comando             //flight(v01,bra,ams,1000)             plquery q = new plquery("assert(fligth(" + new.id + "," + new.airportfrom.id + "," + new.airportto.id + "," + new.price + "))");         }         catch (plexception e)         {             console.writeline(e.messagepl);             console.writeline(e.message);         }                 {             plengine.plcleanup();         }     } 

this runs fine, , don't error message nor exceptions (i used one, because flight/4 , airport/2 statements static, changed both dynamic @ beggining of file , no errors thrown).

my problem when try consult involving new asserts got @ runtime.

internal list<string> directflight(airport from, airport to)     {         list<string> list = new list<string>();          try         {             plengine.initialize(new string[] { "" });             //plengine.initialize(param);              plquery.plcall("consult(vuelos)");              //comando             //una_escala(w,from,to)             using (plquery q = new plquery("directf(w," + from.id + "," + to.id + ")"))             {                 foreach (plqueryvariables v in q.solutionvariables)                 {                     list.add(v["w"].tostring());                 }             }         }         catch (plexception e)         {             console.writeline(e.messagepl);             console.writeline(e.message);         }                 {             plengine.plcleanup();         }          return list;     } 

my list<string> list variable should return list of flight id's go from to, , works pre-loaded flights (the ones on vuelos.pl call on plquery.plcall("consult(vuelos)");), doesn't take account of new flights created @ runtime , can't figure out why.

my error consisted on 2 malpractices. first, cleaned plengine everytime executed query

            {         plengine.plcleanup();     } 

what did in order fix this, initialize plengine 1 time @ class constructor class prolog, way can use same plengine methods. i've looked around , seemingly solution use ? tell('file.pl'), append(listing(atom)), told. save file @ runtime, i'm not aware if can corrupt previous data, chose plengine workaround. doesn't save volatile data, works fine 1 prolog session. still created method clean engine, call when terminate program.

the other issue found, tried execute assert parameters this:

plquery q = new plquery("assert(fligth(" + new.id + "," + new.airportfrom.id + "," + new.airportto.id + "," + new.price + "))"); 

when should have done:

plquery.plcall("assert(fligth(" + new.id + "," + new.airportfrom.id + "," + new.airportto.id + "," + new.price + "))"); 

plquery exclusive requests return variables grasp, while plcall used simple consults or instructions return true/false.

hope helps anyone.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -