format
This commit is contained in:
parent
d0aeb6abd7
commit
887b7098bc
7 changed files with 19 additions and 17 deletions
|
@ -1,5 +1,5 @@
|
|||
#include <cstdio>
|
||||
#include <SWI-Prolog.h>
|
||||
#include <cstdio>
|
||||
|
||||
// après avoir installé swi-prolog (et peut être aussi swi-prolog-devel)
|
||||
// pour pouvoir appeler Prolog à partir du C/C++
|
||||
|
@ -10,9 +10,10 @@
|
|||
// pkg-config swipl --libs
|
||||
|
||||
// et selon les paramètres précédents, pour compiler
|
||||
// g++ 1.cpp -I /opt/local/lib/swipl/include -L/opt/local/lib/swipl/lib/arm64-darwin -lswipl
|
||||
// g++ 1.cpp -I /opt/local/lib/swipl/include
|
||||
// -L/opt/local/lib/swipl/lib/arm64-darwin -lswipl
|
||||
|
||||
int main(int _ac, char** _av) {
|
||||
int main(int _ac, char **_av) {
|
||||
PL_initialise(_ac, _av);
|
||||
printf("ok\n");
|
||||
return 0;
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
f(1).
|
||||
f(2).
|
||||
f(3).
|
||||
f(3).
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
#include <cstdio>
|
||||
#include <SWI-cpp.h>
|
||||
#include <cstdio>
|
||||
|
||||
// swipl-ld -ld g++ -goal true 2.cpp 2-f.pl
|
||||
// attention, recompile nécessaire si 2-f.pl change
|
||||
|
||||
int main(int _ac, char** _av) {
|
||||
int main(int _ac, char **_av) {
|
||||
PL_initialise(_ac, _av);
|
||||
|
||||
|
||||
PlTermv pl_args2(1);
|
||||
PlQuery q0("f", pl_args2);
|
||||
while( q0.next_solution()) {
|
||||
while (q0.next_solution()) {
|
||||
printf("---> %s\n", (char *)pl_args2[0]);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
f(1).
|
||||
f(2).
|
||||
f(10).
|
||||
f(10).
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
#include <cstdio>
|
||||
#include <SWI-cpp.h>
|
||||
#include <cstdio>
|
||||
|
||||
// swipl-ld -ld g++ -goal true 3.cpp empty.pl
|
||||
// on retire 3-f.pl de la compile pour le charger à chq execution
|
||||
// charger empty.pl (qui est vide) permet de ne pas avoir le message de bienvenu de Prolog
|
||||
// charger empty.pl (qui est vide) permet de ne pas avoir le message de bienvenu
|
||||
// de Prolog
|
||||
|
||||
int main(int _ac, char** _av) {
|
||||
int main(int _ac, char **_av) {
|
||||
PL_initialise(_ac, _av);
|
||||
|
||||
PlTermv pl_args(1);
|
||||
|
@ -14,7 +15,7 @@ int main(int _ac, char** _av) {
|
|||
|
||||
PlTermv pl_args2(1);
|
||||
PlQuery q0("f", pl_args2);
|
||||
while( q0.next_solution()) {
|
||||
while (q0.next_solution()) {
|
||||
printf("---> %s\n", (char *)pl_args2[0]);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#include <cstdio>
|
||||
#include <SWI-cpp.h>
|
||||
#include <cstdio>
|
||||
|
||||
// swipl-ld -ld g++ -goal true 4.cpp empty.pl
|
||||
|
||||
int main(int _ac, char** _av) {
|
||||
int main(int _ac, char **_av) {
|
||||
printf("using fac.pl to compute 10!\n");
|
||||
PL_initialise(_ac, _av);
|
||||
|
||||
|
@ -14,7 +14,7 @@ int main(int _ac, char** _av) {
|
|||
PlTermv pl_args2(2);
|
||||
pl_args2[0] = 10;
|
||||
PlQuery q0("fac", pl_args2);
|
||||
while( q0.next_solution()) {
|
||||
while (q0.next_solution()) {
|
||||
printf("---> %d\n", (int)pl_args2[1]);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,4 +5,4 @@ fac(X,F):-
|
|||
fac( Y, Next ),
|
||||
F is X * Next.
|
||||
|
||||
% ?- fac(3, X).
|
||||
% ?- fac(3, X).
|
||||
|
|
Reference in a new issue