YAP 7.1.0
Query Handling in the YAP interface.

Engine and Query Management. More...

Detailed Description

Engine and Query Management.

These classes wrap engine and query An engine is an environment where we can rum Prolog, that is, where we can run queries

Also, supports callbacks and engine configuration


Class Documentation

◆ YAPQuery

class YAPQuery

Queries and engines.

Queries

interface to a YAP Query; uses an SWI-like status info internally

Definition at line 38 of file yapq.hh.

Inheritance diagram for YAPQuery:
YAPPredicate YAPModuleProp YAPProp

Public Member Functions

 YAPQuery (YAPPredicate p, YAPTerm t[])
 main constructor, uses a predicate and an array of terms More...
 
 YAPQuery (YAPFunctor f, YAPTerm mod, YAPTerm t[])
 full constructor, More...
 
 YAPQuery (YAPFunctor f, YAPTerm mod, Term t[])
 often, this is more efficient More...
 
 YAPQuery (const char *s)
 functor/term constructor, More...
 
 YAPQuery (YAPTerm t)
 string constructor with just an atom More...
 
void setFlag (int flag)
 set flags for query execution, currently only for exception handling More...
 
void resetFlag (int flag)
 reset flags for query execution, currently only for exception handling More...
 
bool first ()
 first query More...
 
bool next ()
 ask for the next solution of the current query same call for every solution More...
 
bool deterministic ()
 does this query have open choice-points? or is it deterministic? More...
 
const char * text ()
 represent the top-goal More...
 
void close ()
 remove alternatives in the current search space, and finish the current query finish the current query: undo all bindings More...
 
void cut ()
 query variables More...
 
Term namedVars ()
 
YAPPairTermnamedVarTerms ()
 
std::vector< Term > namedVarsVector ()
 query variables, but copied out More...
 
YAPTerm getTerm (yhandle_t t)
 convert a ref to a binding More...
 
bool command ()
 simple YAP Query; just calls YAP and reports success or failure, Useful when we just want things done, eg YAPCommand("load_files(library(lists), )") More...
 
- Public Member Functions inherited from YAPPredicate
 YAPPredicate (const char *s0, Term &tout, YAPPairTerm *&names, CELL *&nts)
 String constructor for predicates. More...
 
 YAPPredicate (YAPFunctor f)
 Functor constructor for predicates. More...
 
 YAPPredicate (YAPFunctor f, YAPTerm mod)
 Functor constructor for predicates, is given a specific module. More...
 
 YAPPredicate (YAPAtom at, YAPTerm mod)
 Name/arity constructor for predicates. More...
 
 YAPPredicate (YAPAtom at)
 Name/0 constructor for predicates. More...
 
 YAPPredicate (YAPAtom at, uintptr_t arity, YAPModule mod)
 Mod:Name/Arity constructor for predicates. More...
 
 YAPPredicate (YAPAtom at, uintptr_t arity)
 Atom/Arity constructor for predicates. More...
 
 YAPPredicate (const std::string at, uintptr_t arity, std::string mod="")
 std::string/Arity constructor for predicates More...
 
 YAPPredicate (const char *at, uintptr_t arity)
 char *‍/arity constructor for predicates More...
 
 YAPPredicate (const char *at, uintptr_t arity, YAPTerm mod)
 char *‍/module constructor for predicates More...
 
 YAPPredicate (const char *at, YAPTerm mod)
 char *‍/module constructor for predicates More...
 
YAPModule module ()
 module of a predicate More...
 
YAPAtom name ()
 name of predicate More...
 
YAPFunctor functor ()
 functor of predicate More...
 
uintptr_t getArity ()
 arity of predicate More...
 
arity_t arity ()
 
PredEntrypredEntry ()
 
- Public Member Functions inherited from YAPModuleProp
 YAPModuleProp (YAPModule tmod)
 
virtual YAPModule module ()
 
- Public Member Functions inherited from YAPProp
virtual ~YAPProp ()
 get name of property virtual YAPAtom name(); More...
 

Additional Inherited Members

