Check out SWI-Prolog datatypes and Verify Type of a Term
?- var(foo).
false.
?- nonvar(foo).
true.
?- number(foo).
false.
?- atom(foo).
true.
?- string(foo).
false.
?- atomic(foo).
true.
?- compound(foo).
false.
?- callable(foo).
true.
?- ground(foo).
true.
?- var(foo()).
false.
?- nonvar(foo()).
true.
?- number(foo()).
false.
?- atom(foo()).
false.
?- string(foo()).
false.
?- atomic(foo()).
false.
?- compound(foo()).
true.
?- callable(foo()).
true.
?- ground(foo()).
true.
So now you have some useful ideas but they really are not of much use for a beginner. Latter when you get more advanced you start to eat these predicates that check types like candy. Then when you get really advanced you use them only when absolutely necessary because you can keep track of all of the details in your head.
Also note the note for callable/2
This was intended as a type-test for arguments to call/1, call/2 etc.
In other words don’t rely on callable/2 for just about anything.
But how should I understand
foo()
?
Your knowledge of imperative programming will do you good when learning Prolog. Do not focus on the ()
. What you should understand is
- Prolog is homoiconic so data is code and code is data.
As code foo()
is a predicate that has no arguments but then that would be more commonly written as just foo
. If it had arguments it could be foo(A,B)
.
foo()
could be used as data but more likely it would have one or more values associated with it, E.g, foo(bar)
or foo(bar,baa)
.
- Prolog for beginner should not think about functions. Latter on the use of the word function will slip in for certain needs but for the most part early on learn that Prolog has predicates.
Please explain. Examples would be good.
See this reply
HTH