expand interface to create list from array of terms.
This commit is contained in:
parent
0334632e6e
commit
0409449a23
@ -412,6 +412,7 @@ X_API int STD_PROTO(YAP_IsWideAtom,(Atom));
|
|||||||
X_API char *STD_PROTO(YAP_AtomName,(Atom));
|
X_API char *STD_PROTO(YAP_AtomName,(Atom));
|
||||||
X_API wchar_t *STD_PROTO(YAP_WideAtomName,(Atom));
|
X_API wchar_t *STD_PROTO(YAP_WideAtomName,(Atom));
|
||||||
X_API Term STD_PROTO(YAP_MkPairTerm,(Term,Term));
|
X_API Term STD_PROTO(YAP_MkPairTerm,(Term,Term));
|
||||||
|
X_API Term STD_PROTO(YAP_MkListFromTerms,(Term *,Int));
|
||||||
X_API Term STD_PROTO(YAP_MkNewPairTerm,(void));
|
X_API Term STD_PROTO(YAP_MkNewPairTerm,(void));
|
||||||
X_API Term STD_PROTO(YAP_HeadOfTerm,(Term));
|
X_API Term STD_PROTO(YAP_HeadOfTerm,(Term));
|
||||||
X_API Term STD_PROTO(YAP_TailOfTerm,(Term));
|
X_API Term STD_PROTO(YAP_TailOfTerm,(Term));
|
||||||
@ -982,6 +983,44 @@ YAP_MkPairTerm(Term t1, Term t2)
|
|||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
X_API Term
|
||||||
|
YAP_MkListFromTerms(Term *ta, Int sz)
|
||||||
|
{
|
||||||
|
CACHE_REGS
|
||||||
|
Term t;
|
||||||
|
CELL *h;
|
||||||
|
if (sz == 0)
|
||||||
|
return TermNil;
|
||||||
|
BACKUP_H();
|
||||||
|
if (H+sz*2 > ASP-1024) {
|
||||||
|
Int sl1 = Yap_InitSlot((CELL)ta PASS_REGS);
|
||||||
|
RECOVER_H();
|
||||||
|
if (!dogc( PASS_REGS1 )) {
|
||||||
|
return TermNil;
|
||||||
|
}
|
||||||
|
BACKUP_H();
|
||||||
|
ta = (CELL *)Yap_GetFromSlot(sl1 PASS_REGS);
|
||||||
|
Yap_RecoverSlots(1 PASS_REGS);
|
||||||
|
}
|
||||||
|
h = H;
|
||||||
|
t = AbsPair(h);
|
||||||
|
while (sz--) {
|
||||||
|
Term ti = *ta++;
|
||||||
|
if (IsVarTerm(ti)) {
|
||||||
|
RESET_VARIABLE(h);
|
||||||
|
Yap_unify(ti, h[0]);
|
||||||
|
} else {
|
||||||
|
h[0] = ti;
|
||||||
|
}
|
||||||
|
h[1] = AbsPair(h+2);
|
||||||
|
h += 2;
|
||||||
|
}
|
||||||
|
h[-1] = TermNil;
|
||||||
|
H = h;
|
||||||
|
RECOVER_H();
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
X_API Term
|
X_API Term
|
||||||
YAP_MkNewPairTerm()
|
YAP_MkNewPairTerm()
|
||||||
{
|
{
|
||||||
|
11
docs/yap.tex
11
docs/yap.tex
@ -16351,6 +16351,7 @@ hook on garbage collection:
|
|||||||
@findex YAP_MkNewPairTerm (C-Interface function)
|
@findex YAP_MkNewPairTerm (C-Interface function)
|
||||||
@findex YAP_HeadOfTerm (C-Interface function)
|
@findex YAP_HeadOfTerm (C-Interface function)
|
||||||
@findex YAP_TailOfTerm (C-Interface function)
|
@findex YAP_TailOfTerm (C-Interface function)
|
||||||
|
@findex YAP_MkListFromTerms (C-Interface function)
|
||||||
A @i{pair} is a Prolog term which consists of a tuple of two Prolog
|
A @i{pair} is a Prolog term which consists of a tuple of two Prolog
|
||||||
terms designated as the @i{head} and the @i{tail} of the term. Pairs are
|
terms designated as the @i{head} and the @i{tail} of the term. Pairs are
|
||||||
most often used to build @emph{lists}. The following primitives can be
|
most often used to build @emph{lists}. The following primitives can be
|
||||||
@ -16360,11 +16361,18 @@ used to manipulate pairs:
|
|||||||
YAP_Term YAP_MkNewPairTerm(void)
|
YAP_Term YAP_MkNewPairTerm(void)
|
||||||
YAP_Term YAP_HeadOfTerm(YAP_Term @var{t})
|
YAP_Term YAP_HeadOfTerm(YAP_Term @var{t})
|
||||||
YAP_Term YAP_TailOfTerm(YAP_Term @var{t})
|
YAP_Term YAP_TailOfTerm(YAP_Term @var{t})
|
||||||
|
YAP_Term YAP_MkListFromTerms(YAP_Term *@var{pt}, YAP_Int *@var{sz})
|
||||||
@end example
|
@end example
|
||||||
One can construct a new pair from two terms, or one can just build a
|
One can construct a new pair from two terms, or one can just build a
|
||||||
pair whose head and tail are new unbound variables. Finally, one can
|
pair whose head and tail are new unbound variables. Finally, one can
|
||||||
fetch the head or the tail.
|
fetch the head or the tail.
|
||||||
|
|
||||||
|
The last function supports the common operation of constructing a list from an
|
||||||
|
array of terms of size @var{sz} in a simple sweep.
|
||||||
|
|
||||||
|
Notice that the list constructors can call the garbage collector if
|
||||||
|
there is not enough space in the global stack.
|
||||||
|
|
||||||
@findex YAP_MkApplTerm (C-Interface function)
|
@findex YAP_MkApplTerm (C-Interface function)
|
||||||
@findex YAP_MkNewApplTerm (C-Interface function)
|
@findex YAP_MkNewApplTerm (C-Interface function)
|
||||||
@findex YAP_ArgOfTerm (C-Interface function)
|
@findex YAP_ArgOfTerm (C-Interface function)
|
||||||
@ -16392,6 +16400,9 @@ to a compound term. @code{argno} should be greater or equal to 1 and
|
|||||||
less or equal to the arity of the functor. @code{YAP_ArgsOfTerm}
|
less or equal to the arity of the functor. @code{YAP_ArgsOfTerm}
|
||||||
returns a pointer to an array of arguments.
|
returns a pointer to an array of arguments.
|
||||||
|
|
||||||
|
Notice that the compound term constructors can call the garbage
|
||||||
|
collector if there is not enough space in the global stack.
|
||||||
|
|
||||||
YAP allows one to manipulate the functors of compound term. The function
|
YAP allows one to manipulate the functors of compound term. The function
|
||||||
@code{YAP_FunctorOfTerm} allows one to obtain a variable of type
|
@code{YAP_FunctorOfTerm} allows one to obtain a variable of type
|
||||||
@code{YAP_Functor} with the functor to a term. The following functions
|
@code{YAP_Functor} with the functor to a term. The following functions
|
||||||
|
@ -181,6 +181,8 @@ extern X_API CONST wchar_t *PROTO(YAP_WideAtomName,(YAP_Atom));
|
|||||||
/* YAP_Term MkPairTerm(YAP_Term Head, YAP_Term Tail) */
|
/* YAP_Term MkPairTerm(YAP_Term Head, YAP_Term Tail) */
|
||||||
extern X_API YAP_Term PROTO(YAP_MkPairTerm,(YAP_Term,YAP_Term));
|
extern X_API YAP_Term PROTO(YAP_MkPairTerm,(YAP_Term,YAP_Term));
|
||||||
|
|
||||||
|
extern X_API YAP_Term PROTO(YAP_MkListFromTerms,(YAP_Term *,YAP_Int));
|
||||||
|
|
||||||
/* YAP_Term MkNewPairTerm(void) */
|
/* YAP_Term MkNewPairTerm(void) */
|
||||||
extern X_API YAP_Term PROTO(YAP_MkNewPairTerm,(void));
|
extern X_API YAP_Term PROTO(YAP_MkNewPairTerm,(void));
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user