git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@15 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc 2001-04-24 16:40:11 +00:00
parent 98283101bb
commit 5bd09d8408
5 changed files with 71 additions and 3 deletions

View File

@ -1238,6 +1238,18 @@ p_restore_regs2(void)
return(TRUE);
}
static Int
p_clean_ifcp(void) {
#if SBA
choiceptr pt0 = (choiceptr)IntegerOfTerm(Deref(ARG1));
#else
choiceptr pt0 = (choiceptr)(LCL0-IntOfTerm(Deref(ARG1)));
#endif
pt0->cp_ap = (yamop *)TRUSTFAILCODE;
return(TRUE);
}
void
InitExecFs(void)
{
@ -1263,5 +1275,6 @@ InitExecFs(void)
InitCPred("$pred_goal_expansion_on", 0, p_pred_goal_expansion_on, SafePredFlag);
InitCPred("$restore_regs", 1, p_restore_regs, SafePredFlag);
InitCPred("$restore_regs", 2, p_restore_regs2, SafePredFlag);
InitCPred("$clean_ifcp", 1, p_clean_ifcp, SafePredFlag);
}

View File

@ -6,7 +6,7 @@
<H2 ALIGN=CENTER>Yap-4.3.19:</H2>
<UL>
<LI> SPEEDUP: inline functor(S) -> Na,Ar.
<LI> NEW: if/3.
<LI> SPEEDUP: inline functor(Na,Ar) -> S.
<LI> FIXED: pillow installation path.
<LI> FIXED: allow yap_flag(user_{},V).

View File

@ -1714,7 +1714,6 @@ The last argument @var{Options} must be a list of options, which can be:
@item filename
the filename for a module to import into the current module.
@table @code
@item library(file)
a library file to import into the current module.
@ -2060,7 +2059,6 @@ The built-in @code{repeat/1} could be defined in Prolog by:
repeat :- repeat.
@end example
@item call(+@var{P}) [IS0]
@findex call/1
@syindex call/1
@ -2099,6 +2097,53 @@ is converted to:
a(X) :- call(X).
@end example
@item if(?@var{G},?@var{H},?@var{I}) [IS0]
@findex if/3
@syindex if/3
@cnindex if/3
Call goal @var{H} once per each solution of goal @var{H}. If goal
@var{H} has no solutions, call goal @var{I}.
The builtin @code{if/3} is similar to @code{->/3}, with the difference
that it will backtrack over the test goal. Consider the following
small data-base:
@example
a(1). b(a). c(x).
a(2). b(b). c(y).
@end example
Execution of an @code{if/3} query will proceed as follows:
@example
?- if(a(X),b(Y),c(Z)).
X = 1,
Y = a ? ;
X = 1,
Y = b ? ;
X = 2,
Y = a ? ;
X = 2,
Y = b ? ;
no
@end example
@noindent
The system will backtrack over the two solutions for @code{a/1} and the
two solutions for @code{b/1}, generating four solutions.
Cuts are allowed inside the first goal @var{G}, but they will only prune
over @var{G}.
If you want @var{G} to be deterministic you should use if-then-else, as
it is both more efficient and more portable.
@item once(+@var{G}) [IS0]
@findex once/1
@snindex once/1

View File

@ -516,6 +516,7 @@ $member(X,[_|L]) :- $member(X,L).
current_predicate(?,:),
findall(?,:,?),
findall(?,:,?,?),
if(:,:,:),
incore(:),
listing(?),
nospy(:),

View File

@ -17,6 +17,15 @@
once(G) :- '$execute'(G), !.
if(X,Y,Z) :-
CP is '$last_choice_pt',
'$execute'(X),
'$clean_ifcp'(CP),
'$execute'(Y).
if(X,Y,Z) :-
'$execute'(Z).
call_with_args(V) :- var(V), !,
throw(error(instantiation_error,call_with_args(V))).
call_with_args(M:A) :- !,