Strange operator (!) in Prolog
Asked Answered
R

1

6
hi(g,plus(A,B),int) :- hi(g,A,int),hi(g,B,int),!.  

in the above statement what does the '!' sign at the end of the statement do ?

Reify answered 5/5, 2011 at 9:58 Comment(0)
C
11

That's the cut operator, which basically states "if we got up to here, don't backtrack."

So, if both recursive calls succeed, the hi predicate will not retry them.

Consumer answered 5/5, 2011 at 10:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.