/* * Project : Embedding SWI-Prolog in a C++ program. * * Author : Lens Stephane Ulg * Date : 10/2009 * * Check if an integer is prime. * */ #include #include using namespace std; int main(int argc, char *argv[]) { int res, nb = 0; /* Start Prolog engine */ PlEngine prolog(argv[0]); /* Get the integer to test */ cout << "Number to test (-1 to quit) ? : "; cin >> nb; while (!cin.fail() && nb > -1) { /* Transform the integer to Prolog term */ PlTermv h(1); h[0] = nb; /* Call the predicate */ res = PlCall("prime", h); if (res) cout << nb << " is prime." << endl; else cout << nb << " is not prime." << endl; cout << "Number to test (-1 to quit) ? : "; cin >> nb; } cout << "\n> Exit" << endl; return 0; }