list_or_partial_list support.

This commit is contained in:
Vítor Santos Costa 2012-03-06 14:41:23 +00:00
parent 9a57a51f40
commit 020323d633
3 changed files with 16 additions and 11 deletions

View File

@ -4234,10 +4234,19 @@ p_is_list( USES_REGS1 )
return Yap_IsListTerm(Deref(ARG1));
}
int
Yap_IsListOrPartialListTerm(Term t)
{
Term *tailp, tail;
Yap_SkipList(&t, &tailp);
tail = *tailp;
return tail == TermNil || IsVarTerm(tail);
}
static Int
p_is_list_or_partial_list( USES_REGS1 )
{
return Yap_IsListTerm(Deref(ARG1));
return Yap_IsListOrPartialListTerm(Deref(ARG1));
}
static Term
@ -4816,8 +4825,8 @@ void Yap_InitUtilCPreds(void)
Yap_InitCPred("term_variables", 2, p_term_variables, 0);
Yap_InitCPred("term_variables", 3, p_term_variables3, 0);
Yap_InitCPred("term_attvars", 2, p_term_attvars, 0);
Yap_InitCPred("is_list", 1, p_is_list, SafePredFlag);
Yap_InitCPred("$is_list_or_partial_list", 1, p_is_list_or_partial_list, SafePredFlag);
Yap_InitCPred("is_list", 1, p_is_list, SafePredFlag|TestPredFlag);
Yap_InitCPred("$is_list_or_partial_list", 1, p_is_list_or_partial_list, SafePredFlag|TestPredFlag);
Yap_InitCPred("rational_term_to_tree", 2, p_break_rational, 0);
Yap_InitCPred("tree_to_rational_term", 2, p_restore_rational, 0);
Yap_InitCPred("=@=", 2, p_variant, 0);

View File

@ -395,6 +395,7 @@ size_t STD_PROTO(Yap_ExportTerm,(Term, char *, size_t, UInt));
size_t STD_PROTO(Yap_SizeOfExportedTerm,(char *));
Term STD_PROTO(Yap_ImportTerm,(char *));
int STD_PROTO(Yap_IsListTerm,(Term));
int STD_PROTO(Yap_IsListOrPartialListTerm,(Term));
Term STD_PROTO(Yap_CopyTermNoShare,(Term));
int STD_PROTO(Yap_SizeGroundTerm,(Term, int));
int STD_PROTO(Yap_IsGroundTerm,(Term));

View File

@ -32,7 +32,7 @@ _^Goal :-
findall(Template, Generator, Answers) :-
( '$partial_list_or_list'(Answers) ->
( '$is_list_or_partial_list'(Answers) ->
true
;
'$do_error'(type_error(list,Answers), findall(Template, Generator, Answers))
@ -80,7 +80,7 @@ findall(Template, Generator, Answers, SoFar) :-
% This is the setof predicate
setof(Template, Generator, Set) :-
( '$partial_list_or_list'(Set) ->
( '$is_list_or_partial_list'(Set) ->
true
;
'$do_error'(type_error(list,Set), setof(Template, Generator, Set))
@ -95,7 +95,7 @@ setof(Template, Generator, Set) :-
% of these variables
bagof(Template, Generator, Bag) :-
( '$partial_list_or_list'(Bag) ->
( '$is_list_or_partial_list'(Bag) ->
true
;
'$do_error'(type_error(list,Bag), bagof(Template, Generator, Bag))
@ -235,8 +235,3 @@ all(T,G,S) :-
'$$split'([T1|Tn],T,X,S1,[T1|S2]) :- '$$split'(Tn,T,X,S1,S2).
'$partial_list_or_list'(V) :- var(V), !.
'$partial_list_or_list'([]) :- !.
'$partial_list_or_list'([_|B]) :- !,
'$partial_list_or_list'(B).