- Protected Member Functions inherited from YAPPredicate
PredEntrygetPred (Term &t, Term &tm, CELL *&outp)
 auxiliary routine to find a predicate in the current module More...
 
PredEntryasPred ()
 
 YAPPredicate ()
 Empty constructor for predicates. More...
 
 YAPPredicate (Term &to, Term &tmod, CELL *&ts, const char *pname)
 
 YAPPredicate (Term t, CELL *&v)
 Term constructor for predicates. More...
 
 YAPPredicate (Term t)
 
 YAPPredicate (YAPTerm t, CELL *&v)
 Term constructor for predicates. More...
 
 YAPPredicate (YAPTerm t)
 
 YAPPredicate (PredEntry *pe)
 Cast constructor for predicates, if we have the implementation data. More...
 
 YAPPredicate (Functor f, Term mod)
 Functor constructor for predicates, is given a specific module. More...
 
- Protected Attributes inherited from YAPPredicate
PredEntryap
 

Constructor & Destructor Documentation

◆ YAPQuery() [1/6]

YAPQuery ( )
inline

Definition at line 67 of file yapq.hh.

◆ ~YAPQuery()

~YAPQuery ( )
inline

Definition at line 71 of file yapq.hh.

◆ YAPQuery() [2/6]

YAPQuery ( YAPPredicate  p,
YAPTerm  t[] 
)

main constructor, uses a predicate and an array of terms

It is given a YAPPredicate p , and an array of terms that must have at least the same arity as the functor

Definition at line 894 of file yapi.cpp.

◆ YAPQuery() [3/6]

YAPQuery ( YAPFunctor  f,
YAPTerm  mod,
YAPTerm  t[] 
)

full constructor,

It is given a functor, module, and an array of terms that must have at least the same arity as the functor

Definition at line 835 of file yapi.cpp.

◆ YAPQuery() [4/6]

YAPQuery ( YAPFunctor  f,
YAPTerm  mod,
Term  t[] 
)

often, this is more efficient

Definition at line 857 of file yapi.cpp.

◆ YAPQuery() [5/6]

YAPQuery ( const char *  s)
inline

functor/term constructor,

It is given a functor, and an array of terms that must have at least the same arity as the functor Works within the current module

string constructor without varnames

It is given a string, calls the parser and obtains a Prolog term that should be a callable goal

Definition at line 99 of file yapq.hh.

◆ YAPQuery() [6/6]

YAPQuery ( YAPTerm  t)
inline

string constructor with just an atom

It i; }; build a query from a term

Definition at line 120 of file yapq.hh.

Member Function Documentation

◆ close()

void close ( )

remove alternatives in the current search space, and finish the current query finish the current query: undo all bindings

Definition at line 1001 of file yapi.cpp.

◆ command()

bool command ( )
inline

simple YAP Query; just calls YAP and reports success or failure, Useful when we just want things done, eg YAPCommand("load_files(library(lists), )")

Definition at line 157 of file yapq.hh.

◆ cut()

void cut ( )

query variables

Definition at line 976 of file yapi.cpp.

◆ deterministic()

bool deterministic ( )

does this query have open choice-points? or is it deterministic?

Definition at line 988 of file yapi.cpp.

◆ first()

bool first ( )
inline

first query

actually implemented by calling the next();

Definition at line 133 of file yapq.hh.

◆ getTerm()

YAPTerm getTerm ( yhandle_t  t)

convert a ref to a binding

Definition at line 999 of file yapi.cpp.

◆ namedVars()

Term namedVars ( )
inline

Definition at line 148 of file yapq.hh.

◆ namedVarsVector()

std::vector< Term > namedVarsVector ( )
inline

query variables, but copied out

Definition at line 151 of file yapq.hh.

◆ namedVarTerms()

YAPPairTerm * namedVarTerms ( )
inline

Definition at line 149 of file yapq.hh.

◆ next()

bool next ( )

ask for the next solution of the current query same call for every solution

Definition at line 913 of file yapi.cpp.

◆ resetFlag()

void resetFlag ( int  flag)
inline

reset flags for query execution, currently only for exception handling

