
- Prolog - Home
- Prolog - Introduction
- Prolog - Environment Setup
- Prolog - Hello World
- Prolog - Basics
- Prolog - Relations
- Prolog - Data Objects
- Loop & Decision Making
- Conjunctions & Disjunctions
Prolog Operators
- Prolog - Type of Operators
- Prolog - Arithmetic Comparison Operators
- Prolog - Unification Operators
- Prolog - Term Comparision Operators
- Prolog - Arithmetic Operators
- Prolog - Logical Operators
- Prolog - List Operators
- Prolog - Custom Operators
Prolog Lists
- Prolog - Lists
- Prolog - Member of List
- Prolog - Length of List
- Prolog - Concatenating Lists
- Prolog - Appending to a List
- Prolog - Deleting from a List
- Prolog - Inserting into a List
- Prolog - Permutation Operation
- Prolog - Combination Operation
- Prolog - Reverse Items of a List
- Prolog - Shift Items of a List
- Prolog - Check Order of a List
- Prolog - SubSet of a Set
- Prolog - Union of Sets
- Prolog - Intersection of Sets
- Prolog - Even and Odd Length Finding
- Prolog - Divide a List
- Prolog - Find Maximum of a List
- Prolog - Find Minimum of a List
- Prolog - Find Sum of a List
- Prolog - Sorting List using MergeSort
Built-In Predicates
- Prolog - Built-In Predicates
- Prolog - Identifying Terms
- Prolog - Decomposing Structures
- Prolog - Collecting All
- Prolog - Mathematical Predicates
- Prolog - Scientific Predicates
Miscellaneous
- Recursion and Structures
- Prolog - Backtracking
- Prolog - Preventing Backtracking
- Prolog - Different and Not
- Prolog - Inputs and Outputs
- Tree Data Structure (Case Study)
- Prolog - Examples
- Prolog - Basic Programs
- Prolog - Practical Arithmetic Examples
- Prolog - Examples of Cuts
- Towers of Hanoi Problem
- Prolog - Linked Lists
- Monkey and Banana Problem
- Prolog Useful Resources
- Prolog - Quick Guide
- Prolog - Useful Resources
- Prolog - Discussion
Prolog - Identifying Terms Predicates
Identifying Terms Predicates are built-in predicates which helps in checking the type of a variable. Following are some of the important predicates that are falls under the identifying terms group −
Predicate | Description |
---|---|
var(X) | succeeds if X is currently an un-instantiated variable. |
novar(X) | succeeds if X is not a variable, or already instantiated |
atom(X) | is true if X currently stands for an atom |
number(X) | is true if X currently stands for a number |
integer(X) | is true if X currently stands for an integer |
float(X) | is true if X currently stands for a real number. |
atomic(X) | is true if X currently stands for a number or an atom. |
compound(X) | is true if X currently stands for a structure. |
The var(X) Predicate
When X is not initialized, then, it will show true, otherwise false. So let us see an example.
Example
| ?- var(X). yes | ?- X = 5, var(X). no | ?- var([X]). no | ?-
The novar(X) Predicate
When X is not initialized, the, it will show false, otherwise true. So let us see an example.
Example
| ?- nonvar(X). no | ?- X = 5, nonvar(X). X = 5 (16 ms) yes | ?- nonvar([X]). yes | ?-
The atom(X) Predicate
This will return true, when a non-variable term with 0 argument and a not numeric term is passed as X, otherwise false.
Example
| ?- atom(paul). yes | ?- X = paul,atom(X). X = paul yes | ?- atom([]). yes | ?- atom([a,b]). no | ?-
The number(X) Predicate
This will return true, X stands for any number, otherwise false.
Example
| ?- number(X). no | ?- X=5,number(X). X = 5 yes | ?- number(5.46). yes | ?-
The integer(X) Predicate
This will return true, when X is a positive or negative integer value, otherwise false.
Example
| ?- integer(5). yes | ?- integer(5.46). no | ?-
The float(X) Predicate
This will return true, X is a floating point number, otherwise false.
Example
| ?- float(5). no | ?- float(5.46). yes | ?-
The atomic(X) Predicate
We have atom(X), that is too specific, it returns false for numeric data, the atomic(X) is like atom(X) but it accepts number.
Example
| ?- atom(5). no | ?- atomic(5). yes | ?-
The compound(X) Predicate
If atomic(X) fails, then the terms are either one non-instantiated variable (that can be tested with var(X)) or a compound term. Compound will be true when we pass some compound structure.
Example
| ?- compound([]). no | ?- compound([a]). yes | ?- compound(b(a)). yes | ?-