Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIXED: likes.cpp sample code #51

Merged
merged 1 commit into from
Aug 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 15 additions & 17 deletions likes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
This example code is in the public domain
*/

#include "SWI-cpp2.h"
#include <iostream>
#include <SWI-cpp2.h>
#include <SWI-cpp2.cpp>

using namespace std;

/* Usage:
Expand All @@ -28,25 +30,19 @@ body(int argc, char **argv)
cout << "Happy people:" << endl;
PlQuery q("happy", av);
while( q.next_solution() )
cout << "\t" << (char *)av[0] << endl;
cout << "\t" << av[0].as_string() << endl;
} else
{ PlTermv av(2);

{ PlTerm_var whom;
PlQuery q("likes", PlTermv(PlTerm_atom(argv[0]), whom));
cout << argv[0] << " likes:" << endl;
av[0] = argv[0];
PlQuery q("likes", av);
while( q.next_solution() )
cout << "\t" << (char *)av[1] << endl;
cout << "\t" << whom.as_string() << endl;
}
} else if ( argc == 2 )
{ PlTermv av(2);

av[0] = argv[0];
av[1] = argv[1];
if ( PlCall("likes", av) )
cout << "yes" << endl;
else
cout << "no" << endl;
{ bool likes = PlCall("likes",
PlTermv(PlTerm_atom(argv[0]), PlTerm_atom(argv[1])));

cout << (likes ? "yes" : "no") << endl;
} else
cout << "Usage: likes x [y] or likes -happy" << endl;

Expand All @@ -60,10 +56,12 @@ main(int argc, char **argv)

try
{ return body(argc-1, argv+1);
} catch ( PlException &ex )
{ cerr << (char *) ex << endl;
} catch ( const PlExceptionBase &ex )
{ cerr << "Exception thrown: " << ex.what() << endl;
exit(1);
}

return 0;
}