Definition at line 129 of file yapq.hh.

◆ setFlag()

void setFlag ( int  flag)
inline

set flags for query execution, currently only for exception handling

Definition at line 127 of file yapq.hh.

◆ text()

const char * text ( void  )

represent the top-goal

Definition at line 479 of file yapi.cpp.

◆ YAPCallback

class YAPCallback

This class implements a callback Prolog-side.

It will be inherited by the Java or Python class that actually implements the callback

Definition at line 170 of file yapq.hh.

Public Member Functions

virtual void run ()
 
virtual void run (char *s)
 

Constructor & Destructor Documentation

◆ ~YAPCallback()

virtual ~YAPCallback ( )
inlinevirtual

Definition at line 172 of file yapq.hh.

Member Function Documentation

◆ run() [1/2]

virtual void run ( )
inlinevirtual

Definition at line 173 of file yapq.hh.

◆ run() [2/2]

virtual void run ( char *  s)
inlinevirtual

Definition at line 174 of file yapq.hh.

◆ YAPEngineArgs

struct YAPEngineArgs

Setup all arguments to a new engine.

Definition at line 178 of file yapq.hh.

Inheritance diagram for YAPEngineArgs:
yap_boot_params

Public Member Functions

void setEmbedded (bool fl)
 
bool getEmbedded ()
 
void setStackSize (bool fl)
 
bool getStackSize ()
 
void setTrailSize (bool fl)
 
bool getTrailSize ()
 
bool getMStackSize ()
 
void setMaxTrailSize (bool fl)
 
bool getMaxTrailSize ()
 
void createSavedState (bool fl)
 
bool creatingSavedState ()
 
void setPLDIR (const char *fl)
 
const char * getPLDIR ()
 
void setINPUT_STARTUP (const char *fl)
 
const char * getINPUT_STARTUP ()
 
void setOUTPUT_STARTUP (const char *fl)
 
void setOUTPUT_RESTORE (const char *fl)
 
const char * getOUTPUT_STARTUP ()
 
void setSOURCEBOOT (const char *fl)
 
const char * getSOURCEBOOT ()
 
void setPrologBOOTSTRAP (const char *fl)
 
const char * getBOOTSTRAP ()
 
void setPrologGoal (const char *fl)
 
const char * getPrologGoal ()
 
void setPrologTopLevelGoal (const char *fl)
 
const char * getPrologTopLevelGoal ()
 
void setHaltAfterBoot (bool fl)
 
bool getHaltAfterBoot ()
 
void setFastBoot (bool fl)
 
bool getFastBoot ()
 
void setArgc (int fl)
 
int getArgc ()
 
void setArgv (char **fl)
 
char ** getArgv ()
 
void setBOOTDIR (const char *fl)
 
const char * getBOOTDIR ()
 
const char * getBOOTFILE ()
 
void setBOOTFILE (const char *fl)
 
void setROOTDIR (const char *fl)
 

Additional Inherited Members

- Public Attributes inherited from yap_boot_params
void * start
 
YAP_file_type_t boot_file_type
 
const char * ROOTDIR
 
const char * BINDIR
 
const char * LIBDIR
 
const char * SHAREDIR
 
const char * INCLUDEDIR
 
const char * DLLDIR
 
const char * PLDIR
 
const char * COMMONSDIR
 
const char * BOOTDIR
 
const char * SOURCEBOOT
 
const char * BOOTSTRAP
 
const char * INPUT_STARTUP
 
bool install
 
bool jupyter
 
const char * OUTPUT_STARTUP
 
size_t HeapSize
 
size_t MaxHeapSize
 
size_t StackSize
 
size_t MaxStackSize
 
size_t MaxGlobalSize
 
size_t TrailSize
 
size_t MaxTrailSize
 
size_t AttsSize
 
size_t MaxAttsSize
 
const char * YapPrologInitGoal
 
const char * PrologRCFile
 
const char * PrologGoal
 
const char * PrologTopLevelGoal
 
const char * PrologAddPath
 
bool HaltAfterBoot
 
