Re: Question about placement of cuts



"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/
.



Relevant Pages

  • Re: Connecting Up Battery
    ... the end cells only 1 pos and 1 neg terminal is used to connect it ... take a pos and neg feed from each end. ... take only the 2 pos feeds from one end and the 2 neg feeds ...
    (uk.rec.waterways)
  • Re: Connecting Up Battery
    ... take a pos and neg feed from each end. ... take only the 2 pos feeds from one end and the 2 neg feeds ... asking whether he should use both posts. ...
    (uk.rec.waterways)
  • Re: Connecting Up Battery
    ... the end cells only 1 pos and 1 neg terminal is used to connect it ... take a pos and neg feed from each end. ... take only the 2 pos feeds from one end and the 2 neg feeds ...
    (uk.rec.waterways)
  • Re: Watch out for this eBAY seller - YourTheBestBuyer
    ... how exactly can you change feedback on Ebay once it has been ... FB before I left my neg FB and today I have 214 pos FB's and 1 neg. ... These power sellers have all sorts of power you and I as normal buyers ...
    (rec.motorcycles)
  • Re: Connecting Up Battery
    ... take a pos and neg feed from each end. ... take only the 2 pos feeds from one end and the 2 neg feeds ... neg to its neighbour. ...
    (uk.rec.waterways)