36X_API
extern Term YAP_MkCharPTerm(
char *n);
61 return Yap_GetFromSlot(hdl);
70 return Deref(Yap_PopHandle(hdl));
75 CACHE_REGS hdl = Yap_InitSlot(t0);
81 Yap_PutInHandle(hdl, t0);
103 mk(YAP_ReadBuffer(s, &tp));
141 BACKUP_MACHINE_REGS();
144 if (!IsApplTerm(t0) && !IsPairTerm(t0))
146 tf =
YAPTerm(ArgOfTerm(i, t0));
147 RECOVER_MACHINE_REGS();
151 inline void bind(Term b) { LOCAL_HandleBase[hdl] = b; }
152 inline void bind(
YAPTerm *b) { LOCAL_HandleBase[hdl] = b->term(); }
160 BACKUP_MACHINE_REGS();
161 out = Yap_eq(
gt(), t1.term());
162 RECOVER_MACHINE_REGS();
169 BACKUP_MACHINE_REGS();
170 out = Yap_unify(
gt(), t1.term());
171 RECOVER_MACHINE_REGS();
178 BACKUP_MACHINE_REGS();
179 out = Yap_eq(
gt(), t1.term());
180 RECOVER_MACHINE_REGS();
188 BACKUP_MACHINE_REGS();
189 out = Yap_Variant(
gt(), t1.term());
190 RECOVER_MACHINE_REGS();
194 virtual intptr_t hashTerm(
size_t sz,
size_t depth,
bool variant) {
197 BACKUP_MACHINE_REGS();
198 out = Yap_TermHash(
gt(), sz, depth,
variant);
199 RECOVER_MACHINE_REGS();
203 virtual bool isVar() {
return IsVarTerm(
gt()); }
206 return IsIntegerTerm(
gt());
209 return IsFloatTerm(
gt());
212 return IsStringTerm(
gt());
215 return !(IsVarTerm(
gt()) || IsNumTerm(
gt()));
220 virtual bool isList() {
return Yap_IsListTerm(
gt()); }
224 virtual Term
getArg(arity_t i);
231 if (IsApplTerm(t0)) {
233 if (IsExtensionFunctor(f))
235 return ArityOfFunctor(f);
236 }
else if (IsPairTerm(t0)) {
247 BACKUP_MACHINE_REGS();
248 if (!(os = Yap_TermToBuffer(Yap_GetFromSlot(hdl), Handle_vars_f))) {
249 RECOVER_MACHINE_REGS();
252 RECOVER_MACHINE_REGS();
257 inline yhandle_t
handle() {
return hdl; };
290 BACKUP_MACHINE_REGS();
291 Term t0 = Yap_MkApplTerm(f, f->ArityOfFE, ts);
293 RECOVER_MACHINE_REGS();
300 YAPApplTerm(
const std::string s, std::vector<Term> ts);
301 YAPApplTerm(
const std::string s, std::vector<YAPTerm> ts);
305 template<
typename...
T>
307 BACKUP_MACHINE_REGS();
309 for(
auto elem : list )
312 Yap_unify( elem, (CELL)HR );
315 RECOVER_MACHINE_REGS();
319 YAPApplTerm(
const std::string s, std::initializer_list<Term> list ) {
320 BACKUP_MACHINE_REGS();
322 for(
auto elem : list )
325 Yap_unify( elem, (CELL)HR );
328 o[0] = (CELL)Yap_MkFunctor(Yap_LookupAtom(s.c_str()), (HR-(o+1)));
330 RECOVER_MACHINE_REGS();
333 YAPApplTerm(
const char s[], std::initializer_list<Term> list ) {
334 BACKUP_MACHINE_REGS();
336 for(
auto elem : list )
339 Yap_unify( elem, (CELL)HR );
342 o[0] = (CELL)Yap_MkFunctor(Yap_LookupAtom(s), (HR-(o+1)));
344 RECOVER_MACHINE_REGS();
348 YAPApplTerm(
const std::string s, std::initializer_list<YAPTerm> list ) {
349 BACKUP_MACHINE_REGS();
351 for(
auto elem : list )
354 Yap_unify( elem.gt(), (CELL)HR );
357 o[0] = (CELL)Yap_MkFunctor(Yap_LookupAtom(s.c_str()), (HR-(o+1)));
359 RECOVER_MACHINE_REGS();
363 BACKUP_MACHINE_REGS();
365 RESET_VARIABLE(HR+1);
366Yap_unify( a1, (CELL)(HR+1) );
369o[0] = (CELL)Yap_MkFunctor(Yap_LookupAtom(s.c_str()), 1);
371RECOVER_MACHINE_REGS();
373YAPApplTerm(
const std::string s, Term a1, Term a2 ) {
374BACKUP_MACHINE_REGS();
377Yap_unify( a1, (CELL)(HR+1) );
379Yap_unify( a2, (CELL)(HR+2) );
382o[0] = (CELL)Yap_MkFunctor(Yap_LookupAtom(s.c_str()), 2);
384RECOVER_MACHINE_REGS();
386YAPApplTerm(
const std::string s, Term a1, Term a2, Term a3 ) {
387BACKUP_MACHINE_REGS();
390Yap_unify( a1, (CELL)(HR+1) );
392Yap_unify( a2, (CELL)(HR+2) );
394Yap_unify( a3, (CELL)(HR+3) );
396o[0] = (CELL)Yap_MkFunctor(Yap_LookupAtom(s.c_str()),3);
398RECOVER_MACHINE_REGS();
404 mk(Yap_MkNewApplTerm(Yap_MkFunctor(Yap_LookupAtom(s.c_str()),
arity),
410 inline Functor functor() {
return FunctorOfTerm(
gt()); }
417 tf = ArgOfTerm(i, t0);
418 RECOVER_MACHINE_REGS();
421 void putArg(
int i, Term targ) {
424 RepAppl(t0)[i] = Deref(targ);
427 void putArg(
int i,
YAPTerm t) {
430 RepAppl(t0)[i] = t.term();
433 virtual bool isVar() {
return false; }
454 if (IsPairTerm(t0) || t0 == TermNil)
457 Yap_ThrowError(TYPE_ERROR_LIST, t0,
"YAPPairTerms");
461 Term getHead() {
return (HeadOfTerm(
gt())); }
462 Term getTail() {
return (TailOfTerm(
gt())); }
464 bool nil() {
return gt() == TermNil; }
466 std::vector<Term> listToArray();
467 std::vector<YAPTerm> listToVector();
477 bool isTagged() {
return IsIntTerm(gt()); }
487 intptr_t getInteger() {
return IntegerOfTerm(gt()); };
498 double getFl() {
return FloatOfTerm(gt()); };
524 return Yap_SkipList(&t1, &tailp);
527 Term &operator[](
size_t n);
545 return gt() == TermNil;
575 while (IsApplTerm(t1) && FunctorOfTerm(t1)==FunctorComma) {
576 t1 = ArgOfTerm(2,t1);
579 return Yap_SkipList(&t1, &tailp);
582 Term &operator[](
size_t n);
606 const char *getString() {
return StringOfTerm(gt()); }
646 const char *
text() {
return (
const char *)AtomOfTerm(
gt())->StrOfAE; }
659 CELL *getVar() {
return VarOfTerm(
gt()); }
667 bool unbound() {
return IsUnboundVar(VarOfTerm(
gt())); }
668 inline bool isVar() {
return true; }
int Yap_NumberVars(Term t, int numbv, bool handle_singles USES_REGS)
numbervariables in term t
YAPModule A YAPModule describes a bare module, which in YAP is just a name.
YAPModuleProp A YAPModuleProp controls access to a module property.
take information on a Prolog error:
Atom A YAP data-base is a collection of atoms, where each atom has a name and a set of Properties.
YAPFunctor represents Prolog functors Name/Arity.
YAPApplTerm(Functor f, Term ts[])
YAPTerm(Term tn)
create an empty YAPTerm
Term deepCopy()
copy the term ( term copy )
bool initialized()
whether the term actually refers to a live object
virtual bool isInteger()
type check for atom
bool nil()
Check if the list is empty.
void mk(Term t0)
create a new YAPTerm from a term
virtual bool isPair()
is a structured term
bool isCompound()
type check for a string " ... "
size_t length()
Return the number of elements in a list term.
bool isString()
type check for floating-point
Term pop_t()
get the Prolog term corresponding to the YAPTerm, and try to recover
const char * text()
return a string with a textual representation of the term
bool unbound()
type check for unbound
virtual bool isAtom()
type check for unound
YAPAtom getAtom()
[] is a list
virtual bool isList()
term is ground
bool isInteger()
type check for atom
void put(Term t0)
copy a term to an YAPTerm
YAPVarTerm(Term t)
is the variable bound to another one
YAPApplTerm(const std::string s, unsigned int arity)
bool isList()
term is ground
virtual bool unifiable(YAPTerm t1)
we can unify t and t1
bool isFloat()
type check for integer
int numberVars(int start, bool singletons=false)
numbervars ( int start, bool process=false )
YAP_tag_t tag()
construct a term out of an integer (if you know object type use YAPIntegerTerm) YAPTerm(long int num)...
Term gt()
handle to term, equivalent to term_t
bool isPair()
is a structured term
yhandle_t handle()
return a handle to the term
YAPTerm()
private method to convert from Term (internal YAP representation) to YAPTerm
YAPTerm(char *s)
parse string s and construct a term
Term & operator[](size_t n)
Extract the nth element.
virtual bool isAppl()
is a primitive term
virtual bool isVar()
term hash,
bool isGround()
is a pair term
YAPListTerm(Term t0)
Create an empty list term.
virtual Term getArg(arity_t i)
term is a list
virtual bool isFloat()
type check for integer
YAPTerm arg(int i)
from YAPTerm to Term (internal YAP representation)
virtual bool isGround()
is a pair term
virtual arity_t arity()
extract the arity of the term variables have arity 0
virtual bool isString()
type check for floating-point
virtual YAP_Term variant(YAPTerm t1)
t == t1, the two terms are equal up to variable renamingvirtual bool variant(
virtual bool unify(YAPTerm t1)
t = t1
virtual const char * text()
return a string with a textual representation of the term
virtual bool exactlyEqual(YAPTerm t1)
this term is == to t1
YAPApplTerm(Term t0)
There are very many ways to build one of these terms:
YAPConjunctiveTerm(Term t0)
Create an empty list term.
virtual ~YAPTerm()
Term destructor, tries to recover slot.
bool isAtom()
type check for unbound
bool isAppl()
is a primitive term
virtual bool isCompound()
type check for a string " ... "
If you like being short, use T instead of YapTerm.
Atom Term Term Representation of an Atom.
Prolog container for error descriptors.
all we need to know about an error/throw