bool FastBoot
 
size_t MaxTableSpaceSize
 
unsigned long int NumberWorkers
 
unsigned long int SchedulerLoop
 
unsigned long int DelayedReleaseLoad
 
bool PrologCannotHandleInterrupts
 
int ExecutionMode
 
int Argc
 
char ** Argv
 
bool Embedded
 
int QuietMode
 
int inp
 
int out
 
int err
 
char * def_var [YAP_MAX_YPP_DEFS]
 
char * def_value [YAP_MAX_YPP_DEFS]
 
int def_c
 
int ErrorNo
 
char * ErrorCause
 

Constructor & Destructor Documentation

◆ YAPEngineArgs()

YAPEngineArgs ( )
inline

Definition at line 181 of file yapq.hh.

Member Function Documentation

◆ createSavedState()

void createSavedState ( bool  fl)
inline

Definition at line 213 of file yapq.hh.

◆ creatingSavedState()

bool creatingSavedState ( )
inline

Definition at line 215 of file yapq.hh.

◆ getArgc()

int getArgc ( )
inline

Definition at line 282 of file yapq.hh.

◆ getArgv()

char ** getArgv ( )
inline

Definition at line 286 of file yapq.hh.

◆ getBOOTDIR()

const char * getBOOTDIR ( )
inline

Definition at line 293 of file yapq.hh.

◆ getBOOTFILE()

const char * getBOOTFILE ( )
inline

Definition at line 295 of file yapq.hh.

◆ getBOOTSTRAP()

const char * getBOOTSTRAP ( )
inline

Definition at line 255 of file yapq.hh.

◆ getEmbedded()

bool getEmbedded ( )
inline

Definition at line 197 of file yapq.hh.

◆ getFastBoot()

bool getFastBoot ( )
inline

Definition at line 278 of file yapq.hh.

◆ getHaltAfterBoot()

bool getHaltAfterBoot ( )
inline

Definition at line 274 of file yapq.hh.

◆ getINPUT_STARTUP()

const char * getINPUT_STARTUP ( )
inline

Definition at line 229 of file yapq.hh.

◆ getMaxTrailSize()

bool getMaxTrailSize ( )
inline

Definition at line 211 of file yapq.hh.

◆ getMStackSize()

bool getMStackSize ( )
inline

Definition at line 207 of file yapq.hh.

◆ getOUTPUT_STARTUP()

const char * getOUTPUT_STARTUP ( )
inline

Definition at line 241 of file yapq.hh.

◆ getPLDIR()

const char * getPLDIR ( )
inline

Definition at line 222 of file yapq.hh.

◆ getPrologGoal()

const char * getPrologGoal ( )
inline

Definition at line 263 of file yapq.hh.

◆ getPrologTopLevelGoal()

const char * getPrologTopLevelGoal ( )
inline

Definition at line 270 of file yapq.hh.

◆ getSOURCEBOOT()

const char * getSOURCEBOOT ( )
inline

Definition at line 248 of file yapq.hh.

◆ getStackSize()

bool getStackSize ( )
inline

Definition at line 201 of file yapq.hh.

◆ getTrailSize()

bool getTrailSize ( )
inline

Definition at line 205 of file yapq.hh.

◆ setArgc()

void setArgc ( int  fl)
inline

Definition at line 280 of file yapq.hh.

◆ setArgv()

void setArgv ( char **  fl)
inline

Definition at line 284 of file yapq.hh.

◆ setBOOTDIR()

void setBOOTDIR ( const char *  fl)
inline

Definition at line 288 of file yapq.hh.

◆ setBOOTFILE()

void setBOOTFILE ( const char *  fl)
inline

Definition at line 297 of file yapq.hh.

◆ setEmbedded()

void setEmbedded ( bool  fl)
inline

Definition at line 195 of file yapq.hh.

◆ setFastBoot()

void setFastBoot ( bool  fl)
inline

Definition at line 276 of file yapq.hh.

◆ setHaltAfterBoot()

void setHaltAfterBoot ( bool  fl)
inline

Definition at line 272 of file yapq.hh.

