Re: Question about placement of cuts
- From: Markus Triska <triska@xxxxxxxx>
- Date: Thu, 30 Aug 2007 14:15:50 +0200
"brianna.laugher@xxxxxxxxx" <brianna.laugher@xxxxxxxxx> writes:
Q1. Is there any difference (to Prolog) between these two styles of
code?
Yes; for example:
Style 1: %?- bar(X). Style 2: %?- bar(X).
%@ X = a ; %@ X = a ;
%@ X = b ; %@ No
%@ No
determine_sign(pos,neg,neg).
determine_sign(pos,pos,pos).
determine_sign(neg,pos,neg).
determine_sign(neg,neg,pos).
What about:
sign_sign_result(pos, S1, S) :- sign_pos(S1, S).
sign_sign_result(neg, S1, S) :- sign_neg(S1, S).
sign_pos(neg, neg).
sign_pos(pos, pos).
sign_neg(neg, pos).
sign_neg(pos, neg).
Due to first-argument indexing, it doesn't leave choice-points if the
first two arguments are instantiated.
determine_sign(_,_,[]).
Mark different categories with distinct functors. What else is there
that you want to use with determine_sign/3? Give it a wrapper or use a
different atom for it, and indexing can distinguish the cases.
Does that have the same effect as adding cuts to each definition?
No; try for example ?- determine_sign(A, B, C).
--
comp.lang.prolog FAQ: http://www.logic.at/prolog/faq/
.
- References:
- Question about placement of cuts
- From: brianna.laugher@xxxxxxxxx
- Question about placement of cuts
- Prev by Date: Question about placement of cuts
- Next by Date: Re: Survey of indexing features for dynamic clauses
- Previous by thread: Question about placement of cuts
- Index(es):
Relevant Pages
|
|