I am working with SWI Prolog. I wish to define an add function: add(X, Y) which returns the sum of X and Y. However, I do not know how to define functions in Prolog. I tried doing this using predicates as such:
add(X, Y, Z) :- Z is X+Y.
but upon executing a query of the form add(2, 3, X) this gives an error saying:
ERROR: toplevel: Undefined procedure: add/3 (DWIM could not correct goal)
Also, I cannot understand the difference between :- and := while writing rules. I read somewhere that :- is used to define predicates while := is used to define functions. I am not sure if this is correct. I tried using := for defining functions but it doesn't work.