user425243
user425243

Reputation:

Strange operator (!) in Prolog

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 ?

Upvotes: 6

Views: 5143

Answers (1)

Fred Foo
Fred Foo

Reputation: 363627

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.

Upvotes: 11

Related Questions