◆ setINPUT_STARTUP()

void setINPUT_STARTUP ( const char *  fl)
inline

Definition at line 224 of file yapq.hh.

◆ setMaxTrailSize()

void setMaxTrailSize ( bool  fl)
inline

Definition at line 209 of file yapq.hh.

◆ setOUTPUT_RESTORE()

void setOUTPUT_RESTORE ( const char *  fl)
inline

Definition at line 236 of file yapq.hh.

◆ setOUTPUT_STARTUP()

void setOUTPUT_STARTUP ( const char *  fl)
inline

Definition at line 231 of file yapq.hh.

◆ setPLDIR()

void setPLDIR ( const char *  fl)
inline

Definition at line 217 of file yapq.hh.

◆ setPrologBOOTSTRAP()

void setPrologBOOTSTRAP ( const char *  fl)
inline

Definition at line 250 of file yapq.hh.

◆ setPrologGoal()

void setPrologGoal ( const char *  fl)
inline

Definition at line 257 of file yapq.hh.

◆ setPrologTopLevelGoal()

void setPrologTopLevelGoal ( const char *  fl)
inline

Definition at line 265 of file yapq.hh.

◆ setROOTDIR()

void setROOTDIR ( const char *  fl)
inline

Definition at line 303 of file yapq.hh.

◆ setSOURCEBOOT()

void setSOURCEBOOT ( const char *  fl)
inline

Definition at line 243 of file yapq.hh.

◆ setStackSize()

void setStackSize ( bool  fl)
inline

Definition at line 199 of file yapq.hh.

◆ setTrailSize()

void setTrailSize ( bool  fl)
inline

Definition at line 203 of file yapq.hh.

◆ YAPEngine

class YAPEngine

YAP Engine: takes care of the execution environment where we can go executing goals.

Definition at line 317 of file yapq.hh.

Public Member Functions

 YAPEngine (YAPEngineArgs *cargs)
 construct a new engine; may use a variable number of arguments More...
 
 YAPEngine (int argc, char *argv[], YAPCallback *callback=(YAPCallback *) NULL)
 construct a new engine, including aaccess to callbacks More...
 
 ~YAPEngine ()
 kill engine More...
 
void delYAPCallback ()
 remove current callback More...
 
void setYAPCallback (YAPCallback *cb)
 set a new callback More...
 
void run (char *s)
 execute the callback More...
 
void close ()
 stop yap More...
 
bool hasError ()
 execute the callback with a text argument More...
 
YAPQueryquery (const char *s)
 build a query on the engine More...
 
YAPQueryquery (YAPTerm t)
 build a query from a term More...
 
YAPQueryqt (Term t)
 build a query from a Prolog term (internal) More...
 
Term Yap_CurrentModule ()
 current module for the engine More...
 
YAPTerm getTerm (yhandle_t h)
 given a handle, fetch a term from the engine More...
 
bool call (YAPPredicate ap, YAPTerm ts[])
 current directory for the engine More...
 
bool goal (YAPTerm Yt, YAPModule module, bool release=false)
 current directory for the engine More...
 
bool mgoal (Term t, Term tmod, bool release=false)
 ru1n a goal in a module More...
 
bool goal (YAPTerm t, bool release=false)
 current directory for the engine More...
 
bool goal (Term t, bool release=false)
 
void reSet ()
 reset Prolog state More...
 
void release ()
 assune that there are no stack pointers, just release memory More...
 
const char * currentDir ()
 
const char * version ()
 report YAP version as a string More...
 
YAPTerm funCall (YAPTerm t)
 
Term fun (Term t)
 
bool setStringFlag (std::string arg, std::string path)
 
Term top_level (std::string s)
 
Term next_answer (YAPQuery *&Q)
 

Constructor & Destructor Documentation

◆ YAPEngine() [1/2]

YAPEngine ( YAPEngineArgs cargs)
inline

construct a new engine; may use a variable number of arguments

Definition at line 328 of file yapq.hh.

◆ YAPEngine() [2/2]

YAPEngine ( int  argc,
char *  argv[],
YAPCallback callback = (YAPCallback *)NULL 
)

construct a new engine, including aaccess to callbacks

construct a new engine using argc/argv list of arguments

Definition at line 1088 of file yapi.cpp.

◆ ~YAPEngine()

~YAPEngine ( )
inline

kill engine

Definition at line 344 of file yapq.hh.

Member Function Documentation

◆ call()

bool call ( YAPPredicate  ap,
YAPTerm  ts[] 
)

current directory for the engine

Definition at line 658 of file yapi.cpp.

◆ close()

void close ( )
inline

stop yap

Definition at line 360 of file yapq.hh.

◆ currentDir()

const char * currentDir ( )
inline

Definition at line 398 of file yapq.hh.

◆ delYAPCallback()

void delYAPCallback ( )
inline

remove current callback

Definition at line 346 of file yapq.hh.

◆ fun()

Term fun ( Term  t)

Definition at line 763 of file yapi.cpp.

◆ funCall()

YAPTerm funCall ( YAPTerm  t)
inline

Definition at line 411 of file yapq.hh.

◆ getTerm()

YAPTerm getTerm ( yhandle_t  h)
inline

given a handle, fetch a term from the engine

Definition at line 373 of file yapq.hh.

◆ goal() [1/3]

bool goal ( Term  t,
bool  release = false 
)
inline

Definition at line 389 of file yapq.hh.

◆ goal() [2/3]

bool goal ( YAPTerm  t,
bool  release = false 
)
inline

current directory for the engine

Definition at line 388 of file yapq.hh.

◆ goal() [3/3]

bool goal ( YAPTerm  Yt,
YAPModule  module,
bool  release = false 
)
inline

current directory for the engine

Definition at line 377 of file yapq.hh.

◆ hasError()

bool hasError ( )
inline

execute the callback with a text argument

Definition at line 363 of file yapq.hh.

◆ mgoal()

bool mgoal ( Term  t,
Term  tmod,
bool  release = false 
)

ru1n a goal in a module

By default, memory will only be fully recovered on backtracking The release option ensures backtracking is called at the very end

Definition at line 687 of file yapi.cpp.

◆ next_answer()

Term next_answer ( YAPQuery *&  Q)

parse string s and make term with var names available

Definition at line 1282 of file yapi.cpp.

◆ qt()

YAPQuery * qt ( Term  t)
inline

build a query from a Prolog term (internal)

Definition at line 369 of file yapq.hh.

◆ query() [1/2]

YAPQuery * query ( const char *  s)
inline

build a query on the engine

Definition at line 365 of file yapq.hh.

◆ query() [2/2]

YAPQuery * query ( YAPTerm  t)
inline

build a query from a term

Definition at line 367 of file yapq.hh.

◆ release()

void release ( )

assune that there are no stack pointers, just release memory

called when a query must be terminated and its state fully recovered,

Definition at line 755 of file yapi.cpp.

◆ reSet()

void reSet ( )

reset Prolog state

Definition at line 1247 of file yapi.cpp.

◆ run()

void run ( char *  s)
inline

execute the callback

void run() { if (_callback) _callback.run(); } execute the callback with a text argument

Definition at line 355 of file yapq.hh.

◆ setStringFlag()

bool setStringFlag ( std::string  arg,
std::string  path 
)
inline

Definition at line 416 of file yapq.hh.

◆ setYAPCallback()

void setYAPCallback ( YAPCallback cb)
inline

set a new callback

Definition at line 348 of file yapq.hh.

◆ top_level()

Term top_level ( std::string  s)

parse string s and make term with var names available

Definition at line 1261 of file yapi.cpp.

◆ version()

const char * version ( )
inline

report YAP version as a string

Definition at line 404 of file yapq.hh.

◆ Yap_CurrentModule()

Term Yap_CurrentModule ( )
inline

current module for the engine

Definition at line 371 of file yapq.hh.

Variable Documentation

◆ YAPPredicate

class X_API YAPPredicate

Definition at line 22 of file yapq.hh.

Variables

class X_API YAPPredicate