0
votes

What is the difference \= and \+?

because

?- 15\=14.
?- \+ 15=14.<--- this gives an error while the above does not.

Why?Aren't they the same?

Edit: here's the error:

Compiling the file:
D:\Program Files\Strawberry Prolog Beta\Games\WarCraft.pro
Warning 4: The string \+ is not an operator. (line 1, before the first clause)
Error 16: Instead of the integer 15 what is expected here is something like an infix operator or a full stop. (line 1, before the first clause)
1 error, 1 warning.

Also I'm using Strawberry prolog I also tried it on SWI prolog still the same.

1
Both work fine for me in SWI-Prolog (succeeding with true.). What Prolog are you using? What is the error message? Please edit the question to add this information. - Isabelle Newbie
Probably an operator precedence issue. Try \+ (15=14). Otherwise, it thinks you're trying to do \+ 15 followed by = 14 which would not make syntactic sense. - lurker

1 Answers

1
votes

I think you are putting queries into Prolog source files. That is not where they should go:

  • predicate definitions go into Prolog source files
  • queries are typed into the interactive Prolog toplevel

Try running the SWI-Prolog program without an input file. You should get a window with some informational messages about the SWI-Prolog version and then a prompt ?-. That is the toplevel. Try typing your query there. All queries should go there.

I don't know about Strawberry Prolog, but I suspect it's